]> git.ipfire.org Git - thirdparty/openssl.git/blob - include/internal/sockets.h
BIO_dgram support for BIO_sendmmsg/BIO_recvmmsg
[thirdparty/openssl.git] / include / internal / sockets.h
1 /*
2 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
3 *
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
8 */
9
10 #ifndef OSSL_INTERNAL_SOCKETS_H
11 # define OSSL_INTERNAL_SOCKETS_H
12 # pragma once
13
14 # include <openssl/opensslconf.h>
15
16 # if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
17 # define NO_SYS_PARAM_H
18 # endif
19 # ifdef WIN32
20 # define NO_SYS_UN_H
21 # endif
22 # ifdef OPENSSL_SYS_VMS
23 # define NO_SYS_PARAM_H
24 # define NO_SYS_UN_H
25 # endif
26
27 # ifdef OPENSSL_NO_SOCK
28
29 # elif defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)
30 # if defined(__DJGPP__)
31 # include <sys/socket.h>
32 # include <sys/un.h>
33 # include <tcp.h>
34 # include <netdb.h>
35 # include <arpa/inet.h>
36 # include <netinet/tcp.h>
37 # elif defined(_WIN32_WCE) && _WIN32_WCE<410
38 # define getservbyname _masked_declaration_getservbyname
39 # endif
40 # if !defined(IPPROTO_IP)
41 /* winsock[2].h was included already? */
42 # include <winsock.h>
43 # endif
44 # ifdef getservbyname
45 /* this is used to be wcecompat/include/winsock_extras.h */
46 # undef getservbyname
47 struct servent *PASCAL getservbyname(const char *, const char *);
48 # endif
49
50 # ifdef _WIN64
51 /*
52 * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
53 * the value constitutes an index in per-process table of limited size
54 * and not a real pointer. And we also depend on fact that all processors
55 * Windows run on happen to be two's-complement, which allows to
56 * interchange INVALID_SOCKET and -1.
57 */
58 # define socket(d,t,p) ((int)socket(d,t,p))
59 # define accept(s,f,l) ((int)accept(s,f,l))
60 # endif
61
62 # else
63 # if defined(__APPLE__)
64 /*
65 * This must be defined before including <netinet/in6.h> to get
66 * IPV6_RECVPKTINFO
67 */
68 # define __APPLE_USE_RFC_3542
69 # endif
70
71 # ifndef NO_SYS_PARAM_H
72 # include <sys/param.h>
73 # endif
74 # ifdef OPENSSL_SYS_VXWORKS
75 # include <time.h>
76 # endif
77
78 # include <netdb.h>
79 # if defined(OPENSSL_SYS_VMS_NODECC)
80 # include <socket.h>
81 # include <in.h>
82 # include <inet.h>
83 # else
84 # include <sys/socket.h>
85 # if !defined(NO_SYS_UN_H) && defined(AF_UNIX) && !defined(OPENSSL_NO_UNIX_SOCK)
86 # include <sys/un.h>
87 # ifndef UNIX_PATH_MAX
88 # define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
89 # endif
90 # endif
91 # ifdef FILIO_H
92 # include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
93 # endif
94 # include <netinet/in.h>
95 # include <arpa/inet.h>
96 # include <netinet/tcp.h>
97 # endif
98
99 # ifdef OPENSSL_SYS_AIX
100 # include <sys/select.h>
101 # endif
102
103 # ifndef VMS
104 # include <sys/ioctl.h>
105 # else
106 # if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
107 /* ioctl is only in VMS > 7.0 and when socketshr is not used */
108 # include <sys/ioctl.h>
109 # endif
110 # include <unixio.h>
111 # if defined(TCPIP_TYPE_SOCKETSHR)
112 # include <socketshr.h>
113 # endif
114 # endif
115
116 # ifndef INVALID_SOCKET
117 # define INVALID_SOCKET (-1)
118 # endif
119 # endif
120
121 /*
122 * Some IPv6 implementations are broken, you can disable them in known
123 * bad versions.
124 */
125 # if !defined(OPENSSL_USE_IPV6)
126 # if defined(AF_INET6)
127 # define OPENSSL_USE_IPV6 1
128 # else
129 # define OPENSSL_USE_IPV6 0
130 # endif
131 # endif
132
133 /*
134 * Some platforms define AF_UNIX, but don't support it
135 */
136 # if !defined(OPENSSL_NO_UNIX_SOCK)
137 # if !defined(AF_UNIX) || defined(NO_SYS_UN_H)
138 # define OPENSSL_NO_UNIX_SOCK
139 # endif
140 # endif
141
142 # define get_last_socket_error() errno
143 # define clear_socket_error() errno=0
144
145 # if defined(OPENSSL_SYS_WINDOWS)
146 # undef get_last_socket_error
147 # undef clear_socket_error
148 # define get_last_socket_error() WSAGetLastError()
149 # define clear_socket_error() WSASetLastError(0)
150 # define readsocket(s,b,n) recv((s),(b),(n),0)
151 # define writesocket(s,b,n) send((s),(b),(n),0)
152 # elif defined(__DJGPP__)
153 # define WATT32
154 # define WATT32_NO_OLDIES
155 # define closesocket(s) close_s(s)
156 # define readsocket(s,b,n) read_s(s,b,n)
157 # define writesocket(s,b,n) send(s,b,n,0)
158 # elif defined(OPENSSL_SYS_VMS)
159 # define ioctlsocket(a,b,c) ioctl(a,b,c)
160 # define closesocket(s) close(s)
161 # define readsocket(s,b,n) recv((s),(b),(n),0)
162 # define writesocket(s,b,n) send((s),(b),(n),0)
163 # elif defined(OPENSSL_SYS_VXWORKS)
164 # define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
165 # define closesocket(s) close(s)
166 # define readsocket(s,b,n) read((s),(b),(n))
167 # define writesocket(s,b,n) write((s),(char *)(b),(n))
168 # elif defined(OPENSSL_SYS_TANDEM)
169 # if defined(OPENSSL_TANDEM_FLOSS)
170 # include <floss.h(floss_read, floss_write)>
171 # define readsocket(s,b,n) floss_read((s),(b),(n))
172 # define writesocket(s,b,n) floss_write((s),(b),(n))
173 # else
174 # define readsocket(s,b,n) read((s),(b),(n))
175 # define writesocket(s,b,n) write((s),(b),(n))
176 # endif
177 # define ioctlsocket(a,b,c) ioctl(a,b,c)
178 # define closesocket(s) close(s)
179 # else
180 # define ioctlsocket(a,b,c) ioctl(a,b,c)
181 # define closesocket(s) close(s)
182 # define readsocket(s,b,n) read((s),(b),(n))
183 # define writesocket(s,b,n) write((s),(b),(n))
184 # endif
185
186 /* also in apps/include/apps.h */
187 # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE)
188 # define openssl_fdset(a, b) FD_SET((unsigned int)(a), b)
189 # else
190 # define openssl_fdset(a, b) FD_SET(a, b)
191 # endif
192
193 #endif