xref: /dflybsd-src/lib/libc/net/if_indextoname.3 (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino.\"	$KAME: if_indextoname.3,v 1.10 2000/11/24 08:13:51 itojun Exp $
286d7f5d3SJohn Marino.\"	BSDI	Id: if_indextoname.3,v 2.2 2000/04/17 22:38:05 dab Exp
386d7f5d3SJohn Marino.\"
486d7f5d3SJohn Marino.\" Copyright (c) 1997, 2000
586d7f5d3SJohn Marino.\"	Berkeley Software Design, Inc.  All rights reserved.
686d7f5d3SJohn Marino.\"
786d7f5d3SJohn Marino.\" Redistribution and use in source and binary forms, with or without
886d7f5d3SJohn Marino.\" modification, are permitted provided that the following conditions
986d7f5d3SJohn Marino.\" are met:
1086d7f5d3SJohn Marino.\" 1. Redistributions of source code must retain the above copyright
1186d7f5d3SJohn Marino.\"    notice, this list of conditions and the following disclaimer.
1286d7f5d3SJohn Marino.\"
1386d7f5d3SJohn Marino.\" THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
1486d7f5d3SJohn Marino.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1586d7f5d3SJohn Marino.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1686d7f5d3SJohn Marino.\" ARE DISCLAIMED.  IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
1786d7f5d3SJohn Marino.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1886d7f5d3SJohn Marino.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1986d7f5d3SJohn Marino.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2086d7f5d3SJohn Marino.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2186d7f5d3SJohn Marino.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2286d7f5d3SJohn Marino.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2386d7f5d3SJohn Marino.\" SUCH DAMAGE.
2486d7f5d3SJohn Marino.\"
2586d7f5d3SJohn Marino.\" $FreeBSD: src/lib/libc/net/if_indextoname.3,v 1.11 2005/11/23 10:49:07 ru Exp $
2686d7f5d3SJohn Marino.\"
2786d7f5d3SJohn Marino.Dd November 23, 2005
2886d7f5d3SJohn Marino.Dt IF_NAMETOINDEX 3
2986d7f5d3SJohn Marino.Os
3086d7f5d3SJohn Marino.Sh NAME
3186d7f5d3SJohn Marino.Nm if_nametoindex ,
3286d7f5d3SJohn Marino.Nm if_indextoname ,
3386d7f5d3SJohn Marino.Nm if_nameindex ,
3486d7f5d3SJohn Marino.Nm if_freenameindex
3586d7f5d3SJohn Marino.Nd provide mappings between interface names and indexes
3686d7f5d3SJohn Marino.Sh LIBRARY
3786d7f5d3SJohn Marino.Lb libc
3886d7f5d3SJohn Marino.Sh SYNOPSIS
3986d7f5d3SJohn Marino.In sys/types.h
4086d7f5d3SJohn Marino.In sys/socket.h
4186d7f5d3SJohn Marino.In net/if.h
4286d7f5d3SJohn Marino.Ft "unsigned int"
4386d7f5d3SJohn Marino.Fn if_nametoindex "const char *ifname"
4486d7f5d3SJohn Marino.Ft "char *"
4586d7f5d3SJohn Marino.Fn if_indextoname "unsigned int ifindex" "char *ifname"
4686d7f5d3SJohn Marino.Ft "struct if_nameindex *"
4786d7f5d3SJohn Marino.Fn if_nameindex "void"
4886d7f5d3SJohn Marino.Ft void
4986d7f5d3SJohn Marino.Fn if_freenameindex "struct if_nameindex *ptr"
5086d7f5d3SJohn Marino.Sh DESCRIPTION
5186d7f5d3SJohn MarinoThe
5286d7f5d3SJohn Marino.Fn if_nametoindex
5386d7f5d3SJohn Marinofunction maps the interface name specified in
5486d7f5d3SJohn Marino.Fa ifname
5586d7f5d3SJohn Marinoto its corresponding index.
5686d7f5d3SJohn MarinoIf the specified interface does not exist, it returns 0.
5786d7f5d3SJohn Marino.Pp
5886d7f5d3SJohn MarinoThe
5986d7f5d3SJohn Marino.Fn if_indextoname
6086d7f5d3SJohn Marinofunction maps the interface index specified in
6186d7f5d3SJohn Marino.Fa ifindex
6286d7f5d3SJohn Marinoto it corresponding name, which is copied into the
6386d7f5d3SJohn Marinobuffer pointed to by
6486d7f5d3SJohn Marino.Fa ifname ,
6586d7f5d3SJohn Marinowhich must be of at least
6686d7f5d3SJohn Marino.Dv IFNAMSIZ
6786d7f5d3SJohn Marinobytes.
6886d7f5d3SJohn MarinoThis pointer is also the return value of the function.
6986d7f5d3SJohn MarinoIf there is no interface corresponding to the specified
7086d7f5d3SJohn Marinoindex,
7186d7f5d3SJohn Marino.Dv NULL
7286d7f5d3SJohn Marinois returned.
7386d7f5d3SJohn Marino.Pp
7486d7f5d3SJohn MarinoThe
7586d7f5d3SJohn Marino.Fn if_nameindex
7686d7f5d3SJohn Marinofunction returns an array of
7786d7f5d3SJohn Marino.Vt if_nameindex
7886d7f5d3SJohn Marinostructures, one structure per interface, as
7986d7f5d3SJohn Marinodefined in the include file
8086d7f5d3SJohn Marino.In net/if.h .
8186d7f5d3SJohn MarinoThe
8286d7f5d3SJohn Marino.Vt if_nameindex
8386d7f5d3SJohn Marinostructure contains at least the following entries:
8486d7f5d3SJohn Marino.Bd -literal
8586d7f5d3SJohn Marino    unsigned int   if_index;  /* 1, 2, ... */
8686d7f5d3SJohn Marino    char          *if_name;   /* null terminated name: "lnc0", ... */
8786d7f5d3SJohn Marino.Ed
8886d7f5d3SJohn Marino.Pp
8986d7f5d3SJohn MarinoThe end of the array of structures is indicated by a structure with an
9086d7f5d3SJohn Marino.Va if_index
9186d7f5d3SJohn Marinoof 0 and an
9286d7f5d3SJohn Marino.Va if_name
9386d7f5d3SJohn Marinoof
9486d7f5d3SJohn Marino.Dv NULL .
9586d7f5d3SJohn MarinoA
9686d7f5d3SJohn Marino.Dv NULL
9786d7f5d3SJohn Marinopointer is returned upon an error.
9886d7f5d3SJohn Marino.Pp
9986d7f5d3SJohn MarinoThe
10086d7f5d3SJohn Marino.Fn if_freenameindex
10186d7f5d3SJohn Marinofunction frees the dynamic memory that was
10286d7f5d3SJohn Marinoallocated by
10386d7f5d3SJohn Marino.Fn if_nameindex .
10486d7f5d3SJohn Marino.Sh RETURN VALUES
10586d7f5d3SJohn MarinoUpon successful completion,
10686d7f5d3SJohn Marino.Fn if_nametoindex
10786d7f5d3SJohn Marinoreturns the index number of the interface.
10886d7f5d3SJohn MarinoIf the interface is not found, a value of 0 is returned and
10986d7f5d3SJohn Marino.Va errno
11086d7f5d3SJohn Marinois set to
11186d7f5d3SJohn Marino.Er ENXIO .
11286d7f5d3SJohn MarinoA value of 0 is also returned if an error
11386d7f5d3SJohn Marinooccurs while retrieving the list of interfaces via
11486d7f5d3SJohn Marino.Xr getifaddrs 3 .
11586d7f5d3SJohn Marino.Pp
11686d7f5d3SJohn MarinoUpon successful completion,
11786d7f5d3SJohn Marino.Fn if_indextoname
11886d7f5d3SJohn Marinoreturns
11986d7f5d3SJohn Marino.Fa ifname .
12086d7f5d3SJohn MarinoIf the interface is not found, a
12186d7f5d3SJohn Marino.Dv NULL
12286d7f5d3SJohn Marinopointer is returned and
12386d7f5d3SJohn Marino.Va errno
12486d7f5d3SJohn Marinois set to
12586d7f5d3SJohn Marino.Er ENXIO .
12686d7f5d3SJohn MarinoA
12786d7f5d3SJohn Marino.Dv NULL
12886d7f5d3SJohn Marinopointer is also returned if an error
12986d7f5d3SJohn Marinooccurs while retrieving the list of interfaces via
13086d7f5d3SJohn Marino.Xr getifaddrs 3 .
13186d7f5d3SJohn Marino.Pp
13286d7f5d3SJohn MarinoThe
13386d7f5d3SJohn Marino.Fn if_nameindex
13486d7f5d3SJohn Marinoreturns a
13586d7f5d3SJohn Marino.Dv NULL
13686d7f5d3SJohn Marinopointer if an error
13786d7f5d3SJohn Marinooccurs while retrieving the list of interfaces via
13886d7f5d3SJohn Marino.Xr getifaddrs 3 ,
13986d7f5d3SJohn Marinoor if sufficient memory cannot be allocated.
14086d7f5d3SJohn Marino.Sh SEE ALSO
14186d7f5d3SJohn Marino.Xr getifaddrs 3 ,
14286d7f5d3SJohn Marino.Xr networking 4
14386d7f5d3SJohn Marino.Sh STANDARDS
14486d7f5d3SJohn MarinoThe
14586d7f5d3SJohn Marino.Fn if_nametoindex ,
14686d7f5d3SJohn Marino.Fn if_indextoname ,
14786d7f5d3SJohn Marino.Fn if_nameindex ,
14886d7f5d3SJohn Marinoand
14986d7f5d3SJohn Marino.Fn if_freenameindex
15086d7f5d3SJohn Marinofunctions conform to
15186d7f5d3SJohn Marino.%T "RFC 2553" .
15286d7f5d3SJohn Marino.Sh HISTORY
15386d7f5d3SJohn MarinoThe implementation first appeared in BSDi
15486d7f5d3SJohn Marino.Bsx .
155