r26497: Fix return type for freeifaddrs().
[ira/wip.git] / source3 / lib / replace / system / network.h
1 #ifndef _system_network_h
2 #define _system_network_h
3 /* 
4    Unix SMB/CIFS implementation.
5
6    networking system include wrappers
7
8    Copyright (C) Andrew Tridgell 2004
9    Copyright (C) Jelmer Vernooij 2007
10    
11      ** NOTE! The following LGPL license applies to the replace
12      ** library. This does NOT imply that all of Samba is released
13      ** under the LGPL
14    
15    This library is free software; you can redistribute it and/or
16    modify it under the terms of the GNU Lesser General Public
17    License as published by the Free Software Foundation; either
18    version 3 of the License, or (at your option) any later version.
19
20    This library is distributed in the hope that it will be useful,
21    but WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23    Lesser General Public License for more details.
24
25    You should have received a copy of the GNU Lesser General Public
26    License along with this library; if not, see <http://www.gnu.org/licenses/>.
27
28 */
29
30 #ifdef HAVE_SYS_SOCKET_H
31 #include <sys/socket.h>
32 #endif
33
34 #ifdef HAVE_UNIXSOCKET
35 #include <sys/un.h>
36 #endif
37
38 #ifdef HAVE_NETINET_IN_H
39 #include <netinet/in.h>
40 #endif
41 #ifdef HAVE_ARPA_INET_H
42 #include <arpa/inet.h>
43 #endif
44
45 #ifdef HAVE_NETDB_H
46 #include <netdb.h>
47 #endif
48
49 #ifdef HAVE_NETINET_TCP_H
50 #include <netinet/tcp.h>
51 #endif
52
53 /*
54  * The next three defines are needed to access the IPTOS_* options
55  * on some systems.
56  */
57
58 #ifdef HAVE_NETINET_IN_SYSTM_H
59 #include <netinet/in_systm.h>
60 #endif
61
62 #ifdef HAVE_NETINET_IN_IP_H
63 #include <netinet/in_ip.h>
64 #endif
65
66 #ifdef HAVE_NETINET_IP_H
67 #include <netinet/ip.h>
68 #endif
69
70 #ifdef HAVE_NET_IF_H
71 #include <net/if.h>
72 #endif
73
74 #ifdef HAVE_UNISTD_H
75 #include <unistd.h>
76 #endif
77
78 #ifdef HAVE_SYS_IOCTL_H
79 #include <sys/ioctl.h>
80 #endif
81
82 #ifdef HAVE_STROPTS_H
83 #include <stropts.h>
84 #endif
85
86 #ifdef REPLACE_INET_NTOA
87 /* define is in "replace.h" */
88 char *rep_inet_ntoa(struct in_addr ip);
89 #endif
90
91 #ifndef HAVE_INET_PTON
92 /* define is in "replace.h" */
93 int rep_inet_pton(int af, const char *src, void *dst);
94 #endif
95
96 #ifndef HAVE_INET_NTOP
97 /* define is in "replace.h" */
98 const char *rep_inet_ntop(int af, const void *src, char *dst, socklen_t size);
99 #endif
100
101 #ifdef HAVE_IFADDRS_H
102 #include <ifaddrs.h>
103 #endif
104
105 #ifndef HAVE_STRUCT_IFADDRS
106 struct ifaddrs {
107         struct ifaddrs   *ifa_next;         /* Pointer to next struct */
108         char             *ifa_name;         /* Interface name */
109         unsigned int     ifa_flags;         /* Interface flags */
110         struct sockaddr  *ifa_addr;         /* Interface address */
111         struct sockaddr  *ifa_netmask;      /* Interface netmask */
112 #undef ifa_dstaddr
113         struct sockaddr  *ifa_dstaddr;      /* P2P interface destination */
114         void             *ifa_data;         /* Address specific data */
115 };
116 #endif
117
118 #ifndef HAVE_GETIFADDRS
119 int rep_getifaddrs(struct ifaddrs **);
120 #endif
121
122 #ifndef HAVE_FREEIFADDRS
123 void rep_freeifaddrs(struct ifaddrs **);
124 #endif
125
126 /*
127  * Some systems have getaddrinfo but not the
128  * defines needed to use it.
129  */
130
131 /* Various macros that ought to be in <netdb.h>, but might not be */
132
133 #ifndef EAI_FAIL
134 #define EAI_BADFLAGS    (-1)
135 #define EAI_NONAME      (-2)
136 #define EAI_AGAIN       (-3)
137 #define EAI_FAIL        (-4)
138 #define EAI_FAMILY      (-6)
139 #define EAI_SOCKTYPE    (-7)
140 #define EAI_SERVICE     (-8)
141 #define EAI_MEMORY      (-10)
142 #define EAI_SYSTEM      (-11)
143 #endif   /* !EAI_FAIL */
144
145 #ifndef AI_PASSIVE
146 #define AI_PASSIVE      0x0001
147 #endif
148
149 #ifndef AI_CANONNAME
150 #define AI_CANONNAME    0x0002
151 #endif
152
153 #ifndef AI_NUMERICHOST
154 /*
155  * some platforms don't support AI_NUMERICHOST; define as zero if using
156  * the system version of getaddrinfo...
157  */
158 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
159 #define AI_NUMERICHOST  0
160 #else
161 #define AI_NUMERICHOST  0x0004
162 #endif
163 #endif
164
165 #ifndef AI_ADDRCONFIG
166 /*
167  * logic copied from AI_NUMERICHOST
168  */
169 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
170 #define AI_ADDRCONFIG   0
171 #else
172 #define AI_ADDRCONFIG   0x0020
173 #endif
174 #endif
175
176 #ifndef AI_NUMERICSERV
177 /*
178  * logic copied from AI_NUMERICHOST
179  */
180 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
181 #define AI_NUMERICSERV  0
182 #else
183 #define AI_NUMERICSERV  0x0400
184 #endif
185 #endif
186
187 #ifndef NI_NUMERICHOST
188 #define NI_NUMERICHOST  1
189 #endif
190
191 #ifndef NI_NUMERICSERV
192 #define NI_NUMERICSERV  2
193 #endif
194
195 #ifndef NI_NOFQDN
196 #define NI_NOFQDN       4
197 #endif
198
199 #ifndef NI_NAMEREQD
200 #define NI_NAMEREQD     8
201 #endif
202
203 #ifndef NI_DGRAM
204 #define NI_DGRAM        16
205 #endif
206
207
208 #ifndef NI_MAXHOST
209 #define NI_MAXHOST      1025
210 #endif
211
212 #ifndef NI_MAXSERV
213 #define NI_MAXSERV      32
214 #endif
215
216 /*
217  * glibc on linux doesn't seem to have MSG_WAITALL
218  * defined. I think the kernel has it though..
219  */
220 #ifndef MSG_WAITALL
221 #define MSG_WAITALL 0
222 #endif
223
224 #ifndef INADDR_LOOPBACK
225 #define INADDR_LOOPBACK 0x7f000001
226 #endif
227
228 #ifndef INADDR_NONE
229 #define INADDR_NONE 0xffffffff
230 #endif
231
232 #ifndef EAFNOSUPPORT
233 #define EAFNOSUPPORT EINVAL
234 #endif
235
236 #ifndef INET_ADDRSTRLEN
237 #define INET_ADDRSTRLEN 16
238 #endif
239
240 #ifndef INET6_ADDRSTRLEN
241 #define INET6_ADDRSTRLEN 46
242 #endif
243
244 #ifndef HOST_NAME_MAX
245 #define HOST_NAME_MAX 256
246 #endif
247
248 #ifndef HAVE_SOCKLEN_T
249 #define HAVE_SOCKLEN_T
250 typedef int socklen_t;
251 #endif
252
253 #ifndef HAVE_SA_FAMILY_T
254 #define HAVE_SA_FAMILY_T
255 typedef unsigned short int sa_family_t;
256 #endif
257
258 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
259 #define HAVE_STRUCT_SOCKADDR_STORAGE
260 #ifdef HAVE_STRUCT_SOCKADDR_IN6
261 #define sockaddr_storage sockaddr_in6
262 #define ss_family sin6_family
263 #define HAVE_SS_FAMILY 1
264 #else
265 #define sockaddr_storage sockaddr_in
266 #define ss_family sin_family
267 #define HAVE_SS_FAMILY 1
268 #endif
269 #endif
270
271 #ifndef HAVE_SS_FAMILY
272 #ifdef HAVE___SS_FAMILY
273 #define ss_family __ss_family
274 #define HAVE_SS_FAMILY 1
275 #endif
276 #endif
277
278 #ifndef HAVE_STRUCT_ADDRINFO
279 #define HAVE_STRUCT_ADDRINFO
280 struct addrinfo {
281         int                     ai_flags;
282         int                     ai_family;
283         int                     ai_socktype;
284         int                     ai_protocol;
285         socklen_t               ai_addrlen;
286         struct sockaddr         *ai_addr;
287         char                    *ai_canonname;
288         struct addrinfo         *ai_next;
289 };
290 #endif   /* HAVE_STRUCT_ADDRINFO */
291
292 #if !defined(HAVE_GETADDRINFO)
293 #include "getaddrinfo.h"
294 #endif
295
296 /* Needed for some systems that don't define it (Solaris). */
297 #ifndef ifr_netmask
298 #define ifr_netmask ifr_addrs
299 #endif
300
301 #ifdef SOCKET_WRAPPER
302 #ifndef SOCKET_WRAPPER_NOT_REPLACE
303 #define SOCKET_WRAPPER_REPLACE
304 #endif
305 #include "lib/socket_wrapper/socket_wrapper.h"
306 #endif
307
308 #endif