diff --git a/net.c b/net.c index 7a2a292..494055c 100644 --- a/net.c +++ b/net.c @@ -10,27 +10,29 @@ int net_getIPs(struct ifaddrs **ifap) { return 0; } -struct ifaddrs *net_getNextIP(struct ifaddrs **ifap, char **interface, char **addr) { +char net_getNextIP(struct ifaddrs **ifap, char **interface, char **addr) { struct sockaddr_in *sa; + *interface = 0; + *addr = 0; - if (*ifap) { - if ( - (*ifap)->ifa_addr->sa_family != AF_INET - || IFF_LOOPBACK == ((*ifap)->ifa_flags & IFF_LOOPBACK) - ) { - *ifap = (*ifap)->ifa_next; - return net_getNextIP(ifap, interface, addr); - } - - sa = (struct sockaddr_in *) (*ifap)->ifa_addr; - *interface = (*ifap)->ifa_name; - *addr = inet_ntoa(sa->sin_addr); - *ifap = (*ifap)->ifa_next; + if (!*ifap) { + return 0; + } - return *ifap; + if ( + (*ifap)->ifa_addr->sa_family != AF_INET + || IFF_LOOPBACK == ((*ifap)->ifa_flags & IFF_LOOPBACK) + ) { + *ifap = (*ifap)->ifa_next; + return net_getNextIP(ifap, interface, addr); } - return 0; + sa = (struct sockaddr_in *) (*ifap)->ifa_addr; + *interface = (*ifap)->ifa_name; + *addr = inet_ntoa(sa->sin_addr); + *ifap = (*ifap)->ifa_next; + + return 1; } void net_freeIfAddr(struct ifaddrs *ifap) { diff --git a/net.h b/net.h index 2a9185f..a92b115 100644 --- a/net.h +++ b/net.h @@ -4,7 +4,7 @@ #include int net_getIPs(struct ifaddrs **ifap); -struct ifaddrs *net_getNextIP(struct ifaddrs **ifap, char **interface, char **addr); +char net_getNextIP(struct ifaddrs **ifap, char **interface, char **addr); void net_freeIfAddr(struct ifaddrs *ifap); #endif