X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/f31b113e7e85bf7057cb88a70d88c5ce9325e208..c1dc896c806693a4a368abf59e6890d32d520074:/components/ip.c diff --git a/components/ip.c b/components/ip.c index 0b6293e..70724eb 100644 --- a/components/ip.c +++ b/components/ip.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include #include #include #include @@ -7,12 +6,15 @@ #if defined(__OpenBSD__) #include #include +#elif defined(__FreeBSD__) + #include + #include #endif #include "../util.h" static const char * -ip(const char *iface, unsigned short sa_family) +ip(const char *interface, unsigned short sa_family) { struct ifaddrs *ifaddr, *ifa; int s; @@ -29,8 +31,9 @@ ip(const char *iface, unsigned short sa_family) } s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); - if (!strcmp(ifa->ifa_name, iface) && + if (!strcmp(ifa->ifa_name, interface) && (ifa->ifa_addr->sa_family == sa_family)) { + freeifaddrs(ifaddr); if (s != 0) { warn("getnameinfo: %s", gai_strerror(s)); return NULL; @@ -45,13 +48,13 @@ ip(const char *iface, unsigned short sa_family) } const char * -ipv4(const char *iface) +ipv4(const char *interface) { - return ip(iface, AF_INET); + return ip(interface, AF_INET); } const char * -ipv6(const char *iface) +ipv6(const char *interface) { - return ip(iface, AF_INET6); + return ip(interface, AF_INET6); }