]> git.sur5r.net Git - i3/i3status/commitdiff
Merge pull request #299 from tuxillo/patch-2
authorIngo Bürk <admin@airblader.de>
Mon, 16 Jul 2018 14:13:47 +0000 (16:13 +0200)
committerGitHub <noreply@github.com>
Mon, 16 Jul 2018 14:13:47 +0000 (16:13 +0200)
Detect interface type on DragonFly BSD

src/first_network_device.c
src/print_wireless_info.c

index b930f5357a709e803c635b499132b6cd160a5cb1..93626a266c68ec411c48f971caf557b92a18229d 100644 (file)
@@ -3,13 +3,17 @@
 #include <sys/stat.h>
 #include <stdlib.h>
 #include <ifaddrs.h>
-#ifdef __OpenBSD__
+#if defined(__OpenBSD__) || defined(__DragonFly__)
 #include <sys/types.h>
 #include <sys/sockio.h>
 #include <sys/ioctl.h>
 #include <net/if.h>
+#endif
+#if defined(__OpenBSD__)
 #include <net80211/ieee80211.h>
 #include <net80211/ieee80211_ioctl.h>
+#elif defined(__DragonFly__)
+#include <netproto/802_11/ieee80211_ioctl.h>
 #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));
 
index d495b47eeb76dfa49fe347d841cabbf7bab3fb63..1d87c790ab86e77f8c6d9cc54f831a5dfe8f5d6a 100644 (file)
@@ -38,6 +38,7 @@
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <ifaddrs.h>
+#include <stdlib.h>
 #include <net/if.h>
 #include <net/if_media.h>
 #include <netproto/802_11/ieee80211.h>