2 * Copyright 1995-2021 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__)
31 # include <sys/socket.h>
35 # elif defined(_WIN32_WCE) && _WIN32_WCE<410
36 # define getservbyname _masked_declaration_getservbyname
38 # if !defined(IPPROTO_IP)
39 /* winsock[2].h was included already? */
43 /* this is used to be wcecompat/include/winsock_extras.h */
45 struct servent *PASCAL getservbyname(const char *, const char *);
50 * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
51 * the value constitutes an index in per-process table of limited size
52 * and not a real pointer. And we also depend on fact that all processors
53 * Windows run on happen to be two's-complement, which allows to
54 * interchange INVALID_SOCKET and -1.
56 # define socket(d,t,p) ((int)socket(d,t,p))
57 # define accept(s,f,l) ((int)accept(s,f,l))
62 # ifndef NO_SYS_PARAM_H
63 # include <sys/param.h>
65 # ifdef OPENSSL_SYS_VXWORKS
70 # if defined(OPENSSL_SYS_VMS_NODECC)
75 # include <sys/socket.h>
78 # ifndef UNIX_PATH_MAX
79 # define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
83 # include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
85 # include <netinet/in.h>
86 # include <arpa/inet.h>
87 # include <netinet/tcp.h>
90 # ifdef OPENSSL_SYS_AIX
91 # include <sys/select.h>
95 # include <sys/ioctl.h>
97 # if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
98 /* ioctl is only in VMS > 7.0 and when socketshr is not used */
99 # include <sys/ioctl.h>
102 # if defined(TCPIP_TYPE_SOCKETSHR)
103 # include <socketshr.h>
107 # ifndef INVALID_SOCKET
108 # define INVALID_SOCKET (-1)
113 * Some IPv6 implementations are broken, you can disable them in known
116 # if !defined(OPENSSL_USE_IPV6)
117 # if defined(AF_INET6)
118 # define OPENSSL_USE_IPV6 1
120 # define OPENSSL_USE_IPV6 0
124 # define get_last_socket_error() errno
125 # define clear_socket_error() errno=0
127 # if defined(OPENSSL_SYS_WINDOWS)
128 # undef get_last_socket_error
129 # undef clear_socket_error
130 # define get_last_socket_error() WSAGetLastError()
131 # define clear_socket_error() WSASetLastError(0)
132 # define readsocket(s,b,n) recv((s),(b),(n),0)
133 # define writesocket(s,b,n) send((s),(b),(n),0)
134 # elif defined(__DJGPP__)
136 # define WATT32_NO_OLDIES
137 # define closesocket(s) close_s(s)
138 # define readsocket(s,b,n) read_s(s,b,n)
139 # define writesocket(s,b,n) send(s,b,n,0)
140 # elif defined(OPENSSL_SYS_VMS)
141 # define ioctlsocket(a,b,c) ioctl(a,b,c)
142 # define closesocket(s) close(s)
143 # define readsocket(s,b,n) recv((s),(b),(n),0)
144 # define writesocket(s,b,n) send((s),(b),(n),0)
145 # elif defined(OPENSSL_SYS_VXWORKS)
146 # define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
147 # define closesocket(s) close(s)
148 # define readsocket(s,b,n) read((s),(b),(n))
149 # define writesocket(s,b,n) write((s),(char *)(b),(n))
150 # elif defined(OPENSSL_SYS_TANDEM)
151 # if defined(OPENSSL_TANDEM_FLOSS)
152 # include <floss.h(floss_read, floss_write)>
153 # define readsocket(s,b,n) floss_read((s),(b),(n))
154 # define writesocket(s,b,n) floss_write((s),(b),(n))
156 # define readsocket(s,b,n) read((s),(b),(n))
157 # define writesocket(s,b,n) write((s),(b),(n))
159 # define ioctlsocket(a,b,c) ioctl(a,b,c)
160 # define closesocket(s) close(s)
162 # define ioctlsocket(a,b,c) ioctl(a,b,c)
163 # define closesocket(s) close(s)
164 # define readsocket(s,b,n) read((s),(b),(n))
165 # define writesocket(s,b,n) write((s),(b),(n))
168 /* also in apps/include/apps.h */
169 # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE)
170 # define openssl_fdset(a, b) FD_SET((unsigned int)(a), b)
172 # define openssl_fdset(a, b) FD_SET(a, b)