1 #ifndef _system_network_h
2 #define _system_network_h
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
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"
36 #ifdef HAVE_SYS_SOCKET_H
37 #include <sys/socket.h>
40 #ifdef HAVE_UNIXSOCKET
44 #ifdef HAVE_NETINET_IN_H
45 #include <netinet/in.h>
47 #ifdef HAVE_ARPA_INET_H
48 #include <arpa/inet.h>
55 #ifdef HAVE_NETINET_TCP_H
56 #include <netinet/tcp.h>
60 * The next three defines are needed to access the IPTOS_* options
64 #ifdef HAVE_NETINET_IN_SYSTM_H
65 #include <netinet/in_systm.h>
68 #ifdef HAVE_NETINET_IN_IP_H
69 #include <netinet/in_ip.h>
72 #ifdef HAVE_NETINET_IP_H
73 #include <netinet/ip.h>
84 #ifdef HAVE_SYS_IOCTL_H
85 #include <sys/ioctl.h>
96 #ifndef HAVE_SOCKLEN_T
97 #define HAVE_SOCKLEN_T
98 typedef int socklen_t
;
101 #if !defined (HAVE_INET_NTOA) || defined(REPLACE_INET_NTOA)
102 /* define is in "replace.h" */
103 char *rep_inet_ntoa(struct in_addr ip
);
106 #ifndef HAVE_INET_PTON
107 /* define is in "replace.h" */
108 int rep_inet_pton(int af
, const char *src
, void *dst
);
111 #ifndef HAVE_INET_NTOP
112 /* define is in "replace.h" */
113 const char *rep_inet_ntop(int af
, const void *src
, char *dst
, socklen_t size
);
116 #ifndef HAVE_INET_ATON
117 /* define is in "replace.h" */
118 int rep_inet_aton(const char *src
, struct in_addr
*dst
);
122 /* define is in "replace.h" */
123 int rep_connect(int sockfd
, const struct sockaddr
*addr
, socklen_t addrlen
);
126 #ifndef HAVE_GETHOSTBYNAME
127 /* define is in "replace.h" */
128 struct hostent
*rep_gethostbyname(const char *name
);
131 #ifdef HAVE_IFADDRS_H
135 #ifndef HAVE_STRUCT_IFADDRS
137 struct ifaddrs
*ifa_next
; /* Pointer to next struct */
138 char *ifa_name
; /* Interface name */
139 unsigned int ifa_flags
; /* Interface flags */
140 struct sockaddr
*ifa_addr
; /* Interface address */
141 struct sockaddr
*ifa_netmask
; /* Interface netmask */
143 struct sockaddr
*ifa_dstaddr
; /* P2P interface destination */
144 void *ifa_data
; /* Address specific data */
148 #ifndef HAVE_GETIFADDRS
149 int rep_getifaddrs(struct ifaddrs
**);
152 #ifndef HAVE_FREEIFADDRS
153 void rep_freeifaddrs(struct ifaddrs
*);
156 #ifndef HAVE_SOCKETPAIR
157 /* define is in "replace.h" */
158 int rep_socketpair(int d
, int type
, int protocol
, int sv
[2]);
162 * Some systems have getaddrinfo but not the
163 * defines needed to use it.
166 /* Various macros that ought to be in <netdb.h>, but might not be */
169 #define EAI_BADFLAGS (-1)
170 #define EAI_NONAME (-2)
171 #define EAI_AGAIN (-3)
172 #define EAI_FAIL (-4)
173 #define EAI_FAMILY (-6)
174 #define EAI_SOCKTYPE (-7)
175 #define EAI_SERVICE (-8)
176 #define EAI_MEMORY (-10)
177 #define EAI_SYSTEM (-11)
178 #endif /* !EAI_FAIL */
181 #define AI_PASSIVE 0x0001
185 #define AI_CANONNAME 0x0002
188 #ifndef AI_NUMERICHOST
190 * some platforms don't support AI_NUMERICHOST; define as zero if using
191 * the system version of getaddrinfo...
193 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
194 #define AI_NUMERICHOST 0
196 #define AI_NUMERICHOST 0x0004
201 * Some of the functions in source3/lib/util_sock.c use AI_ADDRCONFIG. On QNX
202 * 6.3.0, this macro is defined but, if it's used, getaddrinfo will fail. This
203 * prevents smbd from opening any sockets.
205 * If I undefine AI_ADDRCONFIG on such systems and define it to be 0,
206 * this works around the issue.
209 #include <sys/neutrino.h>
210 #if _NTO_VERSION == 630
214 #ifndef AI_ADDRCONFIG
216 * logic copied from AI_NUMERICHOST
218 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
219 #define AI_ADDRCONFIG 0
221 #define AI_ADDRCONFIG 0x0020
225 #ifndef AI_NUMERICSERV
227 * logic copied from AI_NUMERICHOST
229 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
230 #define AI_NUMERICSERV 0
232 #define AI_NUMERICSERV 0x0400
236 #ifndef NI_NUMERICHOST
237 #define NI_NUMERICHOST 1
240 #ifndef NI_NUMERICSERV
241 #define NI_NUMERICSERV 2
249 #define NI_NAMEREQD 8
258 #define NI_MAXHOST 1025
262 #define NI_MAXSERV 32
266 * glibc on linux doesn't seem to have MSG_WAITALL
267 * defined. I think the kernel has it though..
270 #define MSG_WAITALL 0
273 #ifndef INADDR_LOOPBACK
274 #define INADDR_LOOPBACK 0x7f000001
278 #define INADDR_NONE 0xffffffff
282 #define EAFNOSUPPORT EINVAL
285 #ifndef INET_ADDRSTRLEN
286 #define INET_ADDRSTRLEN 16
289 #ifndef INET6_ADDRSTRLEN
290 #define INET6_ADDRSTRLEN 46
293 #ifndef HOST_NAME_MAX
294 #define HOST_NAME_MAX 255
297 #ifndef MAXHOSTNAMELEN
298 #define MAXHOSTNAMELEN HOST_NAME_MAX
301 #ifndef HAVE_SA_FAMILY_T
302 #define HAVE_SA_FAMILY_T
303 typedef unsigned short int sa_family_t
;
306 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
307 #define HAVE_STRUCT_SOCKADDR_STORAGE
308 #ifdef HAVE_STRUCT_SOCKADDR_IN6
309 #define sockaddr_storage sockaddr_in6
310 #define ss_family sin6_family
311 #define HAVE_SS_FAMILY 1
312 #else /*HAVE_STRUCT_SOCKADDR_IN6*/
313 #define sockaddr_storage sockaddr_in
314 #define ss_family sin_family
315 #define HAVE_SS_FAMILY 1
316 #endif /*HAVE_STRUCT_SOCKADDR_IN6*/
317 #endif /*HAVE_STRUCT_SOCKADDR_STORAGE*/
319 #ifndef HAVE_SS_FAMILY
320 #ifdef HAVE___SS_FAMILY
321 #define ss_family __ss_family
322 #define HAVE_SS_FAMILY 1
328 # define IOV_MAX UIO_MAXIOV
332 * IRIX 6.5 has sysconf(_SC_IOV_MAX)
333 * which might return 512 or bigger
340 #ifndef HAVE_STRUCT_ADDRINFO
341 #define HAVE_STRUCT_ADDRINFO
347 socklen_t ai_addrlen
;
348 struct sockaddr
*ai_addr
;
350 struct addrinfo
*ai_next
;
352 #endif /* HAVE_STRUCT_ADDRINFO */
354 #if !defined(HAVE_GETADDRINFO)
355 #include "getaddrinfo.h"
358 /* Needed for some systems that don't define it (Solaris). */
360 #define ifr_netmask ifr_addr
363 /* Some old Linux systems have broken header files */
365 #ifdef HAVE_LINUX_IPV6_V6ONLY_26
366 #define IPV6_V6ONLY 26
367 #endif /* HAVE_LINUX_IPV6_V6ONLY_26 */
368 #endif /* HAVE_IPV6 */
370 #ifdef SOCKET_WRAPPER
371 #ifndef SOCKET_WRAPPER_DISABLE
372 #ifndef SOCKET_WRAPPER_NOT_REPLACE
373 #define SOCKET_WRAPPER_REPLACE
374 #endif /* SOCKET_WRAPPER_NOT_REPLACE */
375 #include "../socket_wrapper/socket_wrapper.h"
376 #endif /* SOCKET_WRAPPER_DISABLE */
377 #endif /* SOCKET_WRAPPER */
380 # ifndef UID_WRAPPER_DISABLE
381 # ifndef UID_WRAPPER_NOT_REPLACE
382 # define UID_WRAPPER_REPLACE
383 # endif /* UID_WRAPPER_NOT_REPLACE */
384 # include "../uid_wrapper/uid_wrapper.h"
385 # endif /* UID_WRAPPER_DISABLE */
386 #else /* UID_WRAPPER */
387 # define uwrap_enabled() 0
388 #endif /* UID_WRAPPER */