]> git.sur5r.net Git - i3/i3status/blobdiff - i3status.c
Fix display of IP addresses (display "no IP" correctly)
[i3/i3status] / i3status.c
index c0a1fe38bb5f87acb8fb458d5d5576c20c7106d0..a0415d3aa9b4b571d2aac19b64ed37d6cf47aa0b 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * Generates a status line for use with wmii or other minimal window managers
+ * i3status – Generates a status line for dzen2 or wmii
  *
  *
- * Copyright (c) 2008-2009 Michael Stapelberg and contributors
+ * Copyright © 2008-2009 Michael Stapelberg and contributors
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without modification,
@@ -64,7 +64,7 @@
 #include <sys/resource.h>
 #endif
 
-#include "wmiistatus.h"
+#include "i3status.h"
 
 #define BAR "^fg(#333333)^p(5;-2)^ro(2)^p()^fg()^p(5)"
 
@@ -360,10 +360,17 @@ static const char *get_ip_address(const char *interface) {
        socklen_t len = sizeof(struct sockaddr_in);
        memset(part, 0, sizeof(part));
 
+       /* First check if the interface is running */
+       (void)strcpy(ifr.ifr_name, interface);
+       if (ioctl(general_socket, SIOCGIFFLAGS, &ifr) < 0 ||
+           !(ifr.ifr_flags & IFF_RUNNING))
+               return NULL;
+
+       /* Interface is up, get the IP address */
        (void)strcpy(ifr.ifr_name, interface);
        ifr.ifr_addr.sa_family = AF_INET;
        if (ioctl(general_socket, SIOCGIFADDR, &ifr) < 0)
-               return NULL;
+               return "no IP";
 
        memcpy(&addr, &ifr.ifr_addr, len);
        (void)inet_ntop(AF_INET, &addr.sin_addr.s_addr, part, len);
@@ -610,7 +617,7 @@ int main(int argc, char *argv[]) {
             pathbuf[512];
        unsigned int i;
 
-       char *configfile = PREFIX "/etc/wmiistatus.conf";
+       char *configfile = PREFIX "/etc/i3status.conf";
        int o, option_index = 0;
        struct option long_options[] = {
                {"config", required_argument, 0, 'c'},
@@ -624,7 +631,7 @@ int main(int argc, char *argv[]) {
                if ((char)o == 'c')
                        configfile = optarg;
                else if ((char)o == 'h') {
-                       printf("wmiistatus (c) 2008-2009 Michael Stapelberg\n"
+                       printf("i3status (c) 2008-2009 Michael Stapelberg\n"
                                "Syntax: %s [-c <configfile>]\n", argv[0]);
                        return 0;
                }