]>
Commit | Line | Data |
---|---|---|
d49d4c81 A |
1 | .\" $KAME: if_indextoname.3,v 1.10 2000/11/24 08:13:51 itojun Exp $ |
2 | .\" BSDI Id: if_indextoname.3,v 2.2 2000/04/17 22:38:05 dab Exp | |
3 | .\" | |
4 | .\" Copyright (c) 1997, 2000 | |
5 | .\" Berkeley Software Design, Inc. All rights reserved. | |
3b7c7bd7 A |
6 | .\" |
7 | .\" Redistribution and use in source and binary forms, with or without | |
8 | .\" modification, are permitted provided that the following conditions | |
9 | .\" are met: | |
10 | .\" 1. Redistributions of source code must retain the above copyright | |
11 | .\" notice, this list of conditions and the following disclaimer. | |
3b7c7bd7 | 12 | .\" |
d49d4c81 | 13 | .\" THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND |
3b7c7bd7 A |
14 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
d49d4c81 | 16 | .\" ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE |
3b7c7bd7 A |
17 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
18 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
19 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
20 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
21 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
22 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
23 | .\" SUCH DAMAGE. | |
24 | .\" | |
d49d4c81 | 25 | .\" $FreeBSD: src/lib/libc/net/if_indextoname.3,v 1.11 2005/11/23 10:49:07 ru Exp $ |
3b7c7bd7 | 26 | .\" |
d49d4c81 | 27 | .Dd November 23, 2005 |
3b7c7bd7 A |
28 | .Dt IF_NAMETOINDEX 3 |
29 | .Os | |
30 | .Sh NAME | |
d49d4c81 | 31 | .Nm if_nametoindex , |
3b7c7bd7 A |
32 | .Nm if_indextoname , |
33 | .Nm if_nameindex , | |
d49d4c81 A |
34 | .Nm if_freenameindex |
35 | .Nd provide mappings between interface names and indexes | |
3b7c7bd7 | 36 | .Sh SYNOPSIS |
d49d4c81 A |
37 | .In sys/types.h |
38 | .In sys/socket.h | |
39 | .In net/if.h | |
40 | .Ft "unsigned int" | |
41 | .Fn if_nametoindex "const char *ifname" | |
3b7c7bd7 | 42 | .Ft "char *" |
d49d4c81 | 43 | .Fn if_indextoname "unsigned int ifindex" "char *ifname" |
3b7c7bd7 | 44 | .Ft "struct if_nameindex *" |
d49d4c81 A |
45 | .Fn if_nameindex "void" |
46 | .Ft void | |
47 | .Fn if_freenameindex "struct if_nameindex *ptr" | |
3b7c7bd7 | 48 | .Sh DESCRIPTION |
d49d4c81 | 49 | The |
3b7c7bd7 | 50 | .Fn if_nametoindex |
d49d4c81 A |
51 | function maps the interface name specified in |
52 | .Fa ifname | |
53 | to its corresponding index. | |
54 | If the specified interface does not exist, it returns 0. | |
3b7c7bd7 | 55 | .Pp |
3b7c7bd7 | 56 | The |
d49d4c81 A |
57 | .Fn if_indextoname |
58 | function maps the interface index specified in | |
59 | .Fa ifindex | |
60 | to it corresponding name, which is copied into the | |
61 | buffer pointed to by | |
62 | .Fa ifname , | |
63 | which must be of at least | |
64 | .Dv IFNAMSIZ | |
65 | bytes. | |
3b7c7bd7 | 66 | This pointer is also the return value of the function. |
d49d4c81 A |
67 | If there is no interface corresponding to the specified |
68 | index, | |
3b7c7bd7 A |
69 | .Dv NULL |
70 | is returned. | |
71 | .Pp | |
d49d4c81 | 72 | The |
3b7c7bd7 | 73 | .Fn if_nameindex |
d49d4c81 A |
74 | function returns an array of |
75 | .Vt if_nameindex | |
76 | structures, one structure per interface, as | |
77 | defined in the include file | |
78 | .In net/if.h . | |
79 | The | |
80 | .Vt if_nameindex | |
81 | structure contains at least the following entries: | |
82 | .Bd -literal | |
3b7c7bd7 A |
83 | unsigned int if_index; /* 1, 2, ... */ |
84 | char *if_name; /* null terminated name: "le0", ... */ | |
3b7c7bd7 A |
85 | .Ed |
86 | .Pp | |
d49d4c81 A |
87 | The end of the array of structures is indicated by a structure with an |
88 | .Va if_index | |
3b7c7bd7 | 89 | of 0 and an |
d49d4c81 | 90 | .Va if_name |
3b7c7bd7 A |
91 | of |
92 | .Dv NULL . | |
d49d4c81 | 93 | A |
3b7c7bd7 | 94 | .Dv NULL |
d49d4c81 | 95 | pointer is returned upon an error. |
3b7c7bd7 | 96 | .Pp |
d49d4c81 | 97 | The |
3b7c7bd7 | 98 | .Fn if_freenameindex |
d49d4c81 A |
99 | function frees the dynamic memory that was |
100 | allocated by | |
101 | .Fn if_nameindex . | |
102 | .Sh RETURN VALUES | |
103 | Upon successful completion, | |
3b7c7bd7 | 104 | .Fn if_nametoindex |
d49d4c81 A |
105 | returns the index number of the interface. |
106 | If the interface is not found, a value of 0 is returned and | |
107 | .Va errno | |
108 | is set to | |
109 | .Er ENXIO . | |
110 | A value of 0 is also returned if an error | |
111 | occurs while retrieving the list of interfaces via | |
112 | .Xr getifaddrs 3 . | |
113 | .Pp | |
114 | Upon successful completion, | |
3b7c7bd7 | 115 | .Fn if_indextoname |
d49d4c81 A |
116 | returns |
117 | .Fa ifname . | |
118 | If the interface is not found, a | |
119 | .Dv NULL | |
120 | pointer is returned and | |
121 | .Va errno | |
122 | is set to | |
123 | .Er ENXIO . | |
124 | A | |
125 | .Dv NULL | |
126 | pointer is also returned if an error | |
127 | occurs while retrieving the list of interfaces via | |
128 | .Xr getifaddrs 3 . | |
129 | .Pp | |
130 | The | |
3b7c7bd7 | 131 | .Fn if_nameindex |
d49d4c81 | 132 | returns a |
3b7c7bd7 | 133 | .Dv NULL |
d49d4c81 A |
134 | pointer if an error |
135 | occurs while retrieving the list of interfaces via | |
136 | .Xr getifaddrs 3 , | |
137 | or if sufficient memory cannot be allocated. | |
3b7c7bd7 | 138 | .Sh SEE ALSO |
d49d4c81 A |
139 | .Xr getifaddrs 3 , |
140 | .Xr networking 4 | |
3b7c7bd7 | 141 | .Sh STANDARDS |
d49d4c81 A |
142 | The |
143 | .Fn if_nametoindex , | |
144 | .Fn if_indextoname , | |
145 | .Fn if_nameindex , | |
146 | and | |
147 | .Fn if_freenameindex | |
148 | functions conform to | |
149 | .%T "RFC 2553" . | |
150 | .Sh HISTORY | |
151 | The implementation first appeared in BSDi | |
152 | .Bsx . |