diff options
| author | Hajimu UMEMOTO <ume@FreeBSD.org> | 2002-11-28 17:46:40 +0000 |
|---|---|---|
| committer | Hajimu UMEMOTO <ume@FreeBSD.org> | 2002-11-28 17:46:40 +0000 |
| commit | c86d6b6cb7a649c2aca409bebb9359c001d6bf8d (patch) | |
| tree | 49efe7fab65d31560f144efc5d9dc915a0e19a4f /lib/libc | |
| parent | af084166b5769ef732e8f6ef3a9225d68a5f2894 (diff) | |
Notes
Diffstat (limited to 'lib/libc')
| -rw-r--r-- | lib/libc/net/if_nametoindex.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/libc/net/if_nametoindex.c b/lib/libc/net/if_nametoindex.c index ca92ab7bb7b3..f4748ca4cbcd 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); |
