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