diff options
| author | pml68 <contact@pml68.dev> | 2025-09-16 21:48:56 +0200 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2025-09-16 22:15:01 +0200 |
| commit | fd3a7cc487ad5dc36d99ccf46f9e3c6461687f99 (patch) | |
| tree | e1627f8ea07510d06a99ea55f275ae3b6e1919a7 /slstatus/components/ip.c | |
| parent | chore: bump dwm and dmenu versions (diff) | |
| download | suckless-setup-fd3a7cc487ad5dc36d99ccf46f9e3c6461687f99.tar.gz | |
chore: sync slstatus with upstream
Diffstat (limited to 'slstatus/components/ip.c')
| -rw-r--r-- | slstatus/components/ip.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/slstatus/components/ip.c b/slstatus/components/ip.c index 9476549..2cdad46 100644 --- a/slstatus/components/ip.c +++ b/slstatus/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; +} |
