]> git.sur5r.net Git - i3/i3status/commitdiff
first_eth_interface: ignore MAC addresses, look for IPv4/IPv6 addresses
authorMichael Stapelberg <michael@stapelberg.de>
Mon, 16 Nov 2015 21:41:18 +0000 (22:41 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Mon, 16 Nov 2015 21:41:18 +0000 (22:41 +0100)
src/first_network_device.c

index 35cd4ff907e15f01bb0bb9566b042919c4d344a9..16f23e07702f4f42ab031987adbacfccf38b035d 100644 (file)
@@ -23,6 +23,13 @@ const char *first_eth_interface(const net_type_t type) {
          addrp = addrp->ifa_next) {
         if (strncasecmp("lo", addrp->ifa_name, strlen("lo")) == 0)
             continue;
+        if (addrp->ifa_addr == NULL)
+            continue;
+        // Skip PF_PACKET addresses (MAC addresses), as they are present on any
+        // ethernet interface.
+        if (addrp->ifa_addr->sa_family != AF_INET &&
+            addrp->ifa_addr->sa_family != AF_INET6)
+            continue;
         // Skip this interface if it is a wireless interface.
         snprintf(path, sizeof(path), "/sys/class/net/%s/wireless", addrp->ifa_name);
         const bool is_wireless = (stat(path, &stbuf) == 0);