summaryrefslogtreecommitdiff
path: root/components/ip.c
diff options
context:
space:
mode:
Diffstat (limited to 'components/ip.c')
-rw-r--r--components/ip.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/components/ip.c b/components/ip.c
index 9476549..2cdad46 100644
--- a/components/ip.c
+++ b/components/ip.c
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
#include <ifaddrs.h>
#include <netdb.h>
+#include <net/if.h>
#include <stdio.h>
#include <string.h>
#if defined(__OpenBSD__)
@@ -59,3 +60,28 @@ ipv6(const char *interface)
{
return ip(interface, AF_INET6);
}
+
+const char *
+up(const char *interface)
+{
+ struct ifaddrs *ifaddr, *ifa;
+
+ if (getifaddrs(&ifaddr) < 0) {
+ warn("getifaddrs:");
+ return NULL;
+ }
+
+ for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+ if (!ifa->ifa_addr)
+ continue;
+
+ if (!strcmp(ifa->ifa_name, interface)) {
+ freeifaddrs(ifaddr);
+ return ifa->ifa_flags & IFF_UP ? "up" : "down";
+ }
+ }
+
+ freeifaddrs(ifaddr);
+
+ return NULL;
+}