DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

if(3N)


if_nameindex, if_nametoindex, if_indextoname, if_freenameindex -- interface identification functions

Synopsis

cc [options] file -lsocket
#include <net/if.h>

unsigned int if_nametoindex(const char * name);

char *if_indextoname(unsigned int index, char * name);

struct if_nameindex *if_nameindex(void);

void if_freenameindex(struct if_nameindex * ptr);

Description

An interface index is a small positive integer (greater than 0) that is used to identify the local interface on which a multicast group is joined. It is also used to identify the interface on which a datagram is received, or to specify the interface on which a datagram is to be sent.

if_nametoindex maps an interface name into its corresponding index. It returns 0 if the specified interface does not exist.

if_indextoname maps an interface index into its corresponding name. The name argument must point to a buffer of at least IFNAMSIZ bytes which is used to hold the returned interface name (including a terminating null character). This pointer is also the return value of the function. If there is not interface corresponding to the specified index, if_indextoname returns NULL.

if_nameindex returns an array of if_nameindex structures, one structure per interface. An if_nameindex structure is defined as follows:

   struct if_nameindex {
   	unsigned int if_index; /* 1, 2, ... */
   	char	    *if_name;  /* null-terminated name */
   };
The end of the array of structures is indicated by a structure with an if_index of 0 and an if_name of NULL. if_nameindex returns a NULL pointer on error. The memory used for the array of structures and if_name members is obtained dynamically.

if_freenameindex frees the dynamic memory that was allocated by if_nameindex. The argument ptr must be a pointer that was previously returned by if_nameindex.

References

getsockopt(3sock), ipv6(7tcp)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004