From 98aa8fbe8027719742958e01b30a044afe200ab3 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 30 Sep 2012 00:01:12 +0000 Subject: [PATCH] Set intf_name in route-linux.c. --- libdnet-stripped/src/route-linux.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/libdnet-stripped/src/route-linux.c b/libdnet-stripped/src/route-linux.c index c0112d071..a80b71b11 100644 --- a/libdnet-stripped/src/route-linux.c +++ b/libdnet-stripped/src/route-linux.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -192,19 +193,31 @@ route_get(route_t *r, struct route_entry *entry) i -= NLMSG_LENGTH(sizeof(*nmsg)); - while (RTA_OK(rta, i)) { + entry->route_gw.addr_type = ADDR_TYPE_NONE; + entry->intf_name[0] = '\0'; + for (rta = RTM_RTA(rmsg); RTA_OK(rta, i); rta = RTA_NEXT(rta, i)) { if (rta->rta_type == RTA_GATEWAY) { - entry->intf_name[0] = '\0'; entry->route_gw.addr_type = entry->route_dst.addr_type; memcpy(entry->route_gw.addr_data8, RTA_DATA(rta), alen); entry->route_gw.addr_bits = alen * 8; - return (0); + } else if (rta->rta_type == RTA_OIF) { + char ifbuf[IFNAMSIZ]; + char *p; + int intf_index; + + intf_index = *(int *) RTA_DATA(rta); + p = if_indextoname(intf_index, ifbuf); + if (p == NULL) + return (-1); + strlcpy(entry->intf_name, ifbuf, sizeof(entry->intf_name)); } - rta = RTA_NEXT(rta, i); } - errno = ESRCH; + if (entry->route_gw.addr_type == ADDR_TYPE_NONE) { + errno = ESRCH; + return (-1); + } - return (-1); + return (0); } int @@ -229,7 +242,7 @@ route_loop(route_t *r, route_handler callback, void *arg) if (i < 11 || !(iflags & RTF_UP)) continue; - entry.intf_name[0] = '\0'; + strlcpy(entry.intf_name, ifbuf, sizeof(entry.intf_name)); entry.route_dst.addr_type = entry.route_gw.addr_type = ADDR_TYPE_IP; @@ -262,7 +275,7 @@ route_loop(route_t *r, route_handler callback, void *arg) if (i < 21 || !(iflags & RTF_UP)) continue; - entry.intf_name[0] = '\0'; + strlcpy(entry.intf_name, ifbuf, sizeof(entry.intf_name)); snprintf(buf, sizeof(buf), "%s:%s:%s:%s:%s:%s:%s:%s/%d", d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],