| 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-2025, 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(VTHREADS) || defined(__PikeOS__) || defined(__DJGPP__) |
| 33 |
|
| 34 |
/* 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 |
|
| 67 |
#define SHUT_RD 0 |
| 68 |
#define SHUT_WR 1 |
| 69 |
#define SHUT_RDWR 2 |
| 70 |
|
| 71 |
#ifndef IPV6_ADD_MEMBERSHIP |
| 72 |
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP |
| 73 |
#endif |
| 74 |
|
| 75 |
#ifndef IPV6_DROP_MEMBERSHIP |
| 76 |
#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP |
| 77 |
#endif |
| 78 |
|
| 79 |
#elif defined (WINNT) |
| 80 |
#define FD_SETSIZE 1024 |
| 81 |
|
| 82 |
#ifdef __MINGW32__ |
| 83 |
#include <winsock2.h> |
| 84 |
#include <ws2tcpip.h> |
| 85 |
#include <versionhelpers.h> |
| 86 |
|
| 87 |
#undef EACCES |
| 88 |
#define EACCES WSAEACCES |
| 89 |
#undef EADDRINUSE |
| 90 |
#define EADDRINUSE WSAEADDRINUSE |
| 91 |
#undef EADDRNOTAVAIL |
| 92 |
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL |
| 93 |
#undef EAFNOSUPPORT |
| 94 |
#define EAFNOSUPPORT WSAEAFNOSUPPORT |
| 95 |
#undef EALREADY |
| 96 |
#define EALREADY WSAEALREADY |
| 97 |
#undef EBADF |
| 98 |
#define EBADF WSAEBADF |
| 99 |
#undef ECONNABORTED |
| 100 |
#define ECONNABORTED WSAECONNABORTED |
| 101 |
#undef ECONNREFUSED |
| 102 |
#define ECONNREFUSED WSAECONNREFUSED |
| 103 |
#undef ECONNRESET |
| 104 |
#define ECONNRESET WSAECONNRESET |
| 105 |
#undef EDESTADDRREQ |
| 106 |
#define EDESTADDRREQ WSAEDESTADDRREQ |
| 107 |
#undef EFAULT |
| 108 |
#define EFAULT WSAEFAULT |
| 109 |
#undef EHOSTDOWN |
| 110 |
#define EHOSTDOWN WSAEHOSTDOWN |
| 111 |
#undef EHOSTUNREACH |
| 112 |
#define EHOSTUNREACH WSAEHOSTUNREACH |
| 113 |
#undef EINPROGRESS |
| 114 |
#define EINPROGRESS WSAEINPROGRESS |
| 115 |
#undef EINTR |
| 116 |
#define EINTR WSAEINTR |
| 117 |
#undef EINVAL |
| 118 |
#define EINVAL WSAEINVAL |
| 119 |
#undef EIO |
| 120 |
#define EIO WSAEDISCON |
| 121 |
#undef EISCONN |
| 122 |
#define EISCONN WSAEISCONN |
| 123 |
#undef ELOOP |
| 124 |
#define ELOOP WSAELOOP |
| 125 |
#undef EMFILE |
| 126 |
#define EMFILE WSAEMFILE |
| 127 |
#undef EMSGSIZE |
| 128 |
#define EMSGSIZE WSAEMSGSIZE |
| 129 |
#undef ENAMETOOLONG |
| 130 |
#define ENAMETOOLONG WSAENAMETOOLONG |
| 131 |
#undef ENETDOWN |
| 132 |
#define ENETDOWN WSAENETDOWN |
| 133 |
#undef ENETRESET |
| 134 |
#define ENETRESET WSAENETRESET |
| 135 |
#undef ENETUNREACH |
| 136 |
#define ENETUNREACH WSAENETUNREACH |
| 137 |
#undef ENOBUFS |
| 138 |
#define ENOBUFS WSAENOBUFS |
| 139 |
#undef ENOPROTOOPT |
| 140 |
#define ENOPROTOOPT WSAENOPROTOOPT |
| 141 |
#undef ENOTCONN |
| 142 |
#define ENOTCONN WSAENOTCONN |
| 143 |
#undef ENOTSOCK |
| 144 |
#define ENOTSOCK WSAENOTSOCK |
| 145 |
#undef EOPNOTSUPP |
| 146 |
#define EOPNOTSUPP WSAEOPNOTSUPP |
| 147 |
#undef EPFNOSUPPORT |
| 148 |
#define EPFNOSUPPORT WSAEPFNOSUPPORT |
| 149 |
#undef EPROTONOSUPPORT |
| 150 |
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT |
| 151 |
#undef EPROTOTYPE |
| 152 |
#define EPROTOTYPE WSAEPROTOTYPE |
| 153 |
#undef ESHUTDOWN |
| 154 |
#define ESHUTDOWN WSAESHUTDOWN |
| 155 |
#undef ESOCKTNOSUPPORT |
| 156 |
#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT |
| 157 |
#undef ETIMEDOUT |
| 158 |
#define ETIMEDOUT WSAETIMEDOUT |
| 159 |
#undef ETOOMANYREFS |
| 160 |
#define ETOOMANYREFS WSAETOOMANYREFS |
| 161 |
#undef EWOULDBLOCK |
| 162 |
#define EWOULDBLOCK WSAEWOULDBLOCK |
| 163 |
|
| 164 |
#define SHUT_RD SD_RECEIVE |
| 165 |
#define SHUT_WR SD_SEND |
| 166 |
#define SHUT_RDWR SD_BOTH |
| 167 |
|
| 168 |
#endif |
| 169 |
|
| 170 |
#define WIN32_LEAN_AND_MEAN |
| 171 |
#include <windows.h> |
| 172 |
|
| 173 |
#elif defined(VMS) |
| 174 |
/* Allow a large number of fds for select. */ |
| 175 |
#define FD_SETSIZE 4096 |
| 176 |
#ifndef IN_RTS |
| 177 |
/* These DEC C headers are not available when building with GCC. Order is |
| 178 |
important. */ |
| 179 |
#include <time.h> |
| 180 |
#include <tcp.h> |
| 181 |
#include <in.h> |
| 182 |
#include <ioctl.h> |
| 183 |
#include <netdb.h> |
| 184 |
#endif |
| 185 |
|
| 186 |
#endif |
| 187 |
|
| 188 |
#include <limits.h> |
| 189 |
#include <errno.h> |
| 190 |
#include <stddef.h> |
| 191 |
|
| 192 |
#if defined (__vxworks) && ! defined (__RTP__) |
| 193 |
#include <sys/times.h> |
| 194 |
#else |
| 195 |
#include <sys/time.h> |
| 196 |
#endif |
| 197 |
|
| 198 |
#if defined(__rtems__) |
| 199 |
#include <unistd.h> |
| 200 |
/* Required, for read(), write(), and close() */ |
| 201 |
#endif |
| 202 |
|
| 203 |
/* |
| 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. |
| 209 |
*/ |
| 210 |
#if !(defined (VMS) || defined (__MINGW32__)) |
| 211 |
#include <sys/socket.h> |
| 212 |
#include <sys/un.h> |
| 213 |
#include <net/if.h> |
| 214 |
#include <netinet/in.h> |
| 215 |
#include <netinet/tcp.h> |
| 216 |
#include <sys/ioctl.h> |
| 217 |
#include <netdb.h> |
| 218 |
#include <unistd.h> |
| 219 |
#endif |
| 220 |
|
| 221 |
#ifdef __ANDROID__ |
| 222 |
#include <unistd.h> |
| 223 |
#include <sys/select.h> |
| 224 |
#endif |
| 225 |
|
| 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 |
| 230 |
|
| 231 |
#elif defined (__linux__) || defined (__GLIBC__) || \ |
| 232 |
(defined (__sun__) && !defined (__vxworks)) || \ |
| 233 |
defined (__rtems__) |
| 234 |
# define HAVE_GETxxxBYyyy_R 1 |
| 235 |
#endif |
| 236 |
|
| 237 |
/* |
| 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 |
| 241 |
* mutual exclusion |
| 242 |
* |
| 243 |
* See "Handling of gethostbyname, gethostbyaddr, getservbyname and |
| 244 |
* getservbyport" in socket.c for details. |
| 245 |
*/ |
| 246 |
|
| 247 |
#if defined (HAVE_GETxxxBYyyy_R) |
| 248 |
# define Need_Netdb_Buffer 1 |
| 249 |
# define Need_Netdb_Lock 0 |
| 250 |
|
| 251 |
#else |
| 252 |
# define Need_Netdb_Buffer 0 |
| 253 |
# if !defined (HAVE_THREAD_SAFE_GETxxxBYyyy) |
| 254 |
# define Need_Netdb_Lock 1 |
| 255 |
# else |
| 256 |
# define Need_Netdb_Lock 0 |
| 257 |
# endif |
| 258 |
#endif |
| 259 |
|
| 260 |
# define Has_Sockaddr_Len (offsetof(struct sockaddr_in, sin_family) != 0) |
| 261 |
|
| 262 |
#if !(defined (_WIN32) || defined (__hpux__) || defined (VMS)) |
| 263 |
# define HAVE_INET_PTON |
| 264 |
# define HAVE_INET_NTOP |
| 265 |
#endif |
| 266 |
|
| 267 |
#endif /* defined(VTHREADS) */ |