diff options
author | Michael Stapelberg <michael@stapelberg.de> | 2009-10-01 17:43:32 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2009-10-01 17:43:32 +0200 |
commit | b2292e770ef96c8abe8cc7134e8defb0b49e902f (patch) | |
tree | 204e7161df0e09f6af8fb8bfb145b70244e58a6d /src/get_wireless_info.c | |
parent | cdb450376e52bad45969c87a44908ef6e9997f39 (diff) |
Implement getting the wireless ESSID
This adds a dependency for libiw
Diffstat (limited to 'src/get_wireless_info.c')
-rw-r--r-- | src/get_wireless_info.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/get_wireless_info.c b/src/get_wireless_info.c index 2cdcb8c..77bb995 100644 --- a/src/get_wireless_info.c +++ b/src/get_wireless_info.c @@ -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; } |