summaryrefslogtreecommitdiffstats
path: root/lib/libc/net/if_nametoindex.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/net/if_nametoindex.c')
-rw-r--r--lib/libc/net/if_nametoindex.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/libc/net/if_nametoindex.c b/lib/libc/net/if_nametoindex.c
index ca92ab7..f4748ca 100644
--- a/lib/libc/net/if_nametoindex.c
+++ b/lib/libc/net/if_nametoindex.c
@@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/sockio.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <ifaddrs.h>
@@ -59,9 +60,21 @@ __FBSDID("$FreeBSD$");
unsigned int
if_nametoindex(const char *ifname)
{
+ int s;
+ struct ifreq ifr;
struct ifaddrs *ifaddrs, *ifa;
unsigned int ni;
+ s = _socket(AF_INET, SOCK_DGRAM, 0);
+ if (s != -1) {
+ strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+ if (_ioctl(s, SIOCGIFINDEX, &ifr) != -1) {
+ _close(s);
+ return (ifr.ifr_index);
+ }
+ _close(s);
+ }
+
if (getifaddrs(&ifaddrs) < 0)
return(0);
OpenPOWER on IntegriCloud