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
This commit is contained in:
committed by
Robert Roth
parent
305701c637
commit
59d9780eae
@@ -33,6 +33,7 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <net/if_dl.h>
|
#include <net/if_dl.h>
|
||||||
|
#include <net/if_media.h>
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
|
|
||||||
static const unsigned long _glibtop_sysdeps_netload =
|
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) {
|
switch (ifa->ifa_addr->sa_family) {
|
||||||
case AF_LINK: {
|
case AF_LINK: {
|
||||||
struct sockaddr_dl *sdl;
|
struct sockaddr_dl *sdl;
|
||||||
|
struct ifmediareq ifmr;
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
int s, flags;
|
int s, flags;
|
||||||
|
|
||||||
@@ -102,6 +104,20 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
|
|||||||
glibtop_warn_io_r(server, "socket(AF_INET)");
|
glibtop_warn_io_r(server, "socket(AF_INET)");
|
||||||
break;
|
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));
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
(void)strlcpy(ifr.ifr_name, ifa->ifa_name,
|
(void)strlcpy(ifr.ifr_name, ifa->ifa_name,
|
||||||
sizeof(ifr.ifr_name));
|
sizeof(ifr.ifr_name));
|
||||||
@@ -110,6 +126,7 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
|
|||||||
close(s);
|
close(s);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(s);
|
close(s);
|
||||||
|
|
||||||
flags = (ifr.ifr_flags & 0xffff) | (ifr.ifr_flagshigh << 16);
|
flags = (ifr.ifr_flags & 0xffff) | (ifr.ifr_flagshigh << 16);
|
||||||
|
Reference in New Issue
Block a user