From afd7e44d9713916a1f10507ba1ea1da927c4ce8e Mon Sep 17 00:00:00 2001 From: Antonio Huete Jimenez Date: Sun, 15 Jul 2018 20:55:01 +0000 Subject: Detect interface type on DragonFly BSD --- src/first_network_device.c | 33 +++++++++++++++++++++++++++------ src/print_wireless_info.c | 1 + 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/first_network_device.c b/src/first_network_device.c index b930f53..93626a2 100644 --- a/src/first_network_device.c +++ b/src/first_network_device.c @@ -3,13 +3,17 @@ #include #include #include -#ifdef __OpenBSD__ +#if defined(__OpenBSD__) || defined(__DragonFly__) #include #include #include #include +#endif +#if defined(__OpenBSD__) #include #include +#elif defined(__DragonFly__) +#include #endif #include "i3status.h" @@ -67,7 +71,7 @@ static bool is_virtual(const char *ifname) { } static net_type_t iface_type(const char *ifname) { -#ifdef __OpenBSD__ +#if defined(__OpenBSD__) /* *First determine if the device is a wireless device by trying two ioctl(2) * commands against it. If either succeeds we can be sure it's a wireless @@ -78,14 +82,23 @@ static net_type_t iface_type(const char *ifname) { struct ifreq ifr; struct ieee80211_bssid bssid; struct ieee80211_nwid nwid; +#elif defined(__DragonFly__) + struct ieee80211req ifr; +#endif +#if defined(__OpenBSD__) || defined(__DragonFly__) struct ifmediareq ifmr; - - int s, ibssid, inwid; - + int s; +#endif +#if defined(__OpenBSD__) + int ibssid, inwid; +#endif +#if defined(__OpenBSD__) || defined(__DragonFly__) if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) return NET_TYPE_OTHER; memset(&ifr, 0, sizeof(ifr)); +#endif +#if defined(__OpenBSD__) ifr.ifr_data = (caddr_t)&nwid; (void)strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); inwid = ioctl(s, SIOCG80211NWID, (caddr_t)&ifr); @@ -98,7 +111,15 @@ static net_type_t iface_type(const char *ifname) { close(s); return NET_TYPE_WIRELESS; } - +#elif defined(__DragonFly__) + (void)strlcpy(ifr.i_name, ifname, sizeof(ifr.i_name)); + ifr.i_type = IEEE80211_IOC_NUMSSIDS; + if (ioctl(s, SIOCG80211, &ifr) == 0) { + close(s); + return NET_TYPE_WIRELESS; + } +#endif +#if defined(__OpenBSD__) || defined(__DragonFly__) (void)memset(&ifmr, 0, sizeof(ifmr)); (void)strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name)); diff --git a/src/print_wireless_info.c b/src/print_wireless_info.c index d495b47..1d87c79 100644 --- a/src/print_wireless_info.c +++ b/src/print_wireless_info.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3