NAME | SYNOPSIS | API RESTRICTIONS | DESCRIPTION | RETURN VALUES | ATTRIBUTES
$(OS_DIR)/lib/libc.a #include <sys/types.h> #include <sys/socket.h> #include <net/if.h>unsigned int if_nametoindex(const char * ifname);
The function or functions documented here may not be used safely in all application contexts with all APIs provided in the ChorusOS 5.0 product.
See API(5FEA) for details.
The functions map an interface index to a readable interface name (such as "lo0" ), and vice versa.
if_nametoindex() converts a readable interface name to an interface index.
If the specified interface does not exist, 0 is returned.
if_indextoname() converts an interface index to a readable interface name. The ifname argument must point to a buffer of at least IF_NAMESIZE bytes. The interface name corresponding to the specified index is returned in this buffer. (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.
if_nameindex() returns an array of if_nameindex structures.
if_nametoindex 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 on error. 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.
if_freenameindex() takes a pointer that was returned by if_nameindex() as argument ( ptr ), and it reclaims the region allocated.
if_nametoindex() returns 0 on error, positive integer on success.
if_indextoname() and if_nameindex() return NULL on errors.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
NAME | SYNOPSIS | API RESTRICTIONS | DESCRIPTION | RETURN VALUES | ATTRIBUTES