Use strncmp rather than strcmp in netlink.c when fetching the interface

MAC address and index.
This commit is contained in:
Nicholas J. Kain 2014-03-12 13:03:34 -04:00
parent fac6794b6c
commit 765f3de274
3 changed files with 7 additions and 3 deletions

View File

@ -30,6 +30,7 @@
#define NDHC_CONFIG_H_
#include <stdint.h>
#include <net/if.h>
struct client_state_t {
unsigned long long leaseStartTime;
@ -51,7 +52,7 @@ struct client_config_t {
char abort_if_no_lease; // Abort if no lease
char background_if_no_lease; // Fork to background if no lease
char clientid_mac; // If true, then the clientid is a MAC addr
char *interface; // The name of the interface to use
char interface[IFNAMSIZ]; // The name of the interface to use
char clientid[64]; // Optional client id to use
char hostname[64]; // Optional hostname to use
char vendor[64]; // Vendor identification that will be sent

View File

@ -399,7 +399,8 @@ int main(int argc, char **argv)
sizeof client_config.hostname);
break;
case 'i':
client_config.interface = optarg;
strnkcpy(client_config.interface, optarg,
sizeof client_config.interface);
break;
case 'n':
client_config.abort_if_no_lease = 1;

View File

@ -58,7 +58,9 @@ static void get_if_index_and_mac(const struct nlmsghdr *nlh,
nl_attr_parse(nlh, sizeof *ifm, nlrtattr_assign, tb);
if (!tb[IFLA_IFNAME])
return;
if (!strcmp(client_config.interface, nlattr_get_data(tb[IFLA_IFNAME]))) {
if (!strncmp(client_config.interface,
nlattr_get_data(tb[IFLA_IFNAME]),
sizeof client_config.interface)) {
client_config.ifindex = ifm->ifi_index;
if (!tb[IFLA_ADDRESS])
suicide("FATAL: Adapter %s lacks a hardware address.");