ADC Home > Reference Library > Reference > Mac OS X > Mac OS X Man Pages

 

This document is a Mac OS X manual page. Manual pages are a command-line technology for providing documentation. You can view these manual pages locally using the man(1) command. These manual pages come from many different sources, and thus, have a variety of writing styles.

For more information about the manual page format, see the manual page for manpages(5).



IF_NAMETOINDEX(3)        BSD Library Functions Manual        IF_NAMETOINDEX(3)

NAME
     if_freenameindex, if_indextoname, if_nameindex, if_nametoindex -- convert interface index to name, and
     vice versa

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <sys/types.h>
     #include <sys/socket.h>
     #include <net/if.h>

     void
     if_freenameindex(struct if_nameindex *ptr);

     char *
     if_indextoname(unsigned ifindex, char *ifname);

     struct if_nameindex *
     if_nameindex(void);

     unsigned int
     if_nametoindex(const char *ifname);

DESCRIPTION
     The functions map interface index to readable interface name (such as ``lo0''), and vice versa.

     if_nametoindex() converts readable interface name to interface index

     If the specified interface does not exist, 0 will be returned.

     if_indextoname() converts interface index to readable interface name.  The ifname argument must point
     to a buffer of at least IF_NAMESIZE bytes into which the interface name corresponding to the specified
     index is returned.  (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 upon an 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.

DIAGNOSTICS
     if_nametoindex() returns 0 on error, positive integer on success.  if_indextoname() and if_nameindex()
     return NULL on errors.

SEE ALSO
     R. Gilligan, S.  Thomson, J. Bound, and W. Stevens, ``Basic Socket Interface Extensions for IPv6,''
     RFC2553, March 1999.

HISTORY
     The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit.

STANDARDS
     These functions are defined in ``Basic Socket Interface Extensions for IPv6'' (RFC2533).

BSD                              May 21, 1998                              BSD

Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.