1 /****************************************************************************
3 * GNAT COMPILER COMPONENTS *
9 * Copyright (C) 2004-2023, 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
85 #include <versionhelpers.h>
88 #define EACCES WSAEACCES
90 #define EADDRINUSE WSAEADDRINUSE
92 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
94 #define EAFNOSUPPORT WSAEAFNOSUPPORT
96 #define EALREADY WSAEALREADY
98 #define EBADF WSAEBADF
100 #define ECONNABORTED WSAECONNABORTED
102 #define ECONNREFUSED WSAECONNREFUSED
104 #define ECONNRESET WSAECONNRESET
106 #define EDESTADDRREQ WSAEDESTADDRREQ
108 #define EFAULT WSAEFAULT
110 #define EHOSTDOWN WSAEHOSTDOWN
112 #define EHOSTUNREACH WSAEHOSTUNREACH
114 #define EINPROGRESS WSAEINPROGRESS
116 #define EINTR WSAEINTR
118 #define EINVAL WSAEINVAL
120 #define EIO WSAEDISCON
122 #define EISCONN WSAEISCONN
124 #define ELOOP WSAELOOP
126 #define EMFILE WSAEMFILE
128 #define EMSGSIZE WSAEMSGSIZE
130 #define ENAMETOOLONG WSAENAMETOOLONG
132 #define ENETDOWN WSAENETDOWN
134 #define ENETRESET WSAENETRESET
136 #define ENETUNREACH WSAENETUNREACH
138 #define ENOBUFS WSAENOBUFS
140 #define ENOPROTOOPT WSAENOPROTOOPT
142 #define ENOTCONN WSAENOTCONN
144 #define ENOTSOCK WSAENOTSOCK
146 #define EOPNOTSUPP WSAEOPNOTSUPP
148 #define EPFNOSUPPORT WSAEPFNOSUPPORT
149 #undef EPROTONOSUPPORT
150 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
152 #define EPROTOTYPE WSAEPROTOTYPE
154 #define ESHUTDOWN WSAESHUTDOWN
155 #undef ESOCKTNOSUPPORT
156 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
158 #define ETIMEDOUT WSAETIMEDOUT
160 #define ETOOMANYREFS WSAETOOMANYREFS
162 #define EWOULDBLOCK WSAEWOULDBLOCK
164 #define SHUT_RD SD_RECEIVE
165 #define SHUT_WR SD_SEND
166 #define SHUT_RDWR SD_BOTH
170 #define WIN32_LEAN_AND_MEAN
174 /* Allow a large number of fds for select. */
175 #define FD_SETSIZE 4096
177 /* These DEC C headers are not available when building with GCC. Order is
192 #if defined (__vxworks) && ! defined (__RTP__)
193 #include <sys/times.h>
195 #include <sys/time.h>
198 #if defined(__rtems__)
200 /* Required, for read(), write(), and close() */
204 * RTEMS has these .h files but not until you have built and installed RTEMS.
205 * When building a C/C++ toolset, you also build the newlib C library, so the
206 * build procedure for an RTEMS GNAT toolset requires that you build a C/C++
207 * toolset, then build and install RTEMS with --enable-multilib, and finally
208 * build the Ada part of the toolset.
210 #if !(defined (VMS) || defined (__MINGW32__))
211 #include <sys/socket.h>
214 #include <netinet/in.h>
215 #include <netinet/tcp.h>
216 #include <sys/ioctl.h>
223 #include <sys/select.h>
226 #if defined (_AIX) || defined (__FreeBSD__) || defined (__hpux__) || \
227 defined (_WIN32) || defined (__APPLE__) || defined (__ANDROID__) || \
228 defined (__DragonFly__) || defined (__NetBSD__) || defined (__OpenBSD__)
229 # define HAVE_THREAD_SAFE_GETxxxBYyyy 1
231 #elif defined (__linux__) || defined (__GLIBC__) || \
232 (defined (__sun__) && !defined (__vxworks)) || \
234 # define HAVE_GETxxxBYyyy_R 1
238 * Properties of the unerlying NetDB library:
239 * Need_Netdb_Buffer __gnat_getXXXbyYYY expects a caller-supplied buffer
240 * Need_Netdb_Lock __gnat_getXXXbyYYY expects the caller to ensure
243 * See "Handling of gethostbyname, gethostbyaddr, getservbyname and
244 * getservbyport" in socket.c for details.
247 #if defined (HAVE_GETxxxBYyyy_R)
248 # define Need_Netdb_Buffer 1
249 # define Need_Netdb_Lock 0
252 # define Need_Netdb_Buffer 0
253 # if !defined (HAVE_THREAD_SAFE_GETxxxBYyyy)
254 # define Need_Netdb_Lock 1
256 # define Need_Netdb_Lock 0
260 # define Has_Sockaddr_Len (offsetof(struct sockaddr_in, sin_family) != 0)
262 #if !(defined (_WIN32) || defined (__hpux__) || defined (VMS))
263 # define HAVE_INET_PTON
264 # define HAVE_INET_NTOP
267 #endif /* defined(VTHREADS) */