]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/net/getifaddrs.3
Merge llvm-project main llvmorg-17-init-19304-gd0b54bb50e51
[FreeBSD/FreeBSD.git] / lib / libc / net / getifaddrs.3
1 .\"     $KAME: getifaddrs.3,v 1.4 2000/05/17 14:13:14 itojun Exp $
2 .\"     BSDI    getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp
3 .\"
4 .\" Copyright (c) 1995, 1999
5 .\"     Berkeley Software Design, Inc.  All rights reserved.
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.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
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 .\"
25 .Dd November 25, 2014
26 .Dt GETIFADDRS 3
27 .Os
28 .Sh NAME
29 .Nm getifaddrs
30 .Nd get interface addresses
31 .Sh SYNOPSIS
32 .In ifaddrs.h
33 .Ft int
34 .Fn getifaddrs "struct ifaddrs **ifap"
35 .Ft void
36 .Fn freeifaddrs "struct ifaddrs *ifp"
37 .Sh DESCRIPTION
38 The
39 .Fn getifaddrs
40 function stores a reference to a linked list of the network interfaces
41 on the local machine in the memory referenced by
42 .Fa ifap .
43 The list consists of
44 .Nm ifaddrs
45 structures, as defined in the include file
46 .In ifaddrs.h .
47 The
48 .Nm ifaddrs
49 structure contains at least the following entries:
50 .Bd -literal
51     struct ifaddrs   *ifa_next;         /* Pointer to next struct */
52     char             *ifa_name;         /* Interface name */
53     u_int             ifa_flags;        /* Interface flags */
54     struct sockaddr  *ifa_addr;         /* Interface address */
55     struct sockaddr  *ifa_netmask;      /* Interface netmask */
56     struct sockaddr  *ifa_broadaddr;    /* Interface broadcast address */
57     struct sockaddr  *ifa_dstaddr;      /* P2P interface destination */
58     void             *ifa_data;         /* Address specific data */
59 .Ed
60 .Pp
61 The
62 .Li ifa_next
63 field contains a pointer to the next structure on the list.
64 This field is
65 .Dv NULL
66 in last structure on the list.
67 .Pp
68 The
69 .Li ifa_name
70 field contains the interface name.
71 .Pp
72 The
73 .Li ifa_flags
74 field contains the interface flags, as set by
75 .Xr ifconfig 8
76 utility.
77 .Pp
78 The
79 .Li ifa_addr
80 field references either the address of the interface or the link level
81 address of the interface, if one exists, otherwise it is NULL.
82 (The
83 .Li sa_family
84 field of the
85 .Li ifa_addr
86 field should be consulted to determine the format of the
87 .Li ifa_addr
88 address.)
89 .Pp
90 The
91 .Li ifa_netmask
92 field references the netmask associated with
93 .Li ifa_addr ,
94 if one is set, otherwise it is NULL.
95 .Pp
96 The
97 .Li ifa_broadaddr
98 field,
99 which should only be referenced for non-P2P interfaces,
100 references the broadcast address associated with
101 .Li ifa_addr ,
102 if one exists, otherwise it is NULL.
103 .Pp
104 The
105 .Li ifa_dstaddr
106 field references the destination address on a P2P interface,
107 if one exists, otherwise it is NULL.
108 .Pp
109 The
110 .Li ifa_data
111 field references address family specific data
112 in a pointer to the
113 .Fa struct if_data
114 (as defined in include file
115 .In net/if.h ) .
116 For
117 .Dv AF_LINK
118 addresses,
119 it contains various interface attributes and statistics.
120 For all other address families,
121 it contains per-address interface statistics.
122 .Pp
123 The data returned by
124 .Fn getifaddrs
125 is dynamically allocated and should be freed using
126 .Fn freeifaddrs
127 when no longer needed.
128 .Sh RETURN VALUES
129 .Rv -std getifaddrs
130 .Sh ERRORS
131 The
132 .Fn getifaddrs
133 may fail and set
134 .Va errno
135 for any of the errors specified for the library routines
136 .Xr ioctl 2 ,
137 .Xr socket 2 ,
138 .Xr malloc 3
139 or
140 .Xr sysctl 3 .
141 .Sh SEE ALSO
142 .Xr ioctl 2 ,
143 .Xr socket 2 ,
144 .Xr sysctl 3 ,
145 .Xr networking 4 ,
146 .Xr ifconfig 8
147 .Sh HISTORY
148 The
149 .Nm
150 implementation first appeared in BSDi
151 .Bsx .
152 .Sh BUGS
153 If both
154 .In net/if.h
155 and
156 .In ifaddrs.h
157 are being included,
158 .In net/if.h
159 .Em must
160 be included before
161 .In ifaddrs.h .