IF_INDEXTONAME(3)IF_INDEXTONAME(3)NAME
if_indextoname, if_nametoindex, if_nameindex, if_freenameindex -
functions for converting interface index to name, and vice versa.
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
char *if_indextoname(unsigned int ifindex, char *ifname);
unsigned int if_nametoindex(const char *ifname);
struct if_nameindex *(void);
void if_freenameindex(struct if_nameindex *ptr);
DESCRIPTION
The functions map interface index to readable interface name (such as
"lo0"), and vice versa.
if_indextoname converts interface index to readable interface name. The
ifname argument must point to a buffer of at least IF_NAMESIZE bytes into
which the interface name corresponding to the specified index is
returned. (IF_NAMESIZE is also defined in <net/if.h> and its value
includes a terminating null byte at the end of the interface name.) This
pointer is also the return value of the function. If there is no
interface corresponding to the specified index, NULL is returned and
errno is set to ENXIO. If there was a system error (such as running out
of memory), errno is set to ENOMEM.
if_nametoindex converts readable interface name to interface index
positive integer value. If the specified interface does not exist, 0
will be returned.
if_nameindex returns an array of if_nameindex structures. if_nameindex
is also defined in <net/if.h>, and is as follows:
struct if_nameindex {
unsigned int if_index; /* 1, 2, ... */
char *if_name; /* null terminated name: "le0",.. */
};
The end of the array of structures is indicated by a structure with an
if_index of 0 and an if_name of NULL . The function returns a NULL
pointer upon an error and errno is set to the approprate value. The
memory used for this array of structures along with the interface names
pointed to by the if_name members is obtained dynamically. This memory
is freed by the if_freenameindex function.
Page 1
IF_INDEXTONAME(3)IF_INDEXTONAME(3)
if_freenameindex takes a pointer that was returned by if_nameindex as
argument (ptr), and it reclaims the region allocated.
DIAGNOSTICS
if_nametoindex returns 0 on error, positive integer on success.
if_indextoname and if_nameindex return NULL on errors.
STANDARDS
These functions are defined in "Basic Socket Interface Extensions for
IPv6" (RFC2553).
Page 2