Manual Pages for Linux CentOS command on man if_nameindex
MyWebUniversity

Manual Pages for Linux CentOS command on man if_nameindex

IFNAMEINDEX(3) Linux Programmer's Manual IFNAMEINDEX(3)

NAME

ifnameindex, iffreenameindex - get network interface names and indexes SYNOPSIS

#include struct ifnameindex *ifnameindex(void); void iffreenameindex(struct ifnameindex *ptr); DESCRIPTION The ifnameindex() function returns an array of ifnameindex strucā€ tures, each containing information about one of the network interfaces on the local system. The ifnameindex structure contains at least the following entries: unsigned int ifindex; /* Index of interface (1, 2, ...) */

char *ifname; /* Null-terminated name ("eth0", etc.) */ The ifindex field contains the interface index. The ifaname field

points to the null-terminated interface name. The end of the array is indicated by entry with ifindex set to zero and ifaname set to NULL. The data structure returned by ifnameindex() is dynamically allocated and should be freed using iffreenameindex() when no longer needed. RETURN VALUE On success, ifnameindex() returns pointer to the array; on error, a NULL pointer is returned, and errno is set appropriately. ERRORS ifnameindex() may fail and set errno if: ENOBUFS Insufficient resources available. ifnameindex() may also fail for any of the errors specified for socket(2), bind(2), ioctl(2), getsockname(2), recvmsg(2), sendto(2), or malloc(3). VERSIONS The ifnameindex() function first appeared in glibc 2.1, but 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. CONFORMING TO

RFC 3493, POSIX.1-2001. This function first appeared in BSDi. EXAMPLE The program below demonstrates the use of the functions described on this page. An example of the output this program might produce is the following:

$ ./a.out 1: lo 2: wlan0 3: em1 Program source

#include

#include

#include

#include int main(int argc, char *argv[]) { struct ifnameindex *ifni, *i; ifni = ifnameindex(); if (ifni == NULL) { perror("ifnameindex"); exit(EXITFAILURE); }

for (i = ifni; ! (i->ifindex == 0 && i->ifname == NULL); i++)

printf("%u: %s\n", i->ifindex, i->ifname); iffreenameindex(ifni); exit(EXITSUCCESS); } SEE ALSO getsockopt(2), setsockopt(2), getifaddrs(3), ifindextoname(3), ifnametoindex(3), ifconfig(8) COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

GNU 2012-11-21 IFNAMEINDEX(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™