From ea2432988cde62b4520e547d8b5d95be489a459a Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 6 Mar 2018 16:31:09 +0100 Subject: show the SSID for wireless interfaces --- netlink-notify.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'netlink-notify.c') diff --git a/netlink-notify.c b/netlink-notify.c index d197dd2..bc41954 100644 --- a/netlink-notify.c +++ b/netlink-notify.c @@ -111,12 +111,38 @@ void list_addresses(struct addresses_seen *addresses_seen, char *interface) { putchar('\n'); } +/*** get_ssid ***/ +void get_ssid(const char *interface, char *essid) { + int sockfd; + struct iwreq wreq; + + memset(&wreq, 0, sizeof(struct iwreq)); + snprintf(wreq.ifr_name, IFNAMSIZ, interface); + wreq.u.essid.pointer = essid; + wreq.u.essid.length = IW_ESSID_MAX_SIZE + 1; + + if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) + return; + + if (ioctl(sockfd, SIOCGIWESSID, &wreq) == -1) + return; +} + /*** newstr_link ***/ char * newstr_link(char *interface, unsigned int flags) { char *notifystr; + char essid[IW_ESSID_MAX_SIZE + 1]; + + memset(&essid, 0, IW_ESSID_MAX_SIZE + 1); + get_ssid(interface, essid); - notifystr = malloc(sizeof(TEXT_NEWLINK) + strlen(interface) + 4); - sprintf(notifystr, TEXT_NEWLINK, interface, (flags & CHECK_CONNECTED) ? "up" : "down"); + if (strlen(essid) == 0) { + notifystr = malloc(sizeof(TEXT_NEWLINK) + strlen(interface) + 4); + sprintf(notifystr, TEXT_NEWLINK, interface, (flags & CHECK_CONNECTED) ? "up" : "down"); + } else { + notifystr = malloc(sizeof(TEXT_WIRELESS) + strlen(interface) + 4 + strlen(essid)); + sprintf(notifystr, TEXT_WIRELESS, interface, (flags & CHECK_CONNECTED) ? "up" : "down", essid); + } return notifystr; } -- cgit v1.2.3-54-g00ecf