]> git.sur5r.net Git - i3/i3status/commitdiff
Bugfix: Correctly check for interface up/down-status (Thanks docsteel)
authorMichael Stapelberg <michael@stapelberg.de>
Wed, 21 Jul 2010 09:01:37 +0000 (11:01 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 21 Jul 2010 09:01:37 +0000 (11:01 +0200)
src/print_ip_addr.c

index e719d2f6b228c96a4333abfe185c28b2b3cdd7fb..1c2839da4689219761686da149574f227cf80bcc 100644 (file)
@@ -22,6 +22,7 @@ const char *get_ip_addr(const char *interface) {
         memset(part, 0, sizeof(part));
 
         struct ifaddrs *ifaddr, *addrp;
+        bool found = false;
 
         getifaddrs(&ifaddr);
 
@@ -40,8 +41,10 @@ const char *get_ip_addr(const char *interface) {
 
              addrp = addrp->ifa_next) {
                 /* Check if the interface is down */
-                if (strcmp(addrp->ifa_name, interface) == 0 &&
-                    (addrp->ifa_flags & IFF_RUNNING) == 0) {
+                if (strcmp(addrp->ifa_name, interface) != 0)
+                        continue;
+                found = true;
+                if ((addrp->ifa_flags & IFF_RUNNING) == 0) {
                         freeifaddrs(ifaddr);
                         return NULL;
                 }
@@ -49,7 +52,7 @@ const char *get_ip_addr(const char *interface) {
 
         if (addrp == NULL) {
                 freeifaddrs(ifaddr);
-                return "no IP";
+                return (found ? "no IP" : NULL);
         }
 
         int ret;