diff options
author | Michael Stapelberg <michael@stapelberg.de> | 2009-07-21 19:07:30 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2009-07-21 19:07:30 +0200 |
commit | 6fda988f360b3145d5772b6964f336dd652357ea (patch) | |
tree | 31647729cafbadf3d9e8213f148e8510d4e9dfed /src/get_wireless_info.c | |
parent | 045c88dfe39c488340e0296e36ea785e9aa77e84 (diff) |
Use own files for each function, add get_ipv6_addr.c
Diffstat (limited to 'src/get_wireless_info.c')
-rw-r--r-- | src/get_wireless_info.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/get_wireless_info.c b/src/get_wireless_info.c new file mode 100644 index 0000000..fd0c60b --- /dev/null +++ b/src/get_wireless_info.c @@ -0,0 +1,44 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include <limits.h> + +#include "i3status.h" + +/* + * Just parses /proc/net/wireless looking for lines beginning with + * wlan_interface, extracting the quality of the link and adding the + * current IP address of wlan_interface. + * + */ +const char *get_wireless_info() { + char buf[1024]; + static char part[512]; + char *interfaces; + memset(buf, 0, sizeof(buf)); + memset(part, 0, sizeof(part)); + + slurp("/proc/net/wireless", buf, sizeof(buf)); + + interfaces = skip_character(buf, '\n', 1) + 1; + while ((interfaces = skip_character(interfaces, '\n', 1)+1) < buf+strlen(buf)) { + while (isspace((int)*interfaces)) + interfaces++; + if (!BEGINS_WITH(interfaces, wlan_interface)) + continue; + int quality; + if (sscanf(interfaces, "%*[^:]: 0000 %d", &quality) != 1) + continue; + if ((quality == UCHAR_MAX) || (quality == 0)) { + if (use_colors) + (void)snprintf(part, sizeof(part), "%sW: down", color("#FF0000")); + else (void)snprintf(part, sizeof(part), "W: down"); + } else (void)snprintf(part, sizeof(part), "%sW: (%03d%%) %s", + color("#00FF00"), quality, get_ip_addr(wlan_interface)); + return part; + } + + return part; +} + |