aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config.def.h1
-rw-r--r--netlink-notify.c30
-rw-r--r--netlink-notify.h5
3 files changed, 34 insertions, 2 deletions
diff --git a/config.def.h b/config.def.h
index 34a496e..937bd9f 100644
--- a/config.def.h
+++ b/config.def.h
@@ -20,6 +20,7 @@
/* define notification text messages */
#define TEXT_TOPIC "Netlink Notification"
#define TEXT_NEWLINK "Interface <b>%s</b> is <b>%s</b>."
+#define TEXT_WIRELESS "Interface <b>%s</b> is <b>%s</b> on <b>%s</b>."
#define TEXT_NEWADDR "Interface <b>%s</b> has new %s address\n<b>%s</b>/%d."
#define TEXT_DELLINK "Interface <b>%s</b> has gone away."
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;
}
diff --git a/netlink-notify.h b/netlink-notify.h
index fec85ae..ee61335 100644
--- a/netlink-notify.h
+++ b/netlink-notify.h
@@ -23,11 +23,13 @@
#include <linux/if.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
+#include <linux/wireless.h>
/* we have to undefine this before including net/if.h to
* notget redefined structs, etc. */
#undef __USE_MISC
#include <net/if.h>
#include <netinet/in.h>
+#include <sys/ioctl.h>
#include <sys/socket.h>
/* systemd headers */
@@ -73,6 +75,9 @@ int match_address(struct addresses_seen *addresses_seen, const char *address, un
/*** list_addresses ***/
void list_addresses(struct addresses_seen *addresses_seen, char *interface);
+/*** get_ssid ***/
+void get_ssid(const char *interface, char *essid);
+
/*** newstr_link ***/
char * newstr_link(char *interface, unsigned int flags);