1 /****************************************************************************
3 * GNAT COMPILER COMPONENTS *
9 * Copyright (C) 2004-2021, Free Software Foundation, Inc. *
11 * GNAT is free software; you can redistribute it and/or modify it under *
12 * terms of the GNU General Public License as published by the Free Soft- *
13 * ware Foundation; either version 3, or (at your option) any later ver- *
14 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
15 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
16 * or FITNESS FOR A PARTICULAR PURPOSE. *
18 * As a special exception under Section 7 of GPL version 3, you are granted *
19 * additional permissions described in the GCC Runtime Library Exception, *
20 * version 3.1, as published by the Free Software Foundation. *
22 * You should have received a copy of the GNU General Public License and *
23 * a copy of the GCC Runtime Library Exception along with this program; *
24 * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see *
25 * <http://www.gnu.org/licenses/>. *
27 * GNAT was originally developed by the GNAT team at New York University. *
28 * Extensive contributions were provided by Ada Core Technologies Inc. *
30 ****************************************************************************/
32 #if defined(VTHREADS) || defined(__PikeOS__) || defined(__DJGPP__)
34 /* Sockets not supported on these platforms. */
41 #ifndef _XOPEN_SOURCE_EXTENDED
42 #define _XOPEN_SOURCE_EXTENDED 1
56 /** No system header may be included prior to this point since on some targets
57 ** we need to redefine FD_SETSIZE.
60 /* Target-specific includes and definitions */
62 #if defined(__vxworks)
71 #ifndef IPV6_ADD_MEMBERSHIP
72 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
75 #ifndef IPV6_DROP_MEMBERSHIP
76 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
80 #define FD_SETSIZE 1024
83 /* winsock2.h allows WSAPoll related definitions only when
84 * _WIN32_WINNT >= 0x0600 */
85 #if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600
86 #define _WIN32_WINNT 0x0600
91 #include <versionhelpers.h>
94 #define EACCES WSAEACCES
96 #define EADDRINUSE WSAEADDRINUSE
98 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
100 #define EAFNOSUPPORT WSAEAFNOSUPPORT
102 #define EALREADY WSAEALREADY
104 #define EBADF WSAEBADF
106 #define ECONNABORTED WSAECONNABORTED
108 #define ECONNREFUSED WSAECONNREFUSED
110 #define ECONNRESET WSAECONNRESET
112 #define EDESTADDRREQ WSAEDESTADDRREQ
114 #define EFAULT WSAEFAULT
116 #define EHOSTDOWN WSAEHOSTDOWN
118 #define EHOSTUNREACH WSAEHOSTUNREACH
120 #define EINPROGRESS WSAEINPROGRESS
122 #define EINTR WSAEINTR
124 #define EINVAL WSAEINVAL
126 #define EIO WSAEDISCON
128 #define EISCONN WSAEISCONN
130 #define ELOOP WSAELOOP
132 #define EMFILE WSAEMFILE
134 #define EMSGSIZE WSAEMSGSIZE
136 #define ENAMETOOLONG WSAENAMETOOLONG
138 #define ENETDOWN WSAENETDOWN
140 #define ENETRESET WSAENETRESET
142 #define ENETUNREACH WSAENETUNREACH
144 #define ENOBUFS WSAENOBUFS
146 #define ENOPROTOOPT WSAENOPROTOOPT
148 #define ENOTCONN WSAENOTCONN
150 #define ENOTSOCK WSAENOTSOCK
152 #define EOPNOTSUPP WSAEOPNOTSUPP
154 #define EPFNOSUPPORT WSAEPFNOSUPPORT
155 #undef EPROTONOSUPPORT
156 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
158 #define EPROTOTYPE WSAEPROTOTYPE
160 #define ESHUTDOWN WSAESHUTDOWN
161 #undef ESOCKTNOSUPPORT
162 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
164 #define ETIMEDOUT WSAETIMEDOUT
166 #define ETOOMANYREFS WSAETOOMANYREFS
168 #define EWOULDBLOCK WSAEWOULDBLOCK
170 #define SHUT_RD SD_RECEIVE
171 #define SHUT_WR SD_SEND
172 #define SHUT_RDWR SD_BOTH
179 /* Allow a large number of fds for select. */
180 #define FD_SETSIZE 4096
182 /* These DEC C headers are not available when building with GCC. Order is
197 #if defined (__vxworks) && ! defined (__RTP__)
198 #include <sys/times.h>
200 #include <sys/time.h>
203 #if defined(__rtems__)
205 /* Required, for read(), write(), and close() */
209 * RTEMS has these .h files but not until you have built and installed RTEMS.
210 * When building a C/C++ toolset, you also build the newlib C library, so the
211 * build procedure for an RTEMS GNAT toolset requires that you build a C/C++
212 * toolset, then build and install RTEMS with --enable-multilib, and finally
213 * build the Ada part of the toolset.
215 #if !(defined (VMS) || defined (__MINGW32__))
216 #include <sys/socket.h>
219 #include <netinet/in.h>
220 #include <netinet/tcp.h>
221 #include <sys/ioctl.h>
228 #include <sys/select.h>
231 #if defined (_AIX) || defined (__FreeBSD__) || defined (__hpux__) || \
232 defined (_WIN32) || defined (__APPLE__) || defined (__ANDROID__) || \
233 defined (__DragonFly__) || defined (__NetBSD__) || defined (__OpenBSD__)
234 # define HAVE_THREAD_SAFE_GETxxxBYyyy 1
236 #elif defined (__linux__) || defined (__GLIBC__) || \
237 (defined (__sun__) && !defined (__vxworks)) || \
239 # define HAVE_GETxxxBYyyy_R 1
243 * Properties of the unerlying NetDB library:
244 * Need_Netdb_Buffer __gnat_getXXXbyYYY expects a caller-supplied buffer
245 * Need_Netdb_Lock __gnat_getXXXbyYYY expects the caller to ensure
248 * See "Handling of gethostbyname, gethostbyaddr, getservbyname and
249 * getservbyport" in socket.c for details.
252 #if defined (HAVE_GETxxxBYyyy_R)
253 # define Need_Netdb_Buffer 1
254 # define Need_Netdb_Lock 0
257 # define Need_Netdb_Buffer 0
258 # if !defined (HAVE_THREAD_SAFE_GETxxxBYyyy)
259 # define Need_Netdb_Lock 1
261 # define Need_Netdb_Lock 0
265 # define Has_Sockaddr_Len (offsetof(struct sockaddr_in, sin_family) != 0)
267 #if !(defined (_WIN32) || defined (__hpux__) || defined (VMS))
268 # define HAVE_INET_PTON
269 # define HAVE_INET_NTOP
272 #endif /* defined(VTHREADS) */