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