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 #ifdef HAVE_SYS_SOCKET_H
31 #include <sys/socket.h>
34 #ifdef HAVE_UNIXSOCKET
38 #ifdef HAVE_NETINET_IN_H
39 #include <netinet/in.h>
41 #ifdef HAVE_ARPA_INET_H
42 #include <arpa/inet.h>
49 #ifdef HAVE_NETINET_TCP_H
50 #include <netinet/tcp.h>
54 * The next three defines are needed to access the IPTOS_* options
58 #ifdef HAVE_NETINET_IN_SYSTM_H
59 #include <netinet/in_systm.h>
62 #ifdef HAVE_NETINET_IN_IP_H
63 #include <netinet/in_ip.h>
66 #ifdef HAVE_NETINET_IP_H
67 #include <netinet/ip.h>
78 #ifdef HAVE_SYS_IOCTL_H
79 #include <sys/ioctl.h>
86 #ifndef HAVE_SOCKLEN_T
87 #define HAVE_SOCKLEN_T
88 typedef int socklen_t;
91 #if !defined (HAVE_INET_NTOA) || defined(REPLACE_INET_NTOA)
92 /* define is in "replace.h" */
93 char *rep_inet_ntoa(struct in_addr ip);
96 #ifndef HAVE_INET_PTON
97 /* define is in "replace.h" */
98 int rep_inet_pton(int af, const char *src, void *dst);
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);
106 #ifndef HAVE_INET_ATON
107 /* define is in "replace.h" */
108 int rep_inet_aton(const char *src, struct in_addr *dst);
112 /* define is in "replace.h" */
113 int rep_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
116 #ifndef HAVE_GETHOSTBYNAME
117 /* define is in "replace.h" */
118 struct hostent *rep_gethostbyname(const char *name);
121 #ifdef HAVE_IFADDRS_H
125 #ifndef HAVE_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 */
133 struct sockaddr *ifa_dstaddr; /* P2P interface destination */
134 void *ifa_data; /* Address specific data */
138 #ifndef HAVE_GETIFADDRS
139 int rep_getifaddrs(struct ifaddrs **);
142 #ifndef HAVE_FREEIFADDRS
143 void rep_freeifaddrs(struct ifaddrs *);
146 #ifndef HAVE_SOCKETPAIR
147 /* define is in "replace.h" */
148 int rep_socketpair(int d, int type, int protocol, int sv[2]);
152 * Some systems have getaddrinfo but not the
153 * defines needed to use it.
156 /* Various macros that ought to be in <netdb.h>, but might not be */
159 #define EAI_BADFLAGS (-1)
160 #define EAI_NONAME (-2)
161 #define EAI_AGAIN (-3)
162 #define EAI_FAIL (-4)
163 #define EAI_FAMILY (-6)
164 #define EAI_SOCKTYPE (-7)
165 #define EAI_SERVICE (-8)
166 #define EAI_MEMORY (-10)
167 #define EAI_SYSTEM (-11)
168 #endif /* !EAI_FAIL */
171 #define AI_PASSIVE 0x0001
175 #define AI_CANONNAME 0x0002
178 #ifndef AI_NUMERICHOST
180 * some platforms don't support AI_NUMERICHOST; define as zero if using
181 * the system version of getaddrinfo...
183 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
184 #define AI_NUMERICHOST 0
186 #define AI_NUMERICHOST 0x0004
190 #ifndef AI_ADDRCONFIG
192 * logic copied from AI_NUMERICHOST
194 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
195 #define AI_ADDRCONFIG 0
197 #define AI_ADDRCONFIG 0x0020
201 #ifndef AI_NUMERICSERV
203 * logic copied from AI_NUMERICHOST
205 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
206 #define AI_NUMERICSERV 0
208 #define AI_NUMERICSERV 0x0400
212 #ifndef NI_NUMERICHOST
213 #define NI_NUMERICHOST 1
216 #ifndef NI_NUMERICSERV
217 #define NI_NUMERICSERV 2
225 #define NI_NAMEREQD 8
234 #define NI_MAXHOST 1025
238 #define NI_MAXSERV 32
242 * glibc on linux doesn't seem to have MSG_WAITALL
243 * defined. I think the kernel has it though..
246 #define MSG_WAITALL 0
249 #ifndef INADDR_LOOPBACK
250 #define INADDR_LOOPBACK 0x7f000001
254 #define INADDR_NONE 0xffffffff
258 #define EAFNOSUPPORT EINVAL
261 #ifndef INET_ADDRSTRLEN
262 #define INET_ADDRSTRLEN 16
265 #ifndef INET6_ADDRSTRLEN
266 #define INET6_ADDRSTRLEN 46
269 #ifndef HOST_NAME_MAX
270 #define HOST_NAME_MAX 256
273 #ifndef HAVE_SA_FAMILY_T
274 #define HAVE_SA_FAMILY_T
275 typedef unsigned short int sa_family_t;
278 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
279 #define HAVE_STRUCT_SOCKADDR_STORAGE
280 #ifdef HAVE_STRUCT_SOCKADDR_IN6
281 #define sockaddr_storage sockaddr_in6
282 #define ss_family sin6_family
283 #define HAVE_SS_FAMILY 1
285 #define sockaddr_storage sockaddr_in
286 #define ss_family sin_family
287 #define HAVE_SS_FAMILY 1
291 #ifndef HAVE_SS_FAMILY
292 #ifdef HAVE___SS_FAMILY
293 #define ss_family __ss_family
294 #define HAVE_SS_FAMILY 1
298 #ifndef HAVE_STRUCT_ADDRINFO
299 #define HAVE_STRUCT_ADDRINFO
305 socklen_t ai_addrlen;
306 struct sockaddr *ai_addr;
308 struct addrinfo *ai_next;
310 #endif /* HAVE_STRUCT_ADDRINFO */
312 #if !defined(HAVE_GETADDRINFO)
313 #include "getaddrinfo.h"
316 /* Needed for some systems that don't define it (Solaris). */
318 #define ifr_netmask ifr_addr
321 #ifdef SOCKET_WRAPPER
322 #ifndef SOCKET_WRAPPER_NOT_REPLACE
323 #define SOCKET_WRAPPER_REPLACE
325 #include "lib/socket_wrapper/socket_wrapper.h"