MirBSD manpage: if_freenameindex(3), if_indextoname(3), if_nameindex(3), if_nametoindex(3)

IF_NAMETOINDEX(3)          BSD Programmer's Manual           IF_NAMETOINDEX(3)


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


     #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_freenameindex(struct if_nameindex *ptr);


     These functions map interface indexes to interface names (such as "lo0"),
     and vice versa.

     The if_nametoindex() function converts an interface name specified by the
     ifname argument to an interface index (positive integer value). If the
     specified interface does not exist, 0 will be returned.

     if_indextoname() converts an interface index specified by the ifindex ar-
     gument to an 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 NUL byte at the end of
     the interface name.) This pointer is also the return value of the func-
     tion. If there is no interface corresponding to the specified index, NULL
     is returned.

     if_nameindex() returns an array of if_nameindex structures. if_nameindex
     is also defined in <net/if.h>, and is as follows:

           struct if_nameindex {
                   unsigned int      if_index;     /* 1, 2, ... */
                   char             *if_name;      /* NUL-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. The function returns a null pointer
     on error. The memory used for this array of structures along with the in-
     terface 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.


     getifaddrs(3), networking(4)

     R. Gilligan, S. Thomson, J. Bound, and W. Stevens, Basic Socket Interface
     Extensions for IPv6, RFC 2553, March 1999.


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

MirBSD #10-current               May 21, 1998                                1

Generated on 2022-12-24 01:00:14 by $MirOS: src/scripts/roff2htm,v 1.113 2022/12/21 23:14:31 tg Exp $ — This product includes material provided by mirabilos.

These manual pages and other documentation are copyrighted by their respective writers; their sources are available at the project’s CVSweb, AnonCVS and other mirrors. The rest is Copyright © 2002–2022 MirBSD.

This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report — diffs preferred.

Kontakt / Impressum & Datenschutzerklärung