1 |
27 |
unneback |
.\" $OpenBSD: getifaddrs.3,v 1.7 2001/10/01 21:58:53 millert 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
|
31 |
|
|
.Fd #include
|
32 |
|
|
.Fd #include
|
33 |
|
|
.Ft int
|
34 |
|
|
.Fn getifaddrs "struct ifaddrs **ifap"
|
35 |
|
|
.Ft void
|
36 |
|
|
.Fn freeifaddrs "struct ifaddrs *ifap"
|
37 |
|
|
.Sh DESCRIPTION
|
38 |
|
|
The
|
39 |
|
|
.Fn getifaddrs
|
40 |
|
|
function stores a reference to a linked list of the network interfaces
|
41 |
|
|
on the local machine in the memory referenced by
|
42 |
|
|
.Fa ifap .
|
43 |
|
|
The list consists of
|
44 |
|
|
.Nm ifaddrs
|
45 |
|
|
structures, as defined in the include file
|
46 |
|
|
.Aq Pa ifaddrs.h .
|
47 |
|
|
The
|
48 |
|
|
.Nm ifaddrs
|
49 |
|
|
structure 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
|
61 |
|
|
.Bl -tag -width Ds
|
62 |
|
|
.It Fa ifa_next
|
63 |
|
|
Contains a pointer to the next structure on the list.
|
64 |
|
|
This field is set to
|
65 |
|
|
.Dv NULL
|
66 |
|
|
in last structure on the list.
|
67 |
|
|
.It Fa ifa_name
|
68 |
|
|
Contains the interface name.
|
69 |
|
|
.It Fa ifa_flags
|
70 |
|
|
Contains the interface flags, as set by
|
71 |
|
|
.Xr ifconfig 8 .
|
72 |
|
|
.It Fa ifa_addr
|
73 |
|
|
References either the address of the interface or the link level
|
74 |
|
|
address of the interface, if one exists, otherwise it is
|
75 |
|
|
.Dv NULL .
|
76 |
|
|
(The
|
77 |
|
|
.Fa sa_family
|
78 |
|
|
field of the
|
79 |
|
|
.Fa ifa_addr
|
80 |
|
|
field should be consulted to determine the format of the
|
81 |
|
|
.Fa ifa_addr
|
82 |
|
|
address.)
|
83 |
|
|
.It Fa ifa_netmask
|
84 |
|
|
References the netmask associated with
|
85 |
|
|
.Fa ifa_addr ,
|
86 |
|
|
if one is set, otherwise it is
|
87 |
|
|
.Dv NULL .
|
88 |
|
|
.It Fa ifa_broadaddr
|
89 |
|
|
This field, which should only be referenced for non-P2P interfaces,
|
90 |
|
|
references the broadcast address associated with
|
91 |
|
|
.Fa ifa_addr ,
|
92 |
|
|
if one exists, otherwise it is
|
93 |
|
|
.Dv NULL .
|
94 |
|
|
.It Fa ifa_dstaddr
|
95 |
|
|
References the destination address on a P2P interface,
|
96 |
|
|
if one exists, otherwise it is
|
97 |
|
|
.Dv NULL .
|
98 |
|
|
.It Fa ifa_data
|
99 |
|
|
References address family specific data.
|
100 |
|
|
For
|
101 |
|
|
.Dv AF_LINK
|
102 |
|
|
addresses it contains a pointer to the
|
103 |
|
|
.Li struct if_data
|
104 |
|
|
(as defined in include file
|
105 |
|
|
.Aq Pa net/if.h )
|
106 |
|
|
which contains various interface attributes and statistics.
|
107 |
|
|
For all other address families, it contains a pointer to the
|
108 |
|
|
.Li struct ifa_data
|
109 |
|
|
(as defined in include file
|
110 |
|
|
.Aq Pa net/if.h )
|
111 |
|
|
which contains per-address interface statistics.
|
112 |
|
|
.El
|
113 |
|
|
.Pp
|
114 |
|
|
The data returned by
|
115 |
|
|
.Fn getifaddrs
|
116 |
|
|
is dynamically allocated and should be freed using
|
117 |
|
|
.Fn freeifaddrs
|
118 |
|
|
when no longer needed.
|
119 |
|
|
.Sh RETURN VALUES
|
120 |
|
|
Upon successful completion, a value of 0 is returned.
|
121 |
|
|
Otherwise, a value of \-1 is returned and
|
122 |
|
|
.Va errno
|
123 |
|
|
is set to indicate the error.
|
124 |
|
|
.Sh ERRORS
|
125 |
|
|
The
|
126 |
|
|
.Fn getifaddrs
|
127 |
|
|
may fail and set
|
128 |
|
|
.Va errno
|
129 |
|
|
for any of the errors specified for the library routines
|
130 |
|
|
.Xr ioctl 2 ,
|
131 |
|
|
.Xr socket 2 ,
|
132 |
|
|
.Xr malloc 3 ,
|
133 |
|
|
or
|
134 |
|
|
.Xr sysctl 3 .
|
135 |
|
|
.Sh BUGS
|
136 |
|
|
If both
|
137 |
|
|
.Aq Pa net/if.h
|
138 |
|
|
and
|
139 |
|
|
.Aq Pa ifaddrs.h
|
140 |
|
|
are being included,
|
141 |
|
|
.Aq Pa net/if.h
|
142 |
|
|
.Em must
|
143 |
|
|
be included before
|
144 |
|
|
.Aq Pa ifaddrs.h .
|
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
|
152 |
|
|
The
|
153 |
|
|
.Fn getifaddrs
|
154 |
|
|
function first appeared in BSDI BSD/OS.
|
155 |
|
|
The function is supplied on
|
156 |
|
|
.Ox
|
157 |
|
|
since
|
158 |
|
|
.Ox 2.7 .
|