HP-UX IPv6 Porting Guide (February 2007)
Identifying Local Interface Names and Indexes
Index-to-Name
Chapter 12 49
Index-to-Name
The second function maps an interface index into its corresponding name.
Header Files
#include <net/if.h>
Syntax
char *if_indextoname(unsigned int ifindex, char *ifname);
The
ifname
parameter must point to a buffer at least IF_NAMESIZE bytes large. The function
returns to
ifname
the interface name of the specified index. (IF_NAMESIZE is also defined in
<net/if.h> and its value includes a terminating NULL byte at the end of the interface
name.) The pointer to if_indextoname also returns the value of the function. If no interface
corresponds to the specified index, the function returns NULL, and sets errno to ENXIO. If a
system error occurred (such as running out of memory), if_indextoname() returns NULL
and sets errno to the proper value (that is, ENOMEM).
Returning All Interface Names and Indexes
The if_nameindex structure holds the information about a single interface. The definition of
the structure is in the <net/if.h> header file.
struct if_nameindex {
unsigned int if_index; /* 1, 2, ... */
char *if_name; /* null terminated name: "le0", .. */
};
The final function returns an array of if_nameindex structures, returning one structure per
interface.
struct if_nameindex *if_nameindex(void);
The if_nameindex function signals the end of the array of structures by returning a structure
with a zero
if_index
value and a NULL
if_name
value. If an error occurred, the function
returns a NULL pointer, and sets errno to the appropriate value.