if_nameindex(3) Library Functions Manual if_nameindex(3) if_nameindex, if_freenameindex - C (libc, -lc) #include struct if_nameindex *if_nameindex(void); void if_freenameindex(struct if_nameindex *ptr); if_nameindex() if_nameindex, . if_nameindex : unsigned int if_index; /* (1, 2, ) */ char *if_name; /* Null (<>, . .) */ if_index . if_name ( null). if_index if_name NULL. , if_nameindex(), if_freenameindex(), . On success, if_nameindex() returns pointer to the array; on error, NULL is returned, and errno is set to indicate the error. if_nameindex() errno : ENOBUFS . if_nameindex() , socket(2), bind(2), ioctl(2), getsockname(2), recvmsg(2), sendto(2) malloc(3). attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |if_nameindex(), | | MT-Safe | |if_freenameindex() | | | +----------------------------+----------------------------------------------------------+--------------------------+ POSIX.1-2008, RFC 3493. glibc 2.1. POSIX.1-2001. BSDi. Before glibc 2.3.4, the implementation supported only interfaces with IPv4 addresses. Support of interfaces that don't have IPv4 addresses is available only on kernels that support netlink. , , , . : $ ./a.out 1: lo 2: wlan0 3: em1 #include #include #include #include int main(void) { struct if_nameindex *if_ni, *i; if_ni = if_nameindex(); if (if_ni == NULL) { perror("if_nameindex"); exit(EXIT_FAILURE); } for (i = if_ni; !(i->if_index == 0 && i->if_name == NULL); i++) printf("%u: %s\n", i->if_index, i->if_name); if_freenameindex(if_ni); exit(EXIT_SUCCESS); } getsockopt(2), setsockopt(2), getifaddrs(3), if_indextoname(3), if_nametoindex(3), ifconfig(8) () Azamat Hackimov , Dmitriy S. Seregin , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux 6.9.1 15 2024 . if_nameindex(3)