lib/replace: make sure we include <sys/uio.h> before socket_wrapper.h
[samba.git] / 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 #ifndef LIBREPLACE_NETWORK_CHECKS
31 #error "AC_LIBREPLACE_NETWORK_CHECKS missing in configure"
32 #endif
33
34 #ifdef HAVE_SYS_SOCKET_H
35 #include <sys/socket.h>
36 #endif
37
38 #ifdef HAVE_UNIXSOCKET
39 #include <sys/un.h>
40 #endif
41
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
48
49 #ifdef HAVE_NETDB_H
50 #include <netdb.h>
51 #endif
52
53 #ifdef HAVE_NETINET_TCP_H
54 #include <netinet/tcp.h>
55 #endif
56
57 /*
58  * The next three defines are needed to access the IPTOS_* options
59  * on some systems.
60  */
61
62 #ifdef HAVE_NETINET_IN_SYSTM_H
63 #include <netinet/in_systm.h>
64 #endif
65
66 #ifdef HAVE_NETINET_IN_IP_H
67 #include <netinet/in_ip.h>
68 #endif
69
70 #ifdef HAVE_NETINET_IP_H
71 #include <netinet/ip.h>
72 #endif
73
74 #ifdef HAVE_NET_IF_H
75 #include <net/if.h>
76 #endif
77
78 #ifdef HAVE_UNISTD_H
79 #include <unistd.h>
80 #endif
81
82 #ifdef HAVE_SYS_IOCTL_H
83 #include <sys/ioctl.h>
84 #endif
85
86 #ifdef HAVE_SYS_UIO_H
87 #include <sys/uio.h>
88 #endif
89
90 #ifdef HAVE_STROPTS_H
91 #include <stropts.h>
92 #endif
93
94 #ifndef HAVE_SOCKLEN_T
95 #define HAVE_SOCKLEN_T
96 typedef int socklen_t;
97 #endif
98
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
103
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
108
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
113
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
118
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
123
124 #ifndef HAVE_GETHOSTBYNAME
125 /* define is in "replace.h" */
126 struct hostent *rep_gethostbyname(const char *name);
127 #endif
128
129 #ifdef HAVE_IFADDRS_H
130 #include <ifaddrs.h>
131 #endif
132
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 */
143 };
144 #endif
145
146 #ifndef HAVE_GETIFADDRS
147 int rep_getifaddrs(struct ifaddrs **);
148 #endif
149
150 #ifndef HAVE_FREEIFADDRS
151 void rep_freeifaddrs(struct ifaddrs *);
152 #endif
153
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
158
159 /*
160  * Some systems have getaddrinfo but not the
161  * defines needed to use it.
162  */
163
164 /* Various macros that ought to be in <netdb.h>, but might not be */
165
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 */
177
178 #ifndef AI_PASSIVE
179 #define AI_PASSIVE      0x0001
180 #endif
181
182 #ifndef AI_CANONNAME
183 #define AI_CANONNAME    0x0002
184 #endif
185
186 #ifndef AI_NUMERICHOST
187 /*
188  * some platforms don't support AI_NUMERICHOST; define as zero if using
189  * the system version of getaddrinfo...
190  */
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
197
198 #ifndef AI_ADDRCONFIG
199 /*
200  * logic copied from AI_NUMERICHOST
201  */
202 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
203 #define AI_ADDRCONFIG   0
204 #else
205 #define AI_ADDRCONFIG   0x0020
206 #endif
207 #endif
208
209 #ifndef AI_NUMERICSERV
210 /*
211  * logic copied from AI_NUMERICHOST
212  */
213 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
214 #define AI_NUMERICSERV  0
215 #else
216 #define AI_NUMERICSERV  0x0400
217 #endif
218 #endif
219
220 #ifndef NI_NUMERICHOST
221 #define NI_NUMERICHOST  1
222 #endif
223
224 #ifndef NI_NUMERICSERV
225 #define NI_NUMERICSERV  2
226 #endif
227
228 #ifndef NI_NOFQDN
229 #define NI_NOFQDN       4
230 #endif
231
232 #ifndef NI_NAMEREQD
233 #define NI_NAMEREQD     8
234 #endif
235
236 #ifndef NI_DGRAM
237 #define NI_DGRAM        16
238 #endif
239
240
241 #ifndef NI_MAXHOST
242 #define NI_MAXHOST      1025
243 #endif
244
245 #ifndef NI_MAXSERV
246 #define NI_MAXSERV      32
247 #endif
248
249 /*
250  * glibc on linux doesn't seem to have MSG_WAITALL
251  * defined. I think the kernel has it though..
252  */
253 #ifndef MSG_WAITALL
254 #define MSG_WAITALL 0
255 #endif
256
257 #ifndef INADDR_LOOPBACK
258 #define INADDR_LOOPBACK 0x7f000001
259 #endif
260
261 #ifndef INADDR_NONE
262 #define INADDR_NONE 0xffffffff
263 #endif
264
265 #ifndef EAFNOSUPPORT
266 #define EAFNOSUPPORT EINVAL
267 #endif
268
269 #ifndef INET_ADDRSTRLEN
270 #define INET_ADDRSTRLEN 16
271 #endif
272
273 #ifndef INET6_ADDRSTRLEN
274 #define INET6_ADDRSTRLEN 46
275 #endif
276
277 #ifndef HOST_NAME_MAX
278 #define HOST_NAME_MAX 255
279 #endif
280
281 #ifndef MAXHOSTNAMELEN
282 #define MAXHOSTNAMELEN HOST_NAME_MAX
283 #endif
284
285 #ifndef HAVE_SA_FAMILY_T
286 #define HAVE_SA_FAMILY_T
287 typedef unsigned short int sa_family_t;
288 #endif
289
290 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
291 #define HAVE_STRUCT_SOCKADDR_STORAGE
292 #ifdef HAVE_STRUCT_SOCKADDR_IN6
293 #define sockaddr_storage sockaddr_in6
294 #define ss_family sin6_family
295 #define HAVE_SS_FAMILY 1
296 #else
297 #define sockaddr_storage sockaddr_in
298 #define ss_family sin_family
299 #define HAVE_SS_FAMILY 1
300 #endif
301 #endif
302
303 #ifndef HAVE_SS_FAMILY
304 #ifdef HAVE___SS_FAMILY
305 #define ss_family __ss_family
306 #define HAVE_SS_FAMILY 1
307 #endif
308 #endif
309
310 #ifndef HAVE_STRUCT_ADDRINFO
311 #define HAVE_STRUCT_ADDRINFO
312 struct addrinfo {
313         int                     ai_flags;
314         int                     ai_family;
315         int                     ai_socktype;
316         int                     ai_protocol;
317         socklen_t               ai_addrlen;
318         struct sockaddr         *ai_addr;
319         char                    *ai_canonname;
320         struct addrinfo         *ai_next;
321 };
322 #endif   /* HAVE_STRUCT_ADDRINFO */
323
324 #if !defined(HAVE_GETADDRINFO)
325 #include "getaddrinfo.h"
326 #endif
327
328 /* Needed for some systems that don't define it (Solaris). */
329 #ifndef ifr_netmask
330 #define ifr_netmask ifr_addr
331 #endif
332
333 #ifdef SOCKET_WRAPPER
334 #ifndef SOCKET_WRAPPER_DISABLE
335 #ifndef SOCKET_WRAPPER_NOT_REPLACE
336 #define SOCKET_WRAPPER_REPLACE
337 #endif /* SOCKET_WRAPPER_NOT_REPLACE */
338 #include "../socket_wrapper/socket_wrapper.h"
339 #endif /* SOCKET_WRAPPER_DISABLE */
340 #endif /* SOCKET_WRAPPER */
341
342 #endif