source:
azure_iot_hub_mbedtls/trunk/musl-1.1.18/src/network/if_indextoname.c@
413
Last change on this file since 413 was 398, checked in by , 5 years ago | |
---|---|
|
|
File size: 509 bytes |
Line | |
---|---|
1 | #define _GNU_SOURCE |
2 | #include <net/if.h> |
3 | #include <sys/socket.h> |
4 | #include <sys/ioctl.h> |
5 | #include <string.h> |
6 | #include <errno.h> |
7 | #include "syscall.h" |
8 | |
9 | char *if_indextoname(unsigned index, char *name) |
10 | { |
11 | struct ifreq ifr; |
12 | int fd, r; |
13 | |
14 | if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0; |
15 | ifr.ifr_ifindex = index; |
16 | r = ioctl(fd, SIOCGIFNAME, &ifr); |
17 | __syscall(SYS_close, fd); |
18 | if (r < 0) { |
19 | if (errno == ENODEV) errno = ENXIO; |
20 | return 0; |
21 | } |
22 | return strncpy(name, ifr.ifr_name, IF_NAMESIZE); |
23 | } |
Note:
See TracBrowser
for help on using the repository browser.