TCP/IP Programming Manual
#include <if.h>
#include <in.h>
#include <in6.h>
#include <netdb.h>
struct if_nameindex *if_nameindex(void);
TAL Synopsis
?NOLIST, SOURCE SOCKDEFT
?NOLIST, SOURCE SOCKPROC
return_value = if_nameindex();
INT(32) return_value;
Errors
Upon successful completion, this function returns a pointer to an array of if_nameindex structures.
The end of the array is a structure that has an if_index value of 0 (zero) and an if_name value
that is NULL pointer.
Otherwise, this function returns NULL.
Usage Guidelines
When an interface (subnet) is created, that interface is assigned a unique number called an interface
index. The interface index identifies the interface used to send or receive multicast datagrams.
Interface index numbers start with 1.
The if_nameindex function is one of four functions used to manage interface indexes.
NOTE: Memory is dynamically allocated for the array of structures returned by this function and
for the interface names pointed to by the if_name members of the structures. Use the
if_freenameindex function to return this memory to the system when it is no longer needed.
Examples
ifnameindex = if_nameindex();
if (ifnameindex == NULL){
perror("if_nameindex failed");
}
freep = ifnameindex;
while (ifnameindex->if_index){
printf("if_nameindex: index, name: %i, %s\n",
ifnameindex->if_index, ifnameindex -> if_name);
ifnameindex++;
}
if_freenameindex(freep);
if_nametoindex
The if_nametoindex function maps an interface name to its corresponding index. (This function
is supported for NonStop TCP/IP only.)
C Synopsis
#include <netdb.h>
unsigned int if_nametoindex(const char *ifname);
TAL Synopsis
?NOLIST, SOURCE SOCKDEFT
?NOLIST, SOURCE SOCKPROC
if_nametoindex 133