xref: /freebsd/lib/libc/net/getifaddrs.3 (revision b601c69bdbe8755d26570261d7fd4c02ee4eff74)
1.\"	$FreeBSD$
2.\"	$KAME: getifaddrs.3,v 1.4 2000/05/17 14:13:14 itojun Exp $
3.\"	BSDI	getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp
4.\"
5.\" Copyright (c) 1995, 1999
6.\"	Berkeley Software Design, Inc.  All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.Dd "October 12, 1995"
26.Dt GETIFADDRS 3
27.Sh NAME
28.Nm getifaddrs
29.Nd get interface addresses
30.Sh SYNOPSIS
31.Fd #include <sys/types.h>
32.Fd #include <sys/socket.h>
33.Fd #include <ifaddrs.h>
34.Ft int
35.Fn getifaddrs "struct ifaddrs **ifap"
36.Ft void
37.Fn freeifaddrs "struct ifaddrs *ifp"
38.Sh DESCRIPTION
39The
40.Fn getifaddrs
41function stores a reference to a linked list of the network interfaces
42on the local machine in the memory referenced by
43.Fa ifap .
44The list consists of
45.Nm ifaddrs
46structures, as defined in the include file
47.Aq Pa ifaddrs.h .
48The
49.Nm ifaddrs
50structure contains at least the following entries:
51.Bd -literal
52    struct ifaddrs   *ifa_next;         /* Pointer to next struct */
53    char             *ifa_name;         /* Interface name */
54    u_int             ifa_flags;        /* Interface flags */
55    struct sockaddr  *ifa_addr;         /* Interface address */
56    struct sockaddr  *ifa_netmask;      /* Interface netmask */
57    struct sockaddr  *ifa_broadaddr;    /* Interface broadcast address */
58    struct sockaddr  *ifa_dstaddr;      /* P2P interface destination */
59    void             *ifa_data;		/* Address specific data */
60.Ed
61.Pp
62The
63.Li ifa_next
64field contains a pointer to the next structure on the list.
65This field is
66.Dv NULL
67in last structure on the list.
68.Pp
69The
70.Li ifa_name
71field contains the interface name.
72.Pp
73The
74.Li ifa_flags
75field contains the interface flags, as set by
76.Xr ifconfig 8
77utility.
78.Pp
79The
80.Li ifa_addr
81field references either the address of the interface or the link level
82address of the interface, if one exists, otherwise it is NULL.
83(The
84.Li sa_family
85field of the
86.Li ifa_addr
87field should be consulted to determine the format of the
88.Li ifa_addr
89address.)
90.Pp
91The
92.Li ifa_netmask
93field references the netmask associated with
94.Li ifa_addr ,
95if one is set, otherwise it is NULL.
96.Pp
97The
98.Li ifa_broadaddr
99field,
100which should only be referenced for non-P2P interfaces,
101references the broadcast address associated with
102.Li ifa_addr ,
103if one exists, otherwise it is NULL.
104.Pp
105The
106.Li ifa_dstaddr
107field references the destination address on a P2P interface,
108if one exists, otherwise it is NULL.
109.Pp
110The
111.Li ifa_data
112field references address family specific data.  For
113.Dv AF_LINK
114addresses it contains a pointer to the
115.Fa struct if_data
116.Pq as defined in include file Aq Pa net/if.h
117which contains various interface attributes and statistics.
118For all other address families, it contains a pointer to the
119.Fa struct ifa_data
120.Pq as defined in include file Aq Pa net/if.h
121which contains per-address interface statistics.
122.Pp
123The data returned by
124.Fn getifaddrs
125is dynamically allocated and should be freed using
126.Fn freeifaddrs
127when no longer needed.
128.Sh RETURN VALUES
129Upon successful completion, a value of 0 is returned.
130Otherwise, a value of -1 is returned and
131.Va errno
132is set to indicate the error.
133.Sh ERRORS
134The
135.Fn getifaddrs
136may fail and set
137.Va errno
138for any of the errors specified for the library routines
139.Xr ioctl 2 ,
140.Xr socket 2 ,
141.Xr malloc 3
142or
143.Xr sysctl 3 .
144.Sh BUGS
145If both
146.Aq Pa net/if.h
147and
148.Aq Pa ifaddrs.h
149are being included,
150.Aq Pa net/if.h
151.Em must
152be included before
153.Aq Pa ifaddrs.h .
154.Sh SEE ALSO
155.Xr ioctl 2 ,
156.Xr socket 2 ,
157.Xr sysctl 3 ,
158.Xr networking 4 ,
159.Xr ifconfig 8
160.Sh HISTORY
161The
162.Nm
163implementation first appeared in BSDI BSD/OS.
164