Merge branch 'vendor/NCURSES'
[dragonfly.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 .\" $FreeBSD: src/lib/libc/net/getifaddrs.3,v 1.10 2005/02/09 18:03:13 ru Exp $
26 .\" $DragonFly: src/lib/libc/net/getifaddrs.3,v 1.5 2007/08/18 20:48:47 swildner Exp $
27 .\"
28 .Dd October 12, 1995
29 .Dt GETIFADDRS 3
30 .Os
31 .Sh NAME
32 .Nm getifaddrs
33 .Nd get interface addresses
34 .Sh LIBRARY
35 .Lb libc
36 .Sh SYNOPSIS
37 .In sys/types.h
38 .In sys/socket.h
39 .In ifaddrs.h
40 .Ft int
41 .Fn getifaddrs "struct ifaddrs **ifap"
42 .Ft void
43 .Fn freeifaddrs "struct ifaddrs *ifp"
44 .Sh DESCRIPTION
45 The
46 .Fn getifaddrs
47 function stores a reference to a linked list of the network interfaces
48 on the local machine in the memory referenced by
49 .Fa ifap .
50 The list consists of
51 .Nm ifaddrs
52 structures, as defined in the include file
53 .In ifaddrs.h .
54 The
55 .Nm ifaddrs
56 structure contains at least the following entries:
57 .Bd -literal
58     struct ifaddrs   *ifa_next;         /* Pointer to next struct */
59     char             *ifa_name;         /* Interface name */
60     u_int             ifa_flags;        /* Interface flags */
61     struct sockaddr  *ifa_addr;         /* Interface address */
62     struct sockaddr  *ifa_netmask;      /* Interface netmask */
63     struct sockaddr  *ifa_broadaddr;    /* Interface broadcast address */
64     struct sockaddr  *ifa_dstaddr;      /* P2P interface destination */
65     void             *ifa_data;         /* Address specific data */
66 .Ed
67 .Pp
68 The
69 .Li ifa_next
70 field contains a pointer to the next structure on the list.
71 This field is
72 .Dv NULL
73 in last structure on the list.
74 .Pp
75 The
76 .Li ifa_name
77 field contains the interface name.
78 .Pp
79 The
80 .Li ifa_flags
81 field contains the interface flags, as set by
82 .Xr ifconfig 8
83 utility.
84 .Pp
85 The
86 .Li ifa_addr
87 field references either the address of the interface or the link level
88 address of the interface, if one exists, otherwise it is NULL.
89 (The
90 .Li sa_family
91 field of the
92 .Li ifa_addr
93 field should be consulted to determine the format of the
94 .Li ifa_addr
95 address.)
96 .Pp
97 The
98 .Li ifa_netmask
99 field references the netmask associated with
100 .Li ifa_addr ,
101 if one is set, otherwise it is NULL.
102 .Pp
103 The
104 .Li ifa_broadaddr
105 field,
106 which should only be referenced for non-P2P interfaces,
107 references the broadcast address associated with
108 .Li ifa_addr ,
109 if one exists, otherwise it is NULL.
110 .Pp
111 The
112 .Li ifa_dstaddr
113 field references the destination address on a P2P interface,
114 if one exists, otherwise it is NULL.
115 .Pp
116 The
117 .Li ifa_data
118 field references address family specific data.
119 For
120 .Dv AF_LINK
121 addresses it contains a pointer to the
122 .Fa struct if_data
123 (as defined in include file
124 .In net/if.h )
125 which contains various interface attributes and statistics.
126 For all other address families, it contains a pointer to the
127 .Fa struct ifa_data
128 (as defined in include file
129 .In net/if.h )
130 which contains per-address interface statistics.
131 .Pp
132 The data returned by
133 .Fn getifaddrs
134 is dynamically allocated and should be freed using
135 .Fn freeifaddrs
136 when no longer needed.
137 .Sh RETURN VALUES
138 .Rv -std getifaddrs
139 .Sh ERRORS
140 The
141 .Fn getifaddrs
142 may fail and set
143 .Va errno
144 for any of the errors specified for the library routines
145 .Xr ioctl 2 ,
146 .Xr socket 2 ,
147 .Xr malloc 3
148 or
149 .Xr sysctl 3 .
150 .Sh SEE ALSO
151 .Xr ioctl 2 ,
152 .Xr socket 2 ,
153 .Xr sysctl 3 ,
154 .Xr networking 4 ,
155 .Xr ifconfig 8
156 .Sh HISTORY
157 The
158 .Nm
159 implementation first appeared in BSDi
160 .Bsx .
161 .Sh BUGS
162 If both
163 .In net/if.h
164 and
165 .In ifaddrs.h
166 are being included,
167 .In net/if.h
168 .Em must
169 be included before
170 .In ifaddrs.h .