From: Dan Robertson Date: Wed, 22 Mar 2017 00:39:49 +0000 (+0000) Subject: Show IP address when address has a label X-Git-Tag: 2.12~2^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fpull%2F213%2Fhead;p=i3%2Fi3status Show IP address when address has a label If an address has been added with a label, ensure the correct address is shown. --- diff --git a/src/print_ip_addr.c b/src/print_ip_addr.c index f9cd1f4..c955c1c 100644 --- a/src/print_ip_addr.c +++ b/src/print_ip_addr.c @@ -29,6 +29,7 @@ const char *get_ip_addr(const char *interface, int family) { struct ifaddrs *ifaddr, *addrp; bool found = false; + int interface_len = strlen(interface); getifaddrs(&ifaddr); @@ -39,13 +40,13 @@ const char *get_ip_addr(const char *interface, int family) { for (addrp = ifaddr; (addrp != NULL && - (strcmp(addrp->ifa_name, interface) != 0 || + (strncmp(addrp->ifa_name, interface, interface_len) != 0 || addrp->ifa_addr == NULL || addrp->ifa_addr->sa_family != family)); addrp = addrp->ifa_next) { /* Check if the interface is down */ - if (strcmp(addrp->ifa_name, interface) != 0) + if (strncmp(addrp->ifa_name, interface, interface_len) != 0) continue; found = true; if ((addrp->ifa_flags & IFF_RUNNING) == 0) {