Name

if_nametoindex, if_indextoname, if_nameindex, if_freenameindex
- return all network interface names and indexes

Synopsis

  #include <net/if.h>
  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);

Return values

Upon successful completion, if_nametoindex returns the index number of the interface. If the interface is not found, a value of 0 is returned and errno is set to ENXIO.

Upon successful completion, if_indextoname returns ifname. If the interface is not found, a NULL pointer is returned and errno is set to ENXIO.

The if_nameindex returns a NULL pointer if sufficient memory cannot be allocated.


Detailed description

The if_nametoindex function maps the interface name specified in ifname to its corresponding index. If the specified interface does not exist, it returns 0.

The if_indextoname function maps the interface index specified in ifindex to it corresponding name, which is copied into the buffer pointed to by ifname, which must be of at least IFNAMSIZ bytes. This pointer is also the return value of the function. If there is no interface corresponding to the specified index, NULL is returned.

The if_nameindex function returns an array of if_nameindex structures, one structure per interface, as defined in the include file

  #include <net/if.h.>The if_nameindex structure contains at least the following entries:
    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. A NULL pointer is returned upon an error.

The if_freenameindex function frees the dynamic memory that was allocated by if_nameindex.


See also

The if_nametoindex, if_indextoname, if_nameindex, and if_freenameindex functions conform to RFC 2553.
The implementation first appeared in BSDi.

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top