xref: /openbsd/share/man/man9/if_get.9 (revision 5dea098c)
1.\" $OpenBSD: if_get.9,v 1.3 2021/01/18 09:55:43 mvs Exp $
2.\"
3.\" Copyright (c) 2015 Martin Pieuchot
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: January 18 2021 $
18.Dt IF_GET 9
19.Os
20.Sh NAME
21.Nm if_get ,
22.Nm if_unit ,
23.Nm if_put
24.Nd get an interface pointer from an interface index
25.Sh SYNOPSIS
26.In net/if.h
27.Ft struct ifnet *
28.Fn if_get "unsigned int ifidx"
29.Ft struct ifnet *
30.Fn if_unit "const char *name"
31.Ft void
32.Fn if_put "struct ifnet *ifp"
33.Sh DESCRIPTION
34The
35.Fn if_get
36function returns a pointer to the interface descriptor corresponding to the
37unique index
38.Fa ifidx .
39This descriptor is guaranteed to be valid until
40.Fn if_put
41is called on the returned pointer.
42.Pp
43The index value
44.Dv 0
45is never associated with an interface descriptor and can be used to determine if
46an interface index is valid or not.
47.Pp
48The
49.Fn if_unit
50function returns a pointer to the interface descriptor corresponding to the
51unique name
52.Fa name .
53This descriptor is guaranteed to be valid until
54.Fn if_put
55is called on the returned pointer.
56.Pp
57The
58.Fn if_put
59function releases a reference on the interface descriptor pointed by
60.Fa ifp .
61If
62.Fa ifp
63is a
64.Dv NULL
65pointer, no action occurs.
66.Sh CONTEXT
67.Fn if_get ,
68.Fn if_unit
69and
70.Fn if_put
71can be called during autoconf, from process context, or from interrupt context.
72.Sh RETURN VALUES
73.Fn if_get
74returns a pointer to an interface descriptor if the index is valid, otherwise
75.Dv NULL .
76.Pp
77.Fn if_unit
78returns a pointer to an interface descriptor if the interface with present
79name exists, otherwise
80.Dv NULL .
81