diff options
author | Christian Hesse <mail@eworm.de> | 2014-10-01 13:10:39 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2014-10-01 13:10:39 +0200 |
commit | a228ec427a4ad92300ffbf2263f28c1e1d6fc18d (patch) | |
tree | a782d9e558d363e1778955d0bdfd18dbf47b85b6 | |
parent | 2ae554021fb6a7c3e8486dc0fa2c48a2e8adf0a0 (diff) | |
download | netlink-notify-a228ec427a4ad92300ffbf2263f28c1e1d6fc18d.tar.gz netlink-notify-a228ec427a4ad92300ffbf2263f28c1e1d6fc18d.tar.zst |
try to get interface name for all interfaces
-rw-r--r-- | netlink-notify.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/netlink-notify.c b/netlink-notify.c index 6570323..ef8a8be 100644 --- a/netlink-notify.c +++ b/netlink-notify.c @@ -234,9 +234,17 @@ int msg_handler (struct sockaddr_nl *nl, struct nlmsghdr *msg) { maxinterface++; if (verbose > 0) - printf("%s: Initializing interface %d.\n", program, maxinterface); + printf("%s: Initializing interface %d: ", program, maxinterface); + + /* get interface name and store it + * in case the interface does no longer exist this may fail, + * use static string '(unknown)' instead */ + if (if_indextoname(maxinterface, ifs[maxinterface].name) == NULL) + strcpy(ifs[maxinterface].name, "(unknown)"); + + if (verbose > 0) + printf("%s\n", ifs[maxinterface].name); - strcpy(ifs[maxinterface].name, "(unknown)"); ifs[maxinterface].state = -1; ifs[maxinterface].deleted = 0; |