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