From: Joseph C. Lehner Date: Mon, 25 Jan 2016 13:18:46 +0000 (+0100) Subject: Fix MAC address parsing X-Git-Tag: v0.9~99 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=6e5156e1375495cb05d23995be8605d88abed1f5;p=oweals%2Fnmrpflash.git Fix MAC address parsing --- diff --git a/nmrp.c b/nmrp.c index 7938b50..61b592d 100644 --- a/nmrp.c +++ b/nmrp.c @@ -246,12 +246,13 @@ static int sock_bind_to_intf(int sock, const char *name) static int mac_parse(const char *str, uint8_t *hwaddr) { - unsigned i, data[6]; + int i; + unsigned data[6]; - i = sscanf(str, "%02x:%02x:%02x:%02x:%02x:%02x", - data, data + 1, data + 2, data + 3, data + 4, data + 5); + sscanf(str, "%02x:%02x:%02x:%02x:%02x:%02x%n", + data, data + 1, data + 2, data + 3, data + 4, data + 5, &i); - if (i == 6) { + if (i == strlen(str)) { for (i = 0; i != 6; ++i) { if (data[i] > 255) { break; @@ -264,8 +265,6 @@ static int mac_parse(const char *str, uint8_t *hwaddr) return 1; } } - - fprintf(stderr, "Invalid MAC address.\n"); return 0; }