aboutsummaryrefslogtreecommitdiffstats
path: root/netlink-notify.c
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2018-03-06 16:31:09 +0100
committerGravatar Christian Hesse <mail@eworm.de>2018-03-06 16:42:01 +0100
commitea2432988cde62b4520e547d8b5d95be489a459a (patch)
tree4396e305cc1f39f2d461de460105d40611109fb5 /netlink-notify.c
parent11150de752942ff5897b5c596dcf72bdbe429f36 (diff)
downloadnetlink-notify-ea2432988cde62b4520e547d8b5d95be489a459a.tar.gz
netlink-notify-ea2432988cde62b4520e547d8b5d95be489a459a.tar.zst
show the SSID for wireless interfaces
Diffstat (limited to 'netlink-notify.c')
-rw-r--r--netlink-notify.c30
1 files changed, 28 insertions, 2 deletions
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;
}