summaryrefslogtreecommitdiffstats
path: root/lib/libc/net/if_nametoindex.c
diff options
context:
space:
mode:
authorume <ume@FreeBSD.org>2002-11-28 17:46:40 +0000
committerume <ume@FreeBSD.org>2002-11-28 17:46:40 +0000
commitcdeea51f465d7a6b284af099f17e8c09471975e5 (patch)
tree49efe7fab65d31560f144efc5d9dc915a0e19a4f /lib/libc/net/if_nametoindex.c
parenta6ddd1313b01a2d725c73a504e092e360cc9354c (diff)
downloadFreeBSD-src-cdeea51f465d7a6b284af099f17e8c09471975e5.zip
FreeBSD-src-cdeea51f465d7a6b284af099f17e8c09471975e5.tar.gz
try SIOCGIFINDEX 1st to be able to use network aliasing.
Submitted by: jlemon Approved by: re
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