if_indextoname Subroutine

Purpose

Maps an interface index into its corresponding name.

Library

Standard C Library <libc.a>

Syntax

#include <net/if.h>
char *if_indextoname(unsigned int ifindex, char *ifname);

Description

When the if_indextoname subroutine is called, the ifname parameter points to a buffer of at least IF_NAMESIZE bytes. The if_indextoname subroutine places the name of the interface in this buffer with the ifindex index.
Note: IF_NAMESIZE is also defined in <net/if.h> and its value includes a terminating null byte at the end of the interface name.

If ifindex is an interface index, the if_indextoname Subroutine returns the ifname value, which points to a buffer containing the interface name. Otherwise, it returns a NULL pointer and sets the errno global value to indicate the error.

If there is no interface corresponding to the specified index, the errno global value is set to ENXIO. If a system error occurs (such as insufficient memory), the errno global value is set to the proper value (such as, ENOMEM).

Parameters

Item Description
ifindex Possible interface index
ifname Possible name of an interface

Error Codes

Item Description
ENXIO There is no interface corresponding to the specified index
ENOMEM Insufficient memory