From f16afb7e167e23718ae3d8573082a410b718ae4c Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Wed, 6 Jan 2021 21:15:49 +0100 Subject: [PATCH] ra: align ifindex resolving Use ioctl SIOCGIFINDEX to resolve ifindex similar as in init_dhcpv6 Signed-off-by: Hans Dedecker (cherry picked from commit 2b6959dfe2095402e004b63d9aca9900c074abb6) --- src/ra.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ra.c b/src/ra.c index 898f449..9fcdb31 100644 --- a/src/ra.c +++ b/src/ra.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -76,6 +77,8 @@ static void ra_send_rs(int signal __attribute__((unused))); int ra_init(const char *ifname, const struct in6_addr *ifid, unsigned int options, unsigned int holdoff_interval) { + struct ifreq ifr; + ra_options = options; ra_holdoff_interval = holdoff_interval; @@ -84,11 +87,12 @@ int ra_init(const char *ifname, const struct in6_addr *ifid, if (sock < 0) goto failure; - if_index = if_nametoindex(ifname); - if (!if_index) + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1); + if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0) goto failure; - strncpy(if_name, ifname, sizeof(if_name) - 1); + if_index = ifr.ifr_ifindex; lladdr = *ifid; rtnl = socket(AF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_ROUTE); -- 2.30.2