[libgtop] freebsd: Support GLIBTOP_IF_FLAGS_WIRELESS in netload



commit 59d9780eae2de492663c0e3c5dc48b265ceb26a6
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Sat Aug 20 11:36:44 2016 +0800

    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 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/sysdeps/freebsd/netload.c b/sysdeps/freebsd/netload.c
index 80a8fb6..6a25eb4 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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]