-static char *getifname(int interface, char *name, size_t len) {
- int fd = -1;
- char *ret = NULL;
- struct ifreq ifr;
-
- assert(interface >= 0);
-
- if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
- daemon_log(LOG_ERR, "socket(): %s", strerror(errno));
- goto finish;
- }
-
- memset(&ifr, 0, sizeof(ifr));
- ifr.ifr_ifindex = interface;
-
- if (ioctl(fd, SIOCGIFNAME, &ifr) < 0) {
- daemon_log(LOG_ERR, "SIOCGIFNAME: %s\n", strerror(errno));
- goto finish;
- }
-
- strncpy(name, ifr.ifr_name, len-1);
- name[len-1] = 0;
- ret = name;
-
-finish:
- if (fd >= 0)
- close(fd);
-
- return ret;
-}
-