From 59d9780eae2de492663c0e3c5dc48b265ceb26a6 Mon Sep 17 00:00:00 2001 From: Ting-Wei Lan Date: Sat, 20 Aug 2016 11:36:44 +0800 Subject: [PATCH] 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 --- sysdeps/freebsd/netload.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 #include #include +#include #include 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);