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;
return 1;
}
}
-
- fprintf(stderr, "Invalid MAC address.\n");
return 0;
}