mirror of
https://github.com/fluencelabs/musl
synced 2025-06-03 10:01:38 +00:00
19 lines
422 B
C
19 lines
422 B
C
#define _GNU_SOURCE
|
|
#include <net/if.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/ioctl.h>
|
|
#include <string.h>
|
|
#include "syscall.h"
|
|
|
|
char *if_indextoname(unsigned index, char *name)
|
|
{
|
|
struct ifreq ifr;
|
|
int fd, r;
|
|
|
|
if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) return 0;
|
|
ifr.ifr_ifindex = index;
|
|
r = ioctl(fd, SIOCGIFNAME, &ifr);
|
|
__syscall(SYS_close, fd);
|
|
return r < 0 ? 0 : strncpy(name, ifr.ifr_name, IF_NAMESIZE);
|
|
}
|