]> git.sur5r.net Git - i3/i3status/blobdiff - src/print_wireless_info.c
DragonFlyBSD support added
[i3/i3status] / src / print_wireless_info.c
index b5e7ba26e9d6a9ecc63fc8c1fd2d25707b8f0baf..9ab9c2f38786f8132d448f69ba7b3f4cb96155d2 100644 (file)
 #define IW_ESSID_MAX_SIZE IEEE80211_NWID_LEN
 #endif
 
+#ifdef __DragonFly__
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <ifaddrs.h>
+#include <net/if.h>
+#include <net/if_media.h>
+#include <netproto/802_11/ieee80211.h>
+#include <netproto/802_11/ieee80211_ioctl.h>
+#include <unistd.h>
+#define IW_ESSID_MAX_SIZE IEEE80211_NWID_LEN
+#endif
+
 #ifdef __OpenBSD__
 #include <sys/ioctl.h>
 #include <sys/socket.h>
@@ -170,7 +183,7 @@ static int get_wireless_info(const char *interface, wireless_info_t *info) {
         close(skfd);
         return 1;
 #endif
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__DragonFly__)
         int s, len, inwid;
         uint8_t buf[24 * 1024], *cp;
         struct ieee80211req na;
@@ -305,6 +318,15 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
 
         INSTANCE(interface);
 
+       const char *ip_address = get_ip_addr(interface);
+       if (ip_address == NULL) {
+               START_COLOR("color_bad");
+               outwalk += sprintf(outwalk, "%s", format_down);
+               goto out;
+       } else {
+               START_COLOR("color_good");
+       }
+
         if (get_wireless_info(interface, &info)) {
                 walk = format_up;
                 if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY)
@@ -366,9 +388,8 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
                 }
 
                 if (BEGINS_WITH(walk+1, "ip")) {
-                        const char *ip_address = get_ip_addr(interface);
-                        outwalk += sprintf(outwalk, "%s", (ip_address ? ip_address : "no IP"));
-                        walk += strlen("ip");
+                       outwalk += sprintf(outwalk, "%s", ip_address);
+                       walk += strlen("ip");
                 }
 
 #ifdef LINUX
@@ -383,6 +404,7 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
 #endif
         }
 
+out:
         END_COLOR;
         OUTPUT_FULL_TEXT(buffer);
 }