]> git.sur5r.net Git - i3/i3status/commitdiff
Implement getting the wireless ESSID
authorMichael Stapelberg <michael@stapelberg.de>
Thu, 1 Oct 2009 15:43:32 +0000 (17:43 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Thu, 1 Oct 2009 15:43:32 +0000 (17:43 +0200)
This adds a dependency for libiw

Makefile
debian/control
src/get_wireless_info.c

index b894762b9d7466ad34f9fecc22cd3b77801efc7a..fda843827641c7c6103d4978b83098cf0779a296 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,7 @@ VERSION=$(shell git describe --tags --abbrev=0)
 ifeq ($(shell uname),Linux)
 CFLAGS+=-DLINUX
 CFLAGS+=-D_GNU_SOURCE
+LDFLAGS+=-liw
 endif
 
 ifeq ($(shell uname),GNU/kFreeBSD)
index 2591831b9973a02d787923afda497002cba2b6c6..76971c058fb3053cc89d49f3134f0724e9ec795b 100644 (file)
@@ -3,7 +3,7 @@ Section: utils
 Priority: extra
 Maintainer: Michael Stapelberg <michael@stapelberg.de>
 DM-Upload-Allowed: yes
-Build-Depends: debhelper (>= 5)
+Build-Depends: debhelper (>= 5), libiw-dev
 Standards-Version: 3.8.2
 Homepage: http://i3.zekjur.net/i3status
 
index 2cdcb8cf0cbb8f5044791e96cc7d0a612131d658..77bb995b9b945f627968d5599be72c016d21649c 100644 (file)
@@ -4,9 +4,28 @@
 #include <string.h>
 #include <ctype.h>
 #include <limits.h>
+#include <iwlib.h>
 
 #include "i3status.h"
 
+const char *get_wireless_essid() {
+        static char part[512];
+#ifdef LINUX
+        int skfd;
+        if ((skfd = iw_sockets_open()) < 0) {
+                perror("socket");
+                exit(-1);
+        }
+        struct wireless_config cfg;
+        if (iw_get_basic_config(skfd, wlan_interface, &cfg) >= 0)
+                snprintf(part, sizeof(part), "%s", cfg.essid);
+        else part[0] = '\0';
+#else
+        part[0] = '\0';
+#endif
+        return part;
+}
+
 /*
  * Just parses /proc/net/wireless looking for lines beginning with
  * wlan_interface, extracting the quality of the link and adding the
@@ -34,8 +53,8 @@ const char *get_wireless_info() {
                         continue;
                 if ((quality == UCHAR_MAX) || (quality == 0)) {
                         (void)snprintf(part, sizeof(part), "%sW: down%s", color("#FF0000"), endcolor());
-                } else (void)snprintf(part, sizeof(part), "%sW: (%03d%%) %s%s",
-                                color("#00FF00"), quality, get_ip_addr(wlan_interface), endcolor());
+                } else (void)snprintf(part, sizeof(part), "%sW: (%03d%% at %s) %s%s",
+                                color("#00FF00"), quality, get_wireless_essid(), get_ip_addr(wlan_interface), endcolor());
                 return part;
         }