summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIngo Bürk <admin@airblader.de>2018-03-29 12:50:56 +0200
committerGitHub <noreply@github.com>2018-03-29 12:50:56 +0200
commit199a6a27136a5ddb3d813185f0f8cf9185072f08 (patch)
treed51ccd04c7b7207cf789a030166747c25c8bc922 /src
parent5abed8241987a1cb77a4e8e6856f4c7efad3ef0b (diff)
parent6a75ea9aea3bd7fd75d7c3e235b89586bbda4bdf (diff)
Merge pull request #213 from dlrobertson/addr_description
Show IP address when address has a label
Diffstat (limited to 'src')
-rw-r--r--src/print_ip_addr.c5
1 files changed, 3 insertions, 2 deletions
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) {