source: azure_iot_hub/trunk/musl-1.1.18/src/network/if_indextoname.c@ 388

Last change on this file since 388 was 388, checked in by coas-nagasima, 5 years ago

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
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
9char *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.