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