1 /**************************************************************************** 2 * * 3 * GNAT COMPILER COMPONENTS * 4 * * 5 * G S O C K E T * 6 * * 7 * C Header File * 8 * * 9 * Copyright (C) 2004-2012, Free Software Foundation, Inc. * 10 * * 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. * 17 * * 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. * 21 * * 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/>. * 26 * * 27 * GNAT was originally developed by the GNAT team at New York University. * 28 * Extensive contributions were provided by Ada Core Technologies Inc. * 29 * * 30 ****************************************************************************/ 31 32 #if defined(__nucleus__) || defined(VTHREADS) || defined(__ANDROID__) 33 34 #warning Sockets not supported on these platforms 35 #undef HAVE_SOCKETS 36 37 #else 38 39 #define HAVE_SOCKETS 40 41 #ifndef _XOPEN_SOURCE_EXTENDED 42 #define _XOPEN_SOURCE_EXTENDED 1 43 /* For HP-UX */ 44 #endif 45 46 #ifndef BSD_COMP 47 #define BSD_COMP 1 48 /* For Solaris */ 49 #endif 50 51 #ifndef _ALL_SOURCE 52 #define _ALL_SOURCE 1 53 /* For AIX */ 54 #endif 55 56 /** No system header may be included prior to this point since on some targets 57 ** we need to redefine FD_SETSIZE. 58 **/ 59 60 /* Target-specific includes and definitions */ 61 62 #if defined(__vxworks) 63 #include <vxWorks.h> 64 #include <ioLib.h> 65 #include <hostLib.h> 66 #define SHUT_RD 0 67 #define SHUT_WR 1 68 #define SHUT_RDWR 2 69 70 #elif defined (WINNT) 71 #define FD_SETSIZE 1024 72 73 #ifdef __MINGW32__ 74 #include <winsock2.h> 75 #include <ws2tcpip.h> 76 77 #undef EACCES 78 #define EACCES WSAEACCES 79 #undef EADDRINUSE 80 #define EADDRINUSE WSAEADDRINUSE 81 #undef EADDRNOTAVAIL 82 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL 83 #undef EAFNOSUPPORT 84 #define EAFNOSUPPORT WSAEAFNOSUPPORT 85 #undef EALREADY 86 #define EALREADY WSAEALREADY 87 #undef EBADF 88 #define EBADF WSAEBADF 89 #undef ECONNABORTED 90 #define ECONNABORTED WSAECONNABORTED 91 #undef ECONNREFUSED 92 #define ECONNREFUSED WSAECONNREFUSED 93 #undef ECONNRESET 94 #define ECONNRESET WSAECONNRESET 95 #undef EDESTADDRREQ 96 #define EDESTADDRREQ WSAEDESTADDRREQ 97 #undef EFAULT 98 #define EFAULT WSAEFAULT 99 #undef EHOSTDOWN 100 #define EHOSTDOWN WSAEHOSTDOWN 101 #undef EHOSTUNREACH 102 #define EHOSTUNREACH WSAEHOSTUNREACH 103 #undef EINPROGRESS 104 #define EINPROGRESS WSAEINPROGRESS 105 #undef EINTR 106 #define EINTR WSAEINTR 107 #undef EINVAL 108 #define EINVAL WSAEINVAL 109 #undef EIO 110 #define EIO WSAEDISCON 111 #undef EISCONN 112 #define EISCONN WSAEISCONN 113 #undef ELOOP 114 #define ELOOP WSAELOOP 115 #undef EMFILE 116 #define EMFILE WSAEMFILE 117 #undef EMSGSIZE 118 #define EMSGSIZE WSAEMSGSIZE 119 #undef ENAMETOOLONG 120 #define ENAMETOOLONG WSAENAMETOOLONG 121 #undef ENETDOWN 122 #define ENETDOWN WSAENETDOWN 123 #undef ENETRESET 124 #define ENETRESET WSAENETRESET 125 #undef ENETUNREACH 126 #define ENETUNREACH WSAENETUNREACH 127 #undef ENOBUFS 128 #define ENOBUFS WSAENOBUFS 129 #undef ENOPROTOOPT 130 #define ENOPROTOOPT WSAENOPROTOOPT 131 #undef ENOTCONN 132 #define ENOTCONN WSAENOTCONN 133 #undef ENOTSOCK 134 #define ENOTSOCK WSAENOTSOCK 135 #undef EOPNOTSUPP 136 #define EOPNOTSUPP WSAEOPNOTSUPP 137 #undef EPFNOSUPPORT 138 #define EPFNOSUPPORT WSAEPFNOSUPPORT 139 #undef EPROTONOSUPPORT 140 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT 141 #undef EPROTOTYPE 142 #define EPROTOTYPE WSAEPROTOTYPE 143 #undef ESHUTDOWN 144 #define ESHUTDOWN WSAESHUTDOWN 145 #undef ESOCKTNOSUPPORT 146 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT 147 #undef ETIMEDOUT 148 #define ETIMEDOUT WSAETIMEDOUT 149 #undef ETOOMANYREFS 150 #define ETOOMANYREFS WSAETOOMANYREFS 151 #undef EWOULDBLOCK 152 #define EWOULDBLOCK WSAEWOULDBLOCK 153 154 #define SHUT_RD SD_RECEIVE 155 #define SHUT_WR SD_SEND 156 #define SHUT_RDWR SD_BOTH 157 158 #endif 159 160 #include <windows.h> 161 162 #elif defined(VMS) 163 /* Allow a large number of fds for select. */ 164 #define FD_SETSIZE 4096 165 #ifndef IN_RTS 166 /* These DEC C headers are not available when building with GCC. Order is 167 important. */ 168 #include <time.h> 169 #include <tcp.h> 170 #include <in.h> 171 #include <ioctl.h> 172 #include <netdb.h> 173 #endif 174 175 #endif 176 177 #include <limits.h> 178 #include <errno.h> 179 180 #if defined (__vxworks) && ! defined (__RTP__) 181 #include <sys/times.h> 182 #else 183 #include <sys/time.h> 184 #endif 185 186 #if defined(__rtems__) 187 #include <unistd.h> 188 /* Required, for read(), write(), and close() */ 189 #endif 190 191 /* 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. 197 */ 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> 203 #include <netdb.h> 204 #endif 205 206 #if defined (_AIX) || defined (__FreeBSD__) || defined (__hpux__) || \ 207 defined (_WIN32) || defined (__APPLE__) 208 # define HAVE_THREAD_SAFE_GETxxxBYyyy 1 209 210 #elif defined (linux) || defined (__GLIBC__) || \ 211 (defined (sun) && defined (__SVR4) && !defined (__vxworks)) || \ 212 defined(__rtems__) 213 # define HAVE_GETxxxBYyyy_R 1 214 #endif 215 216 /* 217 * Properties of the unerlying NetDB library: 218 * Need_Netdb_Buffer __gnat_getXXXbyYYY expects a caller-supplied buffer 219 * Need_Netdb_Lock __gnat_getXXXbyYYY expects the caller to ensure 220 * mutual exclusion 221 * 222 * See "Handling of gethostbyname, gethostbyaddr, getservbyname and 223 * getservbyport" in socket.c for details. 224 */ 225 226 #if defined (HAVE_GETxxxBYyyy_R) 227 # define Need_Netdb_Buffer 1 228 # define Need_Netdb_Lock 0 229 230 #else 231 # define Need_Netdb_Buffer 0 232 # if !defined (HAVE_THREAD_SAFE_GETxxxBYyyy) 233 # define Need_Netdb_Lock 1 234 # else 235 # define Need_Netdb_Lock 0 236 # endif 237 #endif 238 239 #if defined (__FreeBSD__) || defined (__vxworks) || defined(__rtems__) 240 # define Has_Sockaddr_Len 1 241 #else 242 # define Has_Sockaddr_Len 0 243 #endif 244 245 #if !(defined (__vxworks) || defined (_WIN32) || defined (__hpux__) || defined (VMS)) 246 # define HAVE_INET_PTON 247 #endif 248 249 #endif /* defined(__nucleus__) */ 250