1if_nametoindex(3XNXE/TO)pen Networking Services Library Functiiofn_snametoindex(3XNET)
2
3
4
6 if_nametoindex, if_indextoname, if_nameindex, if_freenameindex - func‐
7 tions to map Internet Protocol network interface names and interface
8 indexes
9
11 cc [ flag... ] file... -lxnet [ library... ]
12 #include <net/if.h>
13
14 unsigned int if_nametoindex(const char *ifname);
15
16
17 char *if_indextoname(unsigned int ifindex, char *ifname);
18
19
20 struct if_nameindex *if_nameindex(void)
21
22
23 void if_freenameindex(struct if_nameindex *ptr);
24
25
27 These functions support the following parameters:
28
29 ifname interface name
30
31
32 ifindex interface index
33
34
35 ptr pointer returned by if_nameindex()
36
37
39 This API defines two functions that map between an Internet Protocol
40 network interface name and index, a third function that returns all the
41 interface names and indexes, and a fourth function to return the
42 dynamic memory allocated by the previous function.
43
44
45 Network interfaces are normally known by names such as eri0, sl1, ppp2,
46 and the like. The ifname argument must point to a buffer of at least
47 IF_NAMESIZE bytes into which the interface name corresponding to the
48 specified index is returned. IF_NAMESIZE is defined in <net/if.h> and
49 its value includes a terminating null byte at the end of the interface
50 name.
51
52 if_nametoindex() The if_nametoindex() function returns the inter‐
53 face index corresponding to the interface name
54 pointed to by the ifname pointer. If the speci‐
55 fied interface name does not exist, the return
56 value is 0, and errno is set to ENXIO. If there
57 was a system error, such as running out of mem‐
58 ory, the return value is 0 and errno is set to
59 the proper value, for example, ENOMEM.
60
61
62 if_indextoname() The if_indextoname() function maps an interface
63 index into its corresponding name. This pointer
64 is also the return value of the function. If
65 there is no interface corresponding to the speci‐
66 fied index, NULL is returned, and errno is set to
67 ENXIO, if there was a system error, such as run‐
68 ning out of memory, if_indextoname() returns NULL
69 and errno would be set to the proper value, for
70 example, ENOMEM.
71
72
73 *if_nameindex() The if_nameindex() function returns an array of
74 if_nameindex structures, one structure per inter‐
75 face. The if_nameindex structure holds the infor‐
76 mation about a single interface and is defined
77 when the <net/if.h> header is included:
78
79 struct if_nameindex {
80 unsigned int if_index; /* 1, 2, ... */
81 char *if_name; /* null terminated name: "eri0", ... */
82 };
83
84 The end of the array of structures is indicated
85 by a structure with an if_index of 0 and an
86 if_name of NULL. The function returns a null
87 pointer upon an error and sets errno to the
88 appropriate value. The memory used for this array
89 of structures along with the interface names
90 pointed to by the if_name members is obtained
91 dynamically. This memory is freed by the
92 if_freenameindex() function.
93
94
95 if_freenameindex() The if_freenameindex() function frees the dynamic
96 memory that was allocated by if_nameindex(). The
97 argument to this function must be a pointer that
98 was returned by if_nameindex().
99
100
102 See attributes(5) for descriptions of the following attributes:
103
104
105
106
107 ┌─────────────────────────────┬─────────────────────────────┐
108 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
109 ├─────────────────────────────┼─────────────────────────────┤
110 │Availability │SUNWcsl (32-bit) │
111 ├─────────────────────────────┼─────────────────────────────┤
112 │ │SUNWcslx (64-bit) │
113 ├─────────────────────────────┼─────────────────────────────┤
114 │Interface Stability │Standard │
115 ├─────────────────────────────┼─────────────────────────────┤
116 │MT-Level │MT-Safe │
117 └─────────────────────────────┴─────────────────────────────┘
118
120 ifconfig(1M), if_nametoindex(3SOCKET), attributes(5), standards(5),
121 if(7P)
122
123
124
125SunOS 5.11 14 Dec 2003 if_nametoindex(3XNET)