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