clang: Compiler tweaks to make android build for x64
[chromium-blink-merge.git] / third_party / talloc / libreplace / system / network.h
blob1f510350bd97ca129c55d38577a67be84a4aec10
1 #ifndef _system_network_h
2 #define _system_network_h
3 /*
4 Unix SMB/CIFS implementation.
6 networking system include wrappers
8 Copyright (C) Andrew Tridgell 2004
9 Copyright (C) Jelmer Vernooij 2007
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
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.
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.
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/>.
30 #ifndef LIBREPLACE_NETWORK_CHECKS
31 #error "AC_LIBREPLACE_NETWORK_CHECKS missing in configure"
32 #endif
34 #ifdef HAVE_SYS_SOCKET_H
35 #include <sys/socket.h>
36 #endif
38 #ifdef HAVE_UNIXSOCKET
39 #include <sys/un.h>
40 #endif
42 #ifdef HAVE_NETINET_IN_H
43 #include <netinet/in.h>
44 #endif
45 #ifdef HAVE_ARPA_INET_H
46 #include <arpa/inet.h>
47 #endif
49 #ifdef HAVE_NETDB_H
50 #include <netdb.h>
51 #endif
53 #ifdef HAVE_NETINET_TCP_H
54 #include <netinet/tcp.h>
55 #endif
58 * The next three defines are needed to access the IPTOS_* options
59 * on some systems.
62 #ifdef HAVE_NETINET_IN_SYSTM_H
63 #include <netinet/in_systm.h>
64 #endif
66 #ifdef HAVE_NETINET_IN_IP_H
67 #include <netinet/in_ip.h>
68 #endif
70 #ifdef HAVE_NETINET_IP_H
71 #include <netinet/ip.h>
72 #endif
74 #ifdef HAVE_NET_IF_H
75 #include <net/if.h>
76 #endif
78 #ifdef HAVE_UNISTD_H
79 #include <unistd.h>
80 #endif
82 #ifdef HAVE_SYS_IOCTL_H
83 #include <sys/ioctl.h>
84 #endif
86 #ifdef HAVE_SYS_UIO_H
87 #include <sys/uio.h>
88 #endif
90 #ifdef HAVE_STROPTS_H
91 #include <stropts.h>
92 #endif
94 #ifndef HAVE_SOCKLEN_T
95 #define HAVE_SOCKLEN_T
96 typedef int socklen_t;
97 #endif
99 #if !defined (HAVE_INET_NTOA) || defined(REPLACE_INET_NTOA)
100 /* define is in "replace.h" */
101 char *rep_inet_ntoa(struct in_addr ip);
102 #endif
104 #ifndef HAVE_INET_PTON
105 /* define is in "replace.h" */
106 int rep_inet_pton(int af, const char *src, void *dst);
107 #endif
109 #ifndef HAVE_INET_NTOP
110 /* define is in "replace.h" */
111 const char *rep_inet_ntop(int af, const void *src, char *dst, socklen_t size);
112 #endif
114 #ifndef HAVE_INET_ATON
115 /* define is in "replace.h" */
116 int rep_inet_aton(const char *src, struct in_addr *dst);
117 #endif
119 #ifndef HAVE_CONNECT
120 /* define is in "replace.h" */
121 int rep_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
122 #endif
124 #ifndef HAVE_GETHOSTBYNAME
125 /* define is in "replace.h" */
126 struct hostent *rep_gethostbyname(const char *name);
127 #endif
129 #ifdef HAVE_IFADDRS_H
130 #include <ifaddrs.h>
131 #endif
133 #ifndef HAVE_STRUCT_IFADDRS
134 struct ifaddrs {
135 struct ifaddrs *ifa_next; /* Pointer to next struct */
136 char *ifa_name; /* Interface name */
137 unsigned int ifa_flags; /* Interface flags */
138 struct sockaddr *ifa_addr; /* Interface address */
139 struct sockaddr *ifa_netmask; /* Interface netmask */
140 #undef ifa_dstaddr
141 struct sockaddr *ifa_dstaddr; /* P2P interface destination */
142 void *ifa_data; /* Address specific data */
144 #endif
146 #ifndef HAVE_GETIFADDRS
147 int rep_getifaddrs(struct ifaddrs **);
148 #endif
150 #ifndef HAVE_FREEIFADDRS
151 void rep_freeifaddrs(struct ifaddrs *);
152 #endif
154 #ifndef HAVE_SOCKETPAIR
155 /* define is in "replace.h" */
156 int rep_socketpair(int d, int type, int protocol, int sv[2]);
157 #endif
160 * Some systems have getaddrinfo but not the
161 * defines needed to use it.
164 /* Various macros that ought to be in <netdb.h>, but might not be */
166 #ifndef EAI_FAIL
167 #define EAI_BADFLAGS (-1)
168 #define EAI_NONAME (-2)
169 #define EAI_AGAIN (-3)
170 #define EAI_FAIL (-4)
171 #define EAI_FAMILY (-6)
172 #define EAI_SOCKTYPE (-7)
173 #define EAI_SERVICE (-8)
174 #define EAI_MEMORY (-10)
175 #define EAI_SYSTEM (-11)
176 #endif /* !EAI_FAIL */
178 #ifndef AI_PASSIVE
179 #define AI_PASSIVE 0x0001
180 #endif
182 #ifndef AI_CANONNAME
183 #define AI_CANONNAME 0x0002
184 #endif
186 #ifndef AI_NUMERICHOST
188 * some platforms don't support AI_NUMERICHOST; define as zero if using
189 * the system version of getaddrinfo...
191 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
192 #define AI_NUMERICHOST 0
193 #else
194 #define AI_NUMERICHOST 0x0004
195 #endif
196 #endif
199 * Some of the functions in source3/lib/util_sock.c use AI_ADDRCONFIG. On QNX
200 * 6.3.0, this macro is defined but, if it's used, getaddrinfo will fail. This
201 * prevents smbd from opening any sockets.
203 * If I undefine AI_ADDRCONFIG on such systems and define it to be 0,
204 * this works around the issue.
206 #ifdef __QNX__
207 #include <sys/neutrino.h>
208 #if _NTO_VERSION == 630
209 #undef AI_ADDRCONFIG
210 #endif
211 #endif
212 #ifndef AI_ADDRCONFIG
214 * logic copied from AI_NUMERICHOST
216 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
217 #define AI_ADDRCONFIG 0
218 #else
219 #define AI_ADDRCONFIG 0x0020
220 #endif
221 #endif
223 #ifndef AI_NUMERICSERV
225 * logic copied from AI_NUMERICHOST
227 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
228 #define AI_NUMERICSERV 0
229 #else
230 #define AI_NUMERICSERV 0x0400
231 #endif
232 #endif
234 #ifndef NI_NUMERICHOST
235 #define NI_NUMERICHOST 1
236 #endif
238 #ifndef NI_NUMERICSERV
239 #define NI_NUMERICSERV 2
240 #endif
242 #ifndef NI_NOFQDN
243 #define NI_NOFQDN 4
244 #endif
246 #ifndef NI_NAMEREQD
247 #define NI_NAMEREQD 8
248 #endif
250 #ifndef NI_DGRAM
251 #define NI_DGRAM 16
252 #endif
255 #ifndef NI_MAXHOST
256 #define NI_MAXHOST 1025
257 #endif
259 #ifndef NI_MAXSERV
260 #define NI_MAXSERV 32
261 #endif
264 * glibc on linux doesn't seem to have MSG_WAITALL
265 * defined. I think the kernel has it though..
267 #ifndef MSG_WAITALL
268 #define MSG_WAITALL 0
269 #endif
271 #ifndef INADDR_LOOPBACK
272 #define INADDR_LOOPBACK 0x7f000001
273 #endif
275 #ifndef INADDR_NONE
276 #define INADDR_NONE 0xffffffff
277 #endif
279 #ifndef EAFNOSUPPORT
280 #define EAFNOSUPPORT EINVAL
281 #endif
283 #ifndef INET_ADDRSTRLEN
284 #define INET_ADDRSTRLEN 16
285 #endif
287 #ifndef INET6_ADDRSTRLEN
288 #define INET6_ADDRSTRLEN 46
289 #endif
291 #ifndef HOST_NAME_MAX
292 #define HOST_NAME_MAX 255
293 #endif
295 #ifndef MAXHOSTNAMELEN
296 #define MAXHOSTNAMELEN HOST_NAME_MAX
297 #endif
299 #ifndef HAVE_SA_FAMILY_T
300 #define HAVE_SA_FAMILY_T
301 typedef unsigned short int sa_family_t;
302 #endif
304 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
305 #define HAVE_STRUCT_SOCKADDR_STORAGE
306 #ifdef HAVE_STRUCT_SOCKADDR_IN6
307 #define sockaddr_storage sockaddr_in6
308 #define ss_family sin6_family
309 #define HAVE_SS_FAMILY 1
310 #else
311 #define sockaddr_storage sockaddr_in
312 #define ss_family sin_family
313 #define HAVE_SS_FAMILY 1
314 #endif
315 #endif
317 #ifndef HAVE_SS_FAMILY
318 #ifdef HAVE___SS_FAMILY
319 #define ss_family __ss_family
320 #define HAVE_SS_FAMILY 1
321 #endif
322 #endif
324 #ifndef IOV_MAX
325 # ifdef UIO_MAXIOV
326 # define IOV_MAX UIO_MAXIOV
327 # else
328 # ifdef __sgi
330 * IRIX 6.5 has sysconf(_SC_IOV_MAX)
331 * which might return 512 or bigger
333 # define IOV_MAX 512
334 # else
335 # error IOV_MAX and UIO_MAXIOV undefined
336 # endif
337 # endif
338 #endif
340 #ifndef HAVE_STRUCT_ADDRINFO
341 #define HAVE_STRUCT_ADDRINFO
342 struct addrinfo {
343 int ai_flags;
344 int ai_family;
345 int ai_socktype;
346 int ai_protocol;
347 socklen_t ai_addrlen;
348 struct sockaddr *ai_addr;
349 char *ai_canonname;
350 struct addrinfo *ai_next;
352 #endif /* HAVE_STRUCT_ADDRINFO */
354 #if !defined(HAVE_GETADDRINFO)
355 #include "getaddrinfo.h"
356 #endif
358 /* Needed for some systems that don't define it (Solaris). */
359 #ifndef ifr_netmask
360 #define ifr_netmask ifr_addr
361 #endif
363 #ifdef SOCKET_WRAPPER
364 #ifndef SOCKET_WRAPPER_DISABLE
365 #ifndef SOCKET_WRAPPER_NOT_REPLACE
366 #define SOCKET_WRAPPER_REPLACE
367 #endif /* SOCKET_WRAPPER_NOT_REPLACE */
368 #include "../socket_wrapper/socket_wrapper.h"
369 #endif /* SOCKET_WRAPPER_DISABLE */
370 #endif /* SOCKET_WRAPPER */
372 #endif