diff options
author | Ting-Wei Lan <lantw@src.gnome.org> | 2016-08-20 11:36:44 +0800 |
---|---|---|
committer | Robert Roth <robert.roth.off@gmail.com> | 2016-08-20 16:46:15 +0300 |
commit | 59d9780eae2de492663c0e3c5dc48b265ceb26a6 (patch) | |
tree | 87f8a1fdd84b6302da5712d8e7a7356b5c78bb49 | |
parent | 305701c6378069c56aed0b6b0dc0124034230915 (diff) | |
download | libgtop-59d9780eae2de492663c0e3c5dc48b265ceb26a6.tar.gz |
freebsd: Support GLIBTOP_IF_FLAGS_WIRELESS in netload
The ioctl call used in this patch doesn't seems to be documented. It is
what ifconfig(8) command uses to display the media type, and its usage
can be learned by reading the source code of ifconfig(8).
https://bugzilla.gnome.org/show_bug.cgi?id=770165
-rw-r--r-- | sysdeps/freebsd/netload.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/sysdeps/freebsd/netload.c b/sysdeps/freebsd/netload.c index 80a8fb6c..6a25eb47 100644 --- a/sysdeps/freebsd/netload.c +++ b/sysdeps/freebsd/netload.c @@ -33,6 +33,7 @@ #include <netinet/in.h> #include <net/if.h> #include <net/if_dl.h> +#include <net/if_media.h> #include <ifaddrs.h> static const unsigned long _glibtop_sysdeps_netload = @@ -94,6 +95,7 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf, switch (ifa->ifa_addr->sa_family) { case AF_LINK: { struct sockaddr_dl *sdl; + struct ifmediareq ifmr; struct ifreq ifr; int s, flags; @@ -102,6 +104,20 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf, glibtop_warn_io_r(server, "socket(AF_INET)"); break; } + + memset(&ifmr, 0, sizeof(ifmr)); + (void)strlcpy(ifmr.ifm_name, ifa->ifa_name, + sizeof(ifmr.ifm_name)); + if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0 && + ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) { + glibtop_warn_io_r(server, "ioctl(SIOCGIFMEDIA)"); + } else { + if (IFM_TYPE (ifmr.ifm_current) & IFM_IEEE80211) + buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_WIRELESS); + if (IFM_TYPE (ifmr.ifm_active) & IFM_IEEE80211) + buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_WIRELESS); + } + memset(&ifr, 0, sizeof(ifr)); (void)strlcpy(ifr.ifr_name, ifa->ifa_name, sizeof(ifr.ifr_name)); @@ -110,6 +126,7 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf, close(s); break; } + close(s); flags = (ifr.ifr_flags & 0xffff) | (ifr.ifr_flagshigh << 16); |