]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
We're not extracting the address from proc, so convert our match address
authorRoy Marples <roy@marples.name>
Tue, 21 Jan 2014 09:58:55 +0000 (09:58 +0000)
committerRoy Marples <roy@marples.name>
Tue, 21 Jan 2014 09:58:55 +0000 (09:58 +0000)
to the same string format and compare instead.

common.h
if-linux.c

index 392125a2f532b15ef717687de2f6fc2444cc57ed..9e3b48c9a819c653d4368e3c81b31633a10386fb 100644 (file)
--- 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 {                                             \
index 93ca2475b3ca5ec7362d63cf2ddf9cf6cc7fee9d..4f908476a5aa972a75be4739969f248da0238c58 100644 (file)
@@ -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;