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