diff options
author | Michael Stapelberg <michael+x200@stapelberg.de> | 2009-04-30 19:46:12 +0200 |
---|---|---|
committer | Michael Stapelberg <michael+x200@stapelberg.de> | 2009-04-30 19:46:12 +0200 |
commit | 6b0c635ce896fb81f4b3138d8c22b879c7a9988f (patch) | |
tree | 08e59120c3f53ca87dfe323169cfe548c7272bfd /i3status.c | |
parent | f723688c352ec868ff6d81f75a3dbc62bef7139f (diff) |
Fix display of IP addresses (display "no IP" correctly)
Diffstat (limited to 'i3status.c')
-rw-r--r-- | i3status.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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); |