HP-UX IPv6 Porting Guide (September 2004)
Table Of Contents
- About This Document
- 1 Introduction
- 2 IPv6 Addressing
- 3 Data Structure Changes
- 4 Migrating Applications from IPv4 to IPv6
- 5 Overview of IPv4 and IPv6 Call Set-up
- 6 Function Calls Converting Names to Addresses
- 7 Function Calls Converting IP addresses to Names
- 8 Reading Error Messages
- 9 Freeing Memory
- 10 Converting Binary and Text Addresses
- 11 Testing for Scope and Type of IPv6 addresses using Macros
- 12 Identifying Local Interface Names and Indexes
- 13 Configuring or Querying an Interface using IPv6 ioctl() Function Calls
- 14 Verifying IPv6 Installation
- 15 Sample Client/Server Programs
- A IPv4 to IPv6 Quick Reference Guide

Identifying Local Interface Names and Indexes
Index-to-Name
Chapter 12 53
Index-to-Name
The second function maps an interface index into its corresponding name.
Header Files
#include <net/if.h>
Syntax
char *if_indextoname(unsigned int ifindex, char *ifname);
The
ifname
parameter must point to a buffer at least IF_NAMESIZE bytes large. The function
returns to
ifname
the interface name of the specified index. (IF_NAMESIZE is also defined in
<net/if.h> and its value includes a terminating NULL byte at the end of the interface
name.) The pointer to if_indextoname also returns the value of the function. If no interface
corresponds to the specified index, the function returns NULL, and sets errno to ENXIO. If a
system error occurred (such as running out of memory), if_indextoname() returns NULL
and sets errno to the proper value (that is, ENOMEM).
Returning All Interface Names and Indexes
The if_nameindex structure holds the information about a single interface. The definition of
the structure is in the <net/if.h> header file.
struct if_nameindex {
unsigned int if_index; /* 1, 2, ... */
char *if_name; /* null terminated name: "le0", .. */
};
The final function returns an array of if_nameindex structures, returning one structure per
interface.
struct if_nameindex *if_nameindex(void);
The if_nameindex function signals the end of the array of structures by returning a structure
with a zero
if_index
value and a NULL
if_name
value. If an error occurred, the function
returns a NULL pointer, and sets errno to the appropriate value.