if_nameindex Subroutine

Purpose

Retrieves index and name information for all interfaces.

Library

The Standard C Library (<libc.a>)

Syntax

#include <net/if.h>

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

Description

The if_nameindex subroutine returns an array of if_nameindex structures (one per interface).

The memory used for this array of structures is obtained dynamically. The interface names pointed to by the if_name members are obtained dynamically as well. This memory is freed by the if_freenameindex subroutine.

The function returns a NULL pointer upon error, and sets the errno global value to the appropriate value. If successful, the function returns an array of structures. The end of an array of structures is indicated by a structure with an if_index value of 0 and an if_name value of NULL.