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
11 #ifndef OSSL_INTERNAL_SOCKETS_H
12 # define OSSL_INTERNAL_SOCKETS_H
15 # if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
16 # define NO_SYS_PARAM_H
21 # ifdef OPENSSL_SYS_VMS
22 # define NO_SYS_PARAM_H
26 # ifdef OPENSSL_NO_SOCK
28 # elif defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)
29 # if defined(__DJGPP__)
30 # include <sys/socket.h>
34 # elif defined(_WIN32_WCE) && _WIN32_WCE<410
35 # define getservbyname _masked_declaration_getservbyname
37 # if !defined(IPPROTO_IP)
38 /* winsock[2].h was included already? */
42 /* this is used to be wcecompat/include/winsock_extras.h */
44 struct servent *PASCAL getservbyname(const char *, const char *);
49 * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
50 * the value constitutes an index in per-process table of limited size
51 * and not a real pointer. And we also depend on fact that all processors
52 * Windows run on happen to be two's-complement, which allows to
53 * interchange INVALID_SOCKET and -1.
55 # define socket(d,t,p) ((int)socket(d,t,p))
56 # define accept(s,f,l) ((int)accept(s,f,l))
61 # ifndef NO_SYS_PARAM_H
62 # include <sys/param.h>
64 # ifdef OPENSSL_SYS_VXWORKS
69 # if defined(OPENSSL_SYS_VMS_NODECC)
74 # include <sys/socket.h>
77 # ifndef UNIX_PATH_MAX
78 # define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
82 # include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
84 # include <netinet/in.h>
85 # include <arpa/inet.h>
86 # include <netinet/tcp.h>
89 # ifdef OPENSSL_SYS_AIX
90 # include <sys/select.h>
94 # include <sys/ioctl.h>
96 # if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
97 /* ioctl is only in VMS > 7.0 and when socketshr is not used */
98 # include <sys/ioctl.h>
101 # if defined(TCPIP_TYPE_SOCKETSHR)
102 # include <socketshr.h>
106 # ifndef INVALID_SOCKET
107 # define INVALID_SOCKET (-1)
112 * Some IPv6 implementations are broken, you can disable them in known
115 # if !defined(OPENSSL_USE_IPV6)
116 # if defined(AF_INET6)
117 # define OPENSSL_USE_IPV6 1
119 # define OPENSSL_USE_IPV6 0
123 # define get_last_socket_error() errno
124 # define clear_socket_error() errno=0
126 # if defined(OPENSSL_SYS_WINDOWS)
127 # undef get_last_socket_error
128 # undef clear_socket_error
129 # define get_last_socket_error() WSAGetLastError()
130 # define clear_socket_error() WSASetLastError(0)
131 # define readsocket(s,b,n) recv((s),(b),(n),0)
132 # define writesocket(s,b,n) send((s),(b),(n),0)
133 # elif defined(__DJGPP__)
135 # define WATT32_NO_OLDIES
136 # define closesocket(s) close_s(s)
137 # define readsocket(s,b,n) read_s(s,b,n)
138 # define writesocket(s,b,n) send(s,b,n,0)
139 # elif defined(OPENSSL_SYS_VMS)
140 # define ioctlsocket(a,b,c) ioctl(a,b,c)
141 # define closesocket(s) close(s)
142 # define readsocket(s,b,n) recv((s),(b),(n),0)
143 # define writesocket(s,b,n) send((s),(b),(n),0)
144 # elif defined(OPENSSL_SYS_VXWORKS)
145 # define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
146 # define closesocket(s) close(s)
147 # define readsocket(s,b,n) read((s),(b),(n))
148 # define writesocket(s,b,n) write((s),(char *)(b),(n))
149 # elif defined(OPENSSL_SYS_TANDEM)
150 # if defined(OPENSSL_TANDEM_FLOSS)
151 # include <floss.h(floss_read, floss_write)>
152 # define readsocket(s,b,n) floss_read((s),(b),(n))
153 # define writesocket(s,b,n) floss_write((s),(b),(n))
155 # define readsocket(s,b,n) read((s),(b),(n))
156 # define writesocket(s,b,n) write((s),(b),(n))
158 # define ioctlsocket(a,b,c) ioctl(a,b,c)
159 # define closesocket(s) close(s)
161 # define ioctlsocket(a,b,c) ioctl(a,b,c)
162 # define closesocket(s) close(s)
163 # define readsocket(s,b,n) read((s),(b),(n))
164 # define writesocket(s,b,n) write((s),(b),(n))
167 /* also in apps/include/apps.h */
168 # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE)
169 # define openssl_fdset(a, b) FD_SET((unsigned int)(a), b)
171 # define openssl_fdset(a, b) FD_SET(a, b)