2 * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #ifndef OSSL_INTERNAL_SOCKETS_H
11 # define OSSL_INTERNAL_SOCKETS_H
14 # include <openssl/opensslconf.h>
16 # if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
17 # define NO_SYS_PARAM_H
22 # ifdef OPENSSL_SYS_VMS
23 # define NO_SYS_PARAM_H
27 # ifdef OPENSSL_NO_SOCK
29 # elif defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)
30 # if defined(__DJGPP__)
32 # define WATT32_NO_OLDIES
33 # include <sys/socket.h>
37 # include <arpa/inet.h>
38 # include <netinet/tcp.h>
39 # elif defined(_WIN32_WCE) && _WIN32_WCE<410
40 # define getservbyname _masked_declaration_getservbyname
42 # if !defined(IPPROTO_IP)
43 /* winsock[2].h was included already? */
47 /* this is used to be wcecompat/include/winsock_extras.h */
49 struct servent *PASCAL getservbyname(const char *, const char *);
54 * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
55 * the value constitutes an index in per-process table of limited size
56 * and not a real pointer. And we also depend on fact that all processors
57 * Windows run on happen to be two's-complement, which allows to
58 * interchange INVALID_SOCKET and -1.
60 # define socket(d,t,p) ((int)socket(d,t,p))
61 # define accept(s,f,l) ((int)accept(s,f,l))
64 /* Windows have other names for shutdown() reasons */
66 # define SHUT_RD SD_RECEIVE
69 # define SHUT_WR SD_SEND
72 # define SHUT_RDWR SD_BOTH
76 # if defined(__APPLE__)
78 * This must be defined before including <netinet/in6.h> to get
81 # define __APPLE_USE_RFC_3542
84 # ifndef NO_SYS_PARAM_H
85 # include <sys/param.h>
87 # ifdef OPENSSL_SYS_VXWORKS
92 # if defined(OPENSSL_SYS_VMS)
93 typedef size_t socklen_t; /* Currently appears to be missing on VMS */
95 # if defined(OPENSSL_SYS_VMS_NODECC)
100 # include <sys/socket.h>
101 # if !defined(NO_SYS_UN_H) && defined(AF_UNIX) && !defined(OPENSSL_NO_UNIX_SOCK)
103 # ifndef UNIX_PATH_MAX
104 # define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
108 # include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
110 # include <netinet/in.h>
111 # include <arpa/inet.h>
112 # include <netinet/tcp.h>
115 # ifdef OPENSSL_SYS_AIX
116 # include <sys/select.h>
119 # ifdef OPENSSL_SYS_UNIX
120 # ifndef OPENSSL_SYS_TANDEM
127 # include <sys/ioctl.h>
129 # if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
130 /* ioctl is only in VMS > 7.0 and when socketshr is not used */
131 # include <sys/ioctl.h>
134 # if defined(TCPIP_TYPE_SOCKETSHR)
135 # include <socketshr.h>
139 # ifndef INVALID_SOCKET
140 # define INVALID_SOCKET (-1)
145 * Some IPv6 implementations are broken, you can disable them in known
148 # if !defined(OPENSSL_USE_IPV6)
149 # if defined(AF_INET6)
150 # define OPENSSL_USE_IPV6 1
152 # define OPENSSL_USE_IPV6 0
157 * Some platforms define AF_UNIX, but don't support it
159 # if !defined(OPENSSL_NO_UNIX_SOCK)
160 # if !defined(AF_UNIX) || defined(NO_SYS_UN_H)
161 # define OPENSSL_NO_UNIX_SOCK
165 # define get_last_socket_error() errno
166 # define clear_socket_error() errno=0
167 # define get_last_socket_error_is_eintr() (get_last_socket_error() == EINTR)
169 # if defined(OPENSSL_SYS_WINDOWS)
170 # undef get_last_socket_error
171 # undef clear_socket_error
172 # undef get_last_socket_error_is_eintr
173 # define get_last_socket_error() WSAGetLastError()
174 # define clear_socket_error() WSASetLastError(0)
175 # define get_last_socket_error_is_eintr() (get_last_socket_error() == WSAEINTR)
176 # define readsocket(s,b,n) recv((s),(b),(n),0)
177 # define writesocket(s,b,n) send((s),(b),(n),0)
178 # elif defined(__DJGPP__)
179 # define closesocket(s) close_s(s)
180 # define readsocket(s,b,n) read_s(s,b,n)
181 # define writesocket(s,b,n) send(s,b,n,0)
182 # elif defined(OPENSSL_SYS_VMS)
183 # define ioctlsocket(a,b,c) ioctl(a,b,c)
184 # define closesocket(s) close(s)
185 # define readsocket(s,b,n) recv((s),(b),(n),0)
186 # define writesocket(s,b,n) send((s),(b),(n),0)
187 # elif defined(OPENSSL_SYS_VXWORKS)
188 # define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
189 # define closesocket(s) close(s)
190 # define readsocket(s,b,n) read((s),(b),(n))
191 # define writesocket(s,b,n) write((s),(char *)(b),(n))
192 # elif defined(OPENSSL_SYS_TANDEM)
193 # if defined(OPENSSL_TANDEM_FLOSS)
194 # include <floss.h(floss_read, floss_write)>
195 # define readsocket(s,b,n) floss_read((s),(b),(n))
196 # define writesocket(s,b,n) floss_write((s),(b),(n))
198 # define readsocket(s,b,n) read((s),(b),(n))
199 # define writesocket(s,b,n) write((s),(b),(n))
201 # define ioctlsocket(a,b,c) ioctl(a,b,c)
202 # define closesocket(s) close(s)
204 # define ioctlsocket(a,b,c) ioctl(a,b,c)
205 # define closesocket(s) close(s)
206 # define readsocket(s,b,n) read((s),(b),(n))
207 # define writesocket(s,b,n) write((s),(b),(n))
210 /* also in apps/include/apps.h */
211 # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE)
212 # define openssl_fdset(a, b) FD_SET((unsigned int)(a), b)
214 # define openssl_fdset(a, b) FD_SET(a, b)