mirror of https://git.musl-libc.org/git/musl
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
417 B
19 lines
417 B
|
15 years ago
|
#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, 0)) < 0) return -1;
|
||
|
|
strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
|
||
|
|
r = ioctl(fd, SIOCGIFINDEX, &ifr);
|
||
|
|
__syscall(SYS_close, fd);
|
||
|
|
return r < 0 ? r : ifr.ifr_ifindex;
|
||
|
|
}
|