]> git.sur5r.net Git - i3/i3status/blobdiff - src/print_eth_info.c
Use "color_degraded" when interface has no IP
[i3/i3status] / src / print_eth_info.c
index af5a75788f7cf17d4d0f3b9154781e83abc0e5d6..e2326b58e5f44416d19511005d0fb12a1cfef931 100644 (file)
@@ -49,11 +49,13 @@ static int print_eth_speed(char *outwalk, const char *interface) {
     } else
         return sprintf(outwalk, "?");
 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
-    char *ethspeed;
+    const char *ethspeed;
     struct ifmediareq ifm;
     (void)memset(&ifm, 0, sizeof(ifm));
     (void)strncpy(ifm.ifm_name, interface, sizeof(ifm.ifm_name));
-    int ret = ioctl(general_socket, SIOCGIFMEDIA, (caddr_t)&ifm);
+    if (ioctl(general_socket, SIOCGIFMEDIA, (caddr_t)&ifm) < 0) {
+        return sprintf(outwalk, "?");
+    }
 
     /* Get the description of the media type, partially taken from
      * FreeBSD's ifconfig */
@@ -124,7 +126,10 @@ void print_eth_info(yajl_gen json_gen, char *buffer, const char *interface, cons
         goto out;
     }
 
-    START_COLOR("color_good");
+    if (BEGINS_WITH(ip_address, "no IP"))
+        START_COLOR("color_degraded");
+    else
+        START_COLOR("color_good");
 
     for (walk = format_up; *walk != '\0'; walk++) {
         if (*walk != '%') {