Start of changeif_nametoindex()--Map an Interface Name to its Corresponding Index



  Syntax
  #include  <net/if.h>

  unsigned int if_nametoindex(const char *ifname);

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

The if_nametoindex() function returns the interface index corresponding to name ifname.


Parameters

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


Authorities

No authorization is required.


Return Value

if_nametoindex() returns an unsigned integer. Possible values are:


Error Conditions

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

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

Usage Notes

  1. The interface (line description) name found at ifname is assumed to be in the default coded character set identifier (CCSID) currently in effect for the job.
  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_nametoindex() is used:

#include <net/if.h>
#include <sys/types.h>
#include <errno.h>

void main()
{

  unsigned int interfaceIndex = if_nametoindex("MYETH");
  if (interfaceIndex == 0)
  {
     printf("if_nametoindex() failed with errno =  %d %s \n",
            errno,strerror(errno));
     return;
  }

  ...

}
End of change

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