Sockets Library Functions if_nametoindex(3SOCKET)
NAME
if_nametoindex, if_indextoname, if_nameindex,
if_freenameindex - routines to map Internet Protocol network
interface names and interface indexesSYNOPSIS
cc [ flag... ] file... -lsocket [ library... ]
#include
unsigned int if_nametoindex(const char *ifname);
char *if_indextoname(unsigned int ifindex, char *ifname);
struct if_nameindex *if_nameindex(void)
void if_freenameindex(struct if_nameindex *ptr);
PARAMETERS
ifname interface name ifindex interface indexptr pointer returned by if_nameindex()
DESCRIPTION
This API defines two functions that map between an Internet Protocol network interface name and index, a third function that returns all the interface names and indexes, and a fourth function to return the dynamic memory allocated by the previous function. Network interfaces are normally known by names such as eri0, sl1, ppp2, and the like. The ifname argument must point to abuffer of at least IF_NAMESIZE bytes into which the inter-
face name corresponding to the specified index is returned.IF_NAMESIZE is defined in
a terminating null byte at the end of the interface name.and its value includes if_nametoindex() The if_nametoindex() function returns
the interface index corresponding to the interface name pointed to by the ifname pointer. If the specified interface name does not exist, the return value is 0, and errno is set toSunOS 5.11 Last change: 28 Jan 2009 1
Sockets Library Functions if_nametoindex(3SOCKET)
ENXIO. If there was a system error, such as running out of memory, the return value is 0 and errno is set to the proper value, for example, ENOMEM.if_indextoname() The if_indextoname() function maps an
interface index into its corresponding name. This pointer is also the return value of the function. If there is nointerface corresponding to the speci-
fied index, NULL is returned, and errno is set to ENXIO, if there was a system error, such as running out ofmemory, if_indextoname() returns NULL
and errno would be set to the proper value, for example, ENOMEM.if_nameindex() The if_nameindex() function returns an
array of if_nameindex structures, one
structure per interface. Theif_nameindex structure holds the
information about a single interface and is defined when theheader is included: struct if_nameindex
unsigned int if_index; /* 1, 2, ... */
char *if_name; /* "net0", ... */
}; While any IPMP IP interfaces arereturned by if_nameindex(), the under-
lying IP interfaces that comprise each IPMP group are not returned. The end of the array of structures is indicated by a structure with anif_index of 0 and an if_name of NULL.
The function returns a null pointer upon an error and sets errno to the appropriate value. The memory used for this array of structures along with the interface names pointed to by theif_name members is obtained dynami-
cally. This memory is freed by theif_freenameindex() function.
if_freenameindex() The if_freenameindex() function frees
the dynamic memory that was allocatedSunOS 5.11 Last change: 28 Jan 2009 2
Sockets Library Functions if_nametoindex(3SOCKET)
by if_nameindex(). The argument to
this function must be a pointer thatwas returned by if_nameindex().
ATTRIBUTES
See attributes(5) for descriptions of the following attri-
butes:____________________________________________________________
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|_____________________________|_____________________________|
| Availability | system/library (32-bit) |
| | SUNWcslx (64-bit) |
|_____________________________|_____________________________|
| MT-Level | MT-Safe |
|_____________________________|_____________________________|
SEE ALSO
ifconfig(1M), if_nametoindex(3XNET), attributes(5), if(7P)
SunOS 5.11 Last change: 28 Jan 2009 3