add 'up' for whether a interface is up or down
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
#include <net/if.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#if defined(__OpenBSD__)
|
#if defined(__OpenBSD__)
|
||||||
@ -59,3 +60,28 @@ ipv6(const char *interface)
|
|||||||
{
|
{
|
||||||
return ip(interface, AF_INET6);
|
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;
|
||||||
|
}
|
||||||
|
@ -56,6 +56,7 @@ static const char unknown_str[] = "n/a";
|
|||||||
* thermal zone on FreeBSD
|
* thermal zone on FreeBSD
|
||||||
* (tz0, tz1, etc.)
|
* (tz0, tz1, etc.)
|
||||||
* uid UID of current user NULL
|
* uid UID of current user NULL
|
||||||
|
* up interface is running interface name (eth0)
|
||||||
* uptime system uptime NULL
|
* uptime system uptime NULL
|
||||||
* username username of current user NULL
|
* username username of current user NULL
|
||||||
* vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer)
|
* vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer)
|
||||||
|
@ -30,6 +30,7 @@ const char *hostname(const char *unused);
|
|||||||
/* ip */
|
/* ip */
|
||||||
const char *ipv4(const char *interface);
|
const char *ipv4(const char *interface);
|
||||||
const char *ipv6(const char *interface);
|
const char *ipv6(const char *interface);
|
||||||
|
const char *up(const char *interface);
|
||||||
|
|
||||||
/* kernel_release */
|
/* kernel_release */
|
||||||
const char *kernel_release(const char *unused);
|
const char *kernel_release(const char *unused);
|
||||||
|
Reference in New Issue
Block a user