From a228ec427a4ad92300ffbf2263f28c1e1d6fc18d Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 1 Oct 2014 13:10:39 +0200 Subject: try to get interface name for all interfaces --- netlink-notify.c | 12 ++++++++++-- 1 file 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; -- cgit v1.2.3-70-g09d2