1 /****************************************************************************
3 * GNAT COMPILER COMPONENTS *
9 * Copyright (C) 2004-2017, 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 #define FD_SETSIZE 1024
78 #define EACCES WSAEACCES
80 #define EADDRINUSE WSAEADDRINUSE
82 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
84 #define EAFNOSUPPORT WSAEAFNOSUPPORT
86 #define EALREADY WSAEALREADY
88 #define EBADF WSAEBADF
90 #define ECONNABORTED WSAECONNABORTED
92 #define ECONNREFUSED WSAECONNREFUSED
94 #define ECONNRESET WSAECONNRESET
96 #define EDESTADDRREQ WSAEDESTADDRREQ
98 #define EFAULT WSAEFAULT
100 #define EHOSTDOWN WSAEHOSTDOWN
102 #define EHOSTUNREACH WSAEHOSTUNREACH
104 #define EINPROGRESS WSAEINPROGRESS
106 #define EINTR WSAEINTR
108 #define EINVAL WSAEINVAL
110 #define EIO WSAEDISCON
112 #define EISCONN WSAEISCONN
114 #define ELOOP WSAELOOP
116 #define EMFILE WSAEMFILE
118 #define EMSGSIZE WSAEMSGSIZE
120 #define ENAMETOOLONG WSAENAMETOOLONG
122 #define ENETDOWN WSAENETDOWN
124 #define ENETRESET WSAENETRESET
126 #define ENETUNREACH WSAENETUNREACH
128 #define ENOBUFS WSAENOBUFS
130 #define ENOPROTOOPT WSAENOPROTOOPT
132 #define ENOTCONN WSAENOTCONN
134 #define ENOTSOCK WSAENOTSOCK
136 #define EOPNOTSUPP WSAEOPNOTSUPP
138 #define EPFNOSUPPORT WSAEPFNOSUPPORT
139 #undef EPROTONOSUPPORT
140 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
142 #define EPROTOTYPE WSAEPROTOTYPE
144 #define ESHUTDOWN WSAESHUTDOWN
145 #undef ESOCKTNOSUPPORT
146 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
148 #define ETIMEDOUT WSAETIMEDOUT
150 #define ETOOMANYREFS WSAETOOMANYREFS
152 #define EWOULDBLOCK WSAEWOULDBLOCK
154 #define SHUT_RD SD_RECEIVE
155 #define SHUT_WR SD_SEND
156 #define SHUT_RDWR SD_BOTH
163 /* Allow a large number of fds for select. */
164 #define FD_SETSIZE 4096
166 /* These DEC C headers are not available when building with GCC. Order is
180 #if defined (__vxworks) && ! defined (__RTP__)
181 #include <sys/times.h>
183 #include <sys/time.h>
186 #if defined(__rtems__)
188 /* Required, for read(), write(), and close() */
192 * RTEMS has these .h files but not until you have built and installed RTEMS.
193 * When building a C/C++ toolset, you also build the newlib C library, so the
194 * build procedure for an RTEMS GNAT toolset requires that you build a C/C++
195 * toolset, then build and install RTEMS with --enable-multilib, and finally
196 * build the Ada part of the toolset.
198 #if !(defined (VMS) || defined (__MINGW32__))
199 #include <sys/socket.h>
200 #include <netinet/in.h>
201 #include <netinet/tcp.h>
202 #include <sys/ioctl.h>
209 #include <sys/select.h>
212 #if defined (_AIX) || defined (__FreeBSD__) || defined (__hpux__) || \
213 defined (_WIN32) || defined (__APPLE__) || defined (__ANDROID__) || \
214 defined (__DragonFly__) || defined (__NetBSD__) || defined (__OpenBSD__)
215 # define HAVE_THREAD_SAFE_GETxxxBYyyy 1
217 #elif defined (__linux__) || defined (__GLIBC__) || \
218 (defined (__sun__) && !defined (__vxworks)) || \
220 # define HAVE_GETxxxBYyyy_R 1
224 * Properties of the unerlying NetDB library:
225 * Need_Netdb_Buffer __gnat_getXXXbyYYY expects a caller-supplied buffer
226 * Need_Netdb_Lock __gnat_getXXXbyYYY expects the caller to ensure
229 * See "Handling of gethostbyname, gethostbyaddr, getservbyname and
230 * getservbyport" in socket.c for details.
233 #if defined (HAVE_GETxxxBYyyy_R)
234 # define Need_Netdb_Buffer 1
235 # define Need_Netdb_Lock 0
238 # define Need_Netdb_Buffer 0
239 # if !defined (HAVE_THREAD_SAFE_GETxxxBYyyy)
240 # define Need_Netdb_Lock 1
242 # define Need_Netdb_Lock 0
246 #if defined (__FreeBSD__) || defined (__vxworks) || defined(__rtems__) \
247 || defined (__DragonFly__) || defined (__NetBSD__) || defined (__OpenBSD__)
248 # define Has_Sockaddr_Len 1
250 # define Has_Sockaddr_Len 0
253 #if !(defined (__vxworks) || defined (_WIN32) || defined (__hpux__) || defined (VMS))
254 # define HAVE_INET_PTON
257 #endif /* defined(VTHREADS) */