if_nameindex() — Return all network interface names and indexes

Standards

Standards / Extensions C or C++ Dependencies

RFC2553
Single UNIX Specification, Version 3

both z/OS® V1R4

Format

#define _OPEN_SYS_SOCK_IPV6
#include <net/if.h>

struct if_nameindex *if_nameindex(void);
SUSV3:
#define _POSIX_C_SOURCE 200112L
#include <net/if.h>

struct if_nameindex *if_nameindex(void);

General description

The if_nameindex() function returns an array of if_nameindex structures, one structure per interface. The end of the array is indicated by a structure with an if_index of zero and an if_name of NULL.

The if_nameindex structure holds the information about a single interface and is defined as a result of including the <net/if.h> header.

struct if_nameindex {
   unsigned int if_index;  /* 1, 2, ... */
   char       *if_name;   /* null terminated name:  "le0", ... */
}; 

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 calling the if_freenameindex() function.

Returned value

When successful, if_nameindex() returns a pointer to an array of if_nameindex structures. Upon failure, if_nameindex() returns NULL and sets errno to one of the following:

Error Code
Description
ENOMEM
Insufficient storage is available to supply the array.

Related information