]> git.saurik.com Git - apple/libinfo.git/blame - gen.subproj/if_indextoname.3
Libinfo-542.40.3.tar.gz
[apple/libinfo.git] / gen.subproj / if_indextoname.3
CommitLineData
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 49The
3b7c7bd7 50.Fn if_nametoindex
d49d4c81
A
51function maps the interface name specified in
52.Fa ifname
53to its corresponding index.
54If the specified interface does not exist, it returns 0.
3b7c7bd7 55.Pp
3b7c7bd7 56The
d49d4c81
A
57.Fn if_indextoname
58function maps the interface index specified in
59.Fa ifindex
60to it corresponding name, which is copied into the
61buffer pointed to by
62.Fa ifname ,
63which must be of at least
64.Dv IFNAMSIZ
65bytes.
3b7c7bd7 66This pointer is also the return value of the function.
d49d4c81
A
67If there is no interface corresponding to the specified
68index,
3b7c7bd7
A
69.Dv NULL
70is returned.
71.Pp
d49d4c81 72The
3b7c7bd7 73.Fn if_nameindex
d49d4c81
A
74function returns an array of
75.Vt if_nameindex
76structures, one structure per interface, as
77defined in the include file
78.In net/if.h .
79The
80.Vt if_nameindex
81structure 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
87The end of the array of structures is indicated by a structure with an
88.Va if_index
3b7c7bd7 89of 0 and an
d49d4c81 90.Va if_name
3b7c7bd7
A
91of
92.Dv NULL .
d49d4c81 93A
3b7c7bd7 94.Dv NULL
d49d4c81 95pointer is returned upon an error.
3b7c7bd7 96.Pp
d49d4c81 97The
3b7c7bd7 98.Fn if_freenameindex
d49d4c81
A
99function frees the dynamic memory that was
100allocated by
101.Fn if_nameindex .
102.Sh RETURN VALUES
103Upon successful completion,
3b7c7bd7 104.Fn if_nametoindex
d49d4c81
A
105returns the index number of the interface.
106If the interface is not found, a value of 0 is returned and
107.Va errno
108is set to
109.Er ENXIO .
110A value of 0 is also returned if an error
111occurs while retrieving the list of interfaces via
112.Xr getifaddrs 3 .
113.Pp
114Upon successful completion,
3b7c7bd7 115.Fn if_indextoname
d49d4c81
A
116returns
117.Fa ifname .
118If the interface is not found, a
119.Dv NULL
120pointer is returned and
121.Va errno
122is set to
123.Er ENXIO .
124A
125.Dv NULL
126pointer is also returned if an error
127occurs while retrieving the list of interfaces via
128.Xr getifaddrs 3 .
129.Pp
130The
3b7c7bd7 131.Fn if_nameindex
d49d4c81 132returns a
3b7c7bd7 133.Dv NULL
d49d4c81
A
134pointer if an error
135occurs while retrieving the list of interfaces via
136.Xr getifaddrs 3 ,
137or 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
142The
143.Fn if_nametoindex ,
144.Fn if_indextoname ,
145.Fn if_nameindex ,
146and
147.Fn if_freenameindex
148functions conform to
149.%T "RFC 2553" .
150.Sh HISTORY
151The implementation first appeared in BSDi
152.Bsx .