From: Roy Marples Date: Tue, 21 Jan 2014 09:58:55 +0000 (+0000) Subject: We're not extracting the address from proc, so convert our match address X-Git-Tag: v6.3.0~99 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2a7f1a95c851f23f1b12c4696144ec46ce46a132;p=thirdparty%2Fdhcpcd.git We're not extracting the address from proc, so convert our match address to the same string format and compare instead. --- diff --git a/common.h b/common.h index 392125a2..9e3b48c9 100644 --- a/common.h +++ b/common.h @@ -39,6 +39,8 @@ #endif #define UNCONST(a) ((void *)(unsigned long)(const void *)(a)) +#define STRINGIFY(a) #a +#define TOSTRING(a) STRINGIFY(a) #define timeval_to_double(tv) ((tv)->tv_sec * 1.0 + (tv)->tv_usec * 1.0e-6) #define timernorm(tv) do { \ diff --git a/if-linux.c b/if-linux.c index 93ca2475..4f908476 100644 --- a/if-linux.c +++ b/if-linux.c @@ -836,35 +836,37 @@ int in6_addr_flags(const char *ifname, const struct in6_addr *addr) { FILE *fp; - char *ent, address[33], name[IF_NAMESIZE + 1]; + char *p, ifaddress[33], address[33], name[IF_NAMESIZE + 1]; unsigned int ifindex; int prefix, scope, flags, i; - struct in6_addr addr6; - static const char *hex = "0123456789abcdef"; fp = fopen("/proc/net/if_inet6", "r"); if (fp == NULL) return -1; - while ((ent = get_line(fp))) { - i = sscanf(ent, "%32[a-f0-9] %x %x %x %x %16s\n", + + p = ifaddress; + for (i = 0; i < (int)sizeof(addr->s6_addr); i++) { + p += snprintf(p, 3, "%.2x", addr->s6_addr[i]); + } + *p = '\0'; + + while ((p = get_line(fp))) { + i = sscanf(p, "%32[a-f0-9] %x %x %x %x" + " %"TOSTRING(IF_NAMESIZE)"s\n", address, &ifindex, &prefix, &scope, &flags, name); if (i != 6 || strlen(address) != 32) { fclose(fp); errno = ENOTSUP; return -1; } - if (strcmp(ifname, name)) - continue; - for (i = 0; i < 16; i++) { - addr6.s6_addr[i] = - ((strchr(hex, address[i * 2]) - hex) << 4) | - (strchr(hex, address[i * 2 + 1]) - hex); - } - if (IN6_ARE_ADDR_EQUAL(addr, &addr6)) { + if (strcmp(ifname, name) == 0 && + strcmp(ifaddress, address) == 0) + { fclose(fp); return flags; } } + fclose(fp); errno = ESRCH; return -1;