summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/if_indextoname.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/if_indextoname.3')
-rw-r--r--src/lib/libc/net/if_indextoname.3136
1 files changed, 136 insertions, 0 deletions
diff --git a/src/lib/libc/net/if_indextoname.3 b/src/lib/libc/net/if_indextoname.3
new file mode 100644
index 0000000000..30293dcdf2
--- /dev/null
+++ b/src/lib/libc/net/if_indextoname.3
@@ -0,0 +1,136 @@
1.\" $OpenBSD: if_indextoname.3,v 1.7 2003/08/08 09:26:02 jmc Exp $
2.\" Copyright (c) 1983, 1991, 1993
3.\" The Regents of the University of California. All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\" notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\" notice, this list of conditions and the following disclaimer in the
12.\" documentation and/or other materials provided with the distribution.
13.\" 3. Neither the name of the University nor the names of its contributors
14.\" may be used to endorse or promote products derived from this software
15.\" without specific prior written permission.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27.\" SUCH DAMAGE.
28.\"
29.\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93
30.\"
31.Dd May 21, 1998
32.Dt IF_NAMETOINDEX 3
33.Os
34.Sh NAME
35.Nm if_nametoindex ,
36.Nm if_indextoname ,
37.Nm if_nameindex ,
38.Nm if_freenameindex
39.Nd convert interface index to name, and vice versa
40.Sh SYNOPSIS
41.Fd #include <net/if.h>
42.Ft "unsigned int"
43.Fn if_nametoindex "const char *ifname"
44.Ft "char *"
45.Fn if_indextoname "unsigned int ifindex" "char *ifname"
46.Ft "struct if_nameindex *"
47.Fn if_nameindex "void"
48.Ft "void"
49.Fn if_freenameindex "struct if_nameindex *ptr"
50.Sh DESCRIPTION
51These functions map interface indexes to interface names (such as
52.Dq lo0 ) ,
53and vice versa.
54.Pp
55The
56.Fn if_nametoindex
57function converts an interface name specified by the
58.Fa ifname
59argument to an interface index (positive integer value).
60If the specified interface does not exist, 0 will be returned.
61.Pp
62.Fn if_indextoname
63converts an interface index specified by the
64.Fa ifindex
65argument to an interface name.
66The
67.Fa ifname
68argument must point to a buffer of at least
69.Dv IF_NAMESIZE
70bytes into which the interface name corresponding to the specified index is
71returned.
72.Pf ( Dv IF_NAMESIZE
73is also defined in
74.Aq Pa net/if.h
75and its value includes a terminating null byte at the end of the
76interface name.)
77This pointer is also the return value of the function.
78If there is no interface corresponding to the specified index,
79.Dv NULL
80is returned.
81.Pp
82.Fn if_nameindex
83returns an array of
84.Fa if_nameindex
85structures.
86.Fa if_nametoindex
87is also defined in
88.Aq Pa net/if.h ,
89and is as follows:
90.Bd -literal -offset
91struct if_nameindex {
92 unsigned int if_index; /* 1, 2, ... */
93 char *if_name; /* null terminated name: "le0", ... */
94};
95.Ed
96.Pp
97The end of the array of structures is indicated by a structure with
98an
99.Fa if_index
100of 0 and an
101.Fa if_name
102of
103.Dv NULL .
104The function returns a null pointer on error.
105The memory used for this array of structures along with the interface
106names pointed to by the
107.Fa if_name
108members is obtained dynamically.
109This memory is freed by the
110.Fn if_freenameindex
111function.
112.Pp
113.Fn if_freenameindex
114takes a pointer that was returned by
115.Fn if_nameindex
116as argument
117.Pq Fa ptr ,
118and it reclaims the region allocated.
119.Sh DIAGNOSTICS
120.Fn if_nametoindex
121returns 0 on error, positive integer on success.
122.Fn if_indextoname
123and
124.Fn if_nameindex
125return
126.Dv NULL
127on errors.
128.Sh SEE ALSO
129.Xr getifaddrs 3 ,
130.Xr networking 4
131.Pp
132R. Gilligan, S. Thomson, J. Bound, and W. Stevens,
133``Basic Socket Interface Extensions for IPv6,'' RFC 2553, March 1999.
134.Sh STANDARDS
135These functions are defined in ``Basic Socket Interface Extensions for IPv6''
136.Pq RFC 2533 .