This manual page is for Mac OS X version 10.6.3

If you are running a different version of Mac OS X, view the documentation locally:

  • In Terminal, using the man(1) command

Reading manual pages

Manual pages are intended as a quick reference for people who already understand a technology.

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

  • For more information about this technology, look for other documentation in the Apple Reference Library.

  • For general information about writing shell scripts, read Shell Scripting Primer.



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

NAME
     if_nametoindex, if_indextoname, if_nameindex, if_freenameindex -- provide mappings between interface
     names and indexes

SYNOPSIS
     #include <sys/types.h>
     #include <sys/socket.h>
     #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);

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 speci-fied specified
     fied 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 <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().

RETURN VALUES
     Upon successful completion, if_nametoindex() returns the index number of the interface.  If the inter-face interface
     face is not found, a value of 0 is returned and errno is set to ENXIO.  A value of 0 is also returned
     if an error occurs while retrieving the list of interfaces via getifaddrs(3).

     Upon successful completion, if_indextoname() returns ifname.  If the interface is not found, a NULL
     pointer is returned and errno is set to ENXIO.  A NULL pointer is also returned if an error occurs
     while retrieving the list of interfaces via getifaddrs(3).

     The if_nameindex() returns a NULL pointer if an error occurs while retrieving the list of interfaces
     via getifaddrs(3), or if sufficient memory cannot be allocated.

SEE ALSO
     getifaddrs(3), networking(4)

STANDARDS
     The if_nametoindex(), if_indextoname(), if_nameindex(), and if_freenameindex() functions conform to RFC
     2553.

HISTORY
     The implementation first appeared in BSDi BSD/OS.

BSD                                           November 23, 2005                                          BSD

Reporting Problems

The way to report a problem with this manual page depends on the type of problem:

Content errors
Report errors in the content of this documentation with the feedback links below.
Bug reports
Report bugs in the functionality of the described tool or API through Bug Reporter.
Formatting problems
Report formatting mistakes in the online version of these pages with the feedback links below.

Did this document help you? Yes It's good, but... Not helpful...