summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--components/ip.c26
-rw-r--r--config.def.h1
-rw-r--r--slstatus.h1
3 files changed, 28 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;
+}
diff --git a/config.def.h b/config.def.h
index d805331..100093e 100644
--- a/config.def.h
+++ b/config.def.h
@@ -56,6 +56,7 @@ static const char unknown_str[] = "n/a";
* thermal zone on FreeBSD
* (tz0, tz1, etc.)
* uid UID of current user NULL
+ * up interface is running interface name (eth0)
* uptime system uptime NULL
* username username of current user NULL
* vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer)
diff --git a/slstatus.h b/slstatus.h
index 8ef5874..394281c 100644
--- a/slstatus.h
+++ b/slstatus.h
@@ -30,6 +30,7 @@ const char *hostname(const char *unused);
/* ip */
const char *ipv4(const char *interface);
const char *ipv6(const char *interface);
+const char *up(const char *interface);
/* kernel_release */
const char *kernel_release(const char *unused);