e9e770205de4084e4038c7abd4767f82ddea33ff
[samba.git] / source / 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 #ifndef HAVE_SOCKLEN_T
87 #define HAVE_SOCKLEN_T
88 typedef int socklen_t;
89 #endif
90
91 #ifdef REPLACE_INET_NTOA
92 /* define is in "replace.h" */
93 char *rep_inet_ntoa(struct in_addr ip);
94 #endif
95
96 #ifndef HAVE_INET_PTON
97 /* define is in "replace.h" */
98 int rep_inet_pton(int af, const char *src, void *dst);
99 #endif
100
101 #ifndef HAVE_INET_NTOP
102 /* define is in "replace.h" */
103 const char *rep_inet_ntop(int af, const void *src, char *dst, socklen_t size);
104 #endif
105
106 #ifndef HAVE_INET_ATON
107 /* define is in "replace.h" */
108 int rep_inet_aton(const char *src, struct in_addr *dst);
109 #endif
110
111 #ifndef HAVE_CONNECT
112 /* define is in "replace.h" */
113 int rep_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
114 #endif
115
116 #ifndef HAVE_GETHOSTBYNAME
117 /* define is in "replace.h" */
118 struct hostent *rep_gethostbyname(const char *name);
119 #endif
120
121 #ifdef HAVE_IFADDRS_H
122 #include <ifaddrs.h>
123 #endif
124
125 #ifndef HAVE_STRUCT_IFADDRS
126 struct ifaddrs {
127         struct ifaddrs   *ifa_next;         /* Pointer to next struct */
128         char             *ifa_name;         /* Interface name */
129         unsigned int     ifa_flags;         /* Interface flags */
130         struct sockaddr  *ifa_addr;         /* Interface address */
131         struct sockaddr  *ifa_netmask;      /* Interface netmask */
132 #undef ifa_dstaddr
133         struct sockaddr  *ifa_dstaddr;      /* P2P interface destination */
134         void             *ifa_data;         /* Address specific data */
135 };
136 #endif
137
138 #ifndef HAVE_GETIFADDRS
139 int rep_getifaddrs(struct ifaddrs **);
140 #endif
141
142 #ifndef HAVE_FREEIFADDRS
143 void rep_freeifaddrs(struct ifaddrs *);
144 #endif
145
146 /*
147  * Some systems have getaddrinfo but not the
148  * defines needed to use it.
149  */
150
151 /* Various macros that ought to be in <netdb.h>, but might not be */
152
153 #ifndef EAI_FAIL
154 #define EAI_BADFLAGS    (-1)
155 #define EAI_NONAME      (-2)
156 #define EAI_AGAIN       (-3)
157 #define EAI_FAIL        (-4)
158 #define EAI_FAMILY      (-6)
159 #define EAI_SOCKTYPE    (-7)
160 #define EAI_SERVICE     (-8)
161 #define EAI_MEMORY      (-10)
162 #define EAI_SYSTEM      (-11)
163 #endif   /* !EAI_FAIL */
164
165 #ifndef AI_PASSIVE
166 #define AI_PASSIVE      0x0001
167 #endif
168
169 #ifndef AI_CANONNAME
170 #define AI_CANONNAME    0x0002
171 #endif
172
173 #ifndef AI_NUMERICHOST
174 /*
175  * some platforms don't support AI_NUMERICHOST; define as zero if using
176  * the system version of getaddrinfo...
177  */
178 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
179 #define AI_NUMERICHOST  0
180 #else
181 #define AI_NUMERICHOST  0x0004
182 #endif
183 #endif
184
185 #ifndef AI_ADDRCONFIG
186 /*
187  * logic copied from AI_NUMERICHOST
188  */
189 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
190 #define AI_ADDRCONFIG   0
191 #else
192 #define AI_ADDRCONFIG   0x0020
193 #endif
194 #endif
195
196 #ifndef AI_NUMERICSERV
197 /*
198  * logic copied from AI_NUMERICHOST
199  */
200 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
201 #define AI_NUMERICSERV  0
202 #else
203 #define AI_NUMERICSERV  0x0400
204 #endif
205 #endif
206
207 #ifndef NI_NUMERICHOST
208 #define NI_NUMERICHOST  1
209 #endif
210
211 #ifndef NI_NUMERICSERV
212 #define NI_NUMERICSERV  2
213 #endif
214
215 #ifndef NI_NOFQDN
216 #define NI_NOFQDN       4
217 #endif
218
219 #ifndef NI_NAMEREQD
220 #define NI_NAMEREQD     8
221 #endif
222
223 #ifndef NI_DGRAM
224 #define NI_DGRAM        16
225 #endif
226
227
228 #ifndef NI_MAXHOST
229 #define NI_MAXHOST      1025
230 #endif
231
232 #ifndef NI_MAXSERV
233 #define NI_MAXSERV      32
234 #endif
235
236 /*
237  * glibc on linux doesn't seem to have MSG_WAITALL
238  * defined. I think the kernel has it though..
239  */
240 #ifndef MSG_WAITALL
241 #define MSG_WAITALL 0
242 #endif
243
244 #ifndef INADDR_LOOPBACK
245 #define INADDR_LOOPBACK 0x7f000001
246 #endif
247
248 #ifndef INADDR_NONE
249 #define INADDR_NONE 0xffffffff
250 #endif
251
252 #ifndef EAFNOSUPPORT
253 #define EAFNOSUPPORT EINVAL
254 #endif
255
256 #ifndef INET_ADDRSTRLEN
257 #define INET_ADDRSTRLEN 16
258 #endif
259
260 #ifndef INET6_ADDRSTRLEN
261 #define INET6_ADDRSTRLEN 46
262 #endif
263
264 #ifndef HOST_NAME_MAX
265 #define HOST_NAME_MAX 256
266 #endif
267
268 #ifndef HAVE_SA_FAMILY_T
269 #define HAVE_SA_FAMILY_T
270 typedef unsigned short int sa_family_t;
271 #endif
272
273 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
274 #define HAVE_STRUCT_SOCKADDR_STORAGE
275 #ifdef HAVE_STRUCT_SOCKADDR_IN6
276 #define sockaddr_storage sockaddr_in6
277 #define ss_family sin6_family
278 #define HAVE_SS_FAMILY 1
279 #else
280 #define sockaddr_storage sockaddr_in
281 #define ss_family sin_family
282 #define HAVE_SS_FAMILY 1
283 #endif
284 #endif
285
286 #ifndef HAVE_SS_FAMILY
287 #ifdef HAVE___SS_FAMILY
288 #define ss_family __ss_family
289 #define HAVE_SS_FAMILY 1
290 #endif
291 #endif
292
293 #ifndef HAVE_STRUCT_ADDRINFO
294 #define HAVE_STRUCT_ADDRINFO
295 struct addrinfo {
296         int                     ai_flags;
297         int                     ai_family;
298         int                     ai_socktype;
299         int                     ai_protocol;
300         socklen_t               ai_addrlen;
301         struct sockaddr         *ai_addr;
302         char                    *ai_canonname;
303         struct addrinfo         *ai_next;
304 };
305 #endif   /* HAVE_STRUCT_ADDRINFO */
306
307 #if !defined(HAVE_GETADDRINFO)
308 #include "getaddrinfo.h"
309 #endif
310
311 /* Needed for some systems that don't define it (Solaris). */
312 #ifndef ifr_netmask
313 #define ifr_netmask ifr_addr
314 #endif
315
316 #ifdef SOCKET_WRAPPER
317 #ifndef SOCKET_WRAPPER_NOT_REPLACE
318 #define SOCKET_WRAPPER_REPLACE
319 #endif
320 #include "lib/socket_wrapper/socket_wrapper.h"
321 #endif
322
323 #endif