diff options
Diffstat (limited to '')
-rw-r--r-- | libc-top-half/musl/src/network/if_nametoindex.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/network/if_nametoindex.c b/libc-top-half/musl/src/network/if_nametoindex.c new file mode 100644 index 0000000..331413c --- /dev/null +++ b/libc-top-half/musl/src/network/if_nametoindex.c @@ -0,0 +1,18 @@ +#define _GNU_SOURCE +#include <net/if.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <string.h> +#include "syscall.h" + +unsigned if_nametoindex(const char *name) +{ + struct ifreq ifr; + int fd, r; + + if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0; + strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); + r = ioctl(fd, SIOCGIFINDEX, &ifr); + __syscall(SYS_close, fd); + return r < 0 ? 0 : ifr.ifr_ifindex; +} |