summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2010-07-21 11:01:37 +0200
committerMichael Stapelberg <michael@stapelberg.de>2010-07-21 11:01:37 +0200
commitfac05bf4e8368ddf8fa43f97d199c7a486441d1d (patch)
treec68dea91b5d59a178a683e671545a7f714bd49d8 /src
parente37b2076b8127c6e4e42a7d77b382cd9be6b121b (diff)
Bugfix: Correctly check for interface up/down-status (Thanks docsteel)
Diffstat (limited to 'src')
-rw-r--r--src/print_ip_addr.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/print_ip_addr.c b/src/print_ip_addr.c
index e719d2f..1c2839d 100644
--- a/src/print_ip_addr.c
+++ b/src/print_ip_addr.c
@@ -22,6 +22,7 @@ const char *get_ip_addr(const char *interface) {
memset(part, 0, sizeof(part));
struct ifaddrs *ifaddr, *addrp;
+ bool found = false;
getifaddrs(&ifaddr);
@@ -40,8 +41,10 @@ const char *get_ip_addr(const char *interface) {
addrp = addrp->ifa_next) {
/* Check if the interface is down */
- if (strcmp(addrp->ifa_name, interface) == 0 &&
- (addrp->ifa_flags & IFF_RUNNING) == 0) {
+ if (strcmp(addrp->ifa_name, interface) != 0)
+ continue;
+ found = true;
+ if ((addrp->ifa_flags & IFF_RUNNING) == 0) {
freeifaddrs(ifaddr);
return NULL;
}
@@ -49,7 +52,7 @@ const char *get_ip_addr(const char *interface) {
if (addrp == NULL) {
freeifaddrs(ifaddr);
- return "no IP";
+ return (found ? "no IP" : NULL);
}
int ret;