if_indextoname()--Map an Interface Index to its Corresponding Name



  Syntax
  #include  <net/if.h>

  char *if_indextoname(unsigned int ifindex, char *ifname);

  Service Program Name: QSOSRV2
  Default Public Authority: *USE
  Threadsafe: Yes

The if_indextoname() function places the name of the interface with index ifindex into the buffer pointed at by ifname. When this function is called, ifname must point to a buffer of at least IFNAMSIZ bytes.


Parameters

ifindex  (Input) 
Interface index.

ifname  (Output) 
Pointer to a null terminated string containing the interface (line description) name returned.


Authorities

No authorization is required.


Return Value

if_indextoname() returns a pointer to a null terminated string containing the interface (line description) name. Possible values are:


Error Conditions

When if_indextoname() fails, errno can be set to one of the following:

[ENXIO]
The specified interface index does not exist.
[EFAULT]
The buffer pointed to by ifname can not be accessed.

Usage Notes

  1. The interface (line description) name stored at ifname will be returned in the default coded character set identifier (CCSID) currently in effect for the job. If this is not a single byte CCSID, then storage greater than IFNAMSIZ (16) bytes may be needed. 22 bytes is large enough for all CCSIDs.

  2. It is important to note that the term "Interface" refers to the name on a line description (i.e. a physical interface) for this API. Other parts of the operating system, when refering to "Interface," mean an IP address.


Related Information


Example

The following example shows how if_indextoname() is used.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#include <net/if.h>
#include <sys/types.h>
#include <errno.h>
ref
void main()
{
  char interfaceName[IFNAMSIZ];
  char *interface = if_indextoname(1, &interfaceName); /* retrieve the name of interface 1 */

  if (interface == NULL)
  {
     printf("if_indextoname() failed with errno =  %d %s \n",
            errno,strerror(errno));
     return;
  }

  ...

}


API introduced: V5R4

[ Back to top | UNIX-Type APIs | APIs by category ]