Start of changeif_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

See Code disclaimer information for information pertaining to code examples.

The following example shows how if_indextoname() is used:

#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;
  }

  ...

}
End of change

API introduced: V5R4
Top | UNIX-Type APIs | APIs by category