Introduction
Introduction Statistics Contact Development Disclaimer Help
add 'up' for whether a interface is up or down - slstatus - status monitor
git clone git://git.suckless.org/slstatus
Log
Files
Refs
README
LICENSE
---
commit af508f0b4cf88b1921c59fdf5dd1a98c08223fa5
parent b6267f7d0bedf5789206adf21f33cfe1a872289c
Author: sewn <[email protected]>
Date: Sat, 16 Mar 2024 00:20:54 +0300
add 'up' for whether a interface is up or down
Diffstat:
M components/ip.c | 26 ++++++++++++++++++++++++++
M config.def.h | 1 +
M slstatus.h | 1 +
3 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git 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
@@ -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
@@ -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);
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.