]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/internal/sockets.h
Copyright year updates
[thirdparty/openssl.git] / include / internal / sockets.h
CommitLineData
0e97f1e1 1/*
da1c088f 2 * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
0e97f1e1 3 *
48f4ad77 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
0e97f1e1
RS
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
ae4186b0
DMSP
10#ifndef OSSL_INTERNAL_SOCKETS_H
11# define OSSL_INTERNAL_SOCKETS_H
3a111aad 12# pragma once
0e97f1e1 13
fea55908
RL
14# include <openssl/opensslconf.h>
15
9a5d80cb
RL
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
0e97f1e1
RS
27# ifdef OPENSSL_NO_SOCK
28
29# elif defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)
9a5d80cb 30# if defined(__DJGPP__)
8ae74c5b
J
31# define WATT32
32# define WATT32_NO_OLDIES
9a5d80cb
RL
33# include <sys/socket.h>
34# include <sys/un.h>
35# include <tcp.h>
36# include <netdb.h>
b9b211fc
JMG
37# include <arpa/inet.h>
38# include <netinet/tcp.h>
9a5d80cb
RL
39# elif defined(_WIN32_WCE) && _WIN32_WCE<410
40# define getservbyname _masked_declaration_getservbyname
41# endif
42# if !defined(IPPROTO_IP)
43 /* winsock[2].h was included already? */
44# include <winsock.h>
45# endif
46# ifdef getservbyname
0e97f1e1 47 /* this is used to be wcecompat/include/winsock_extras.h */
9a5d80cb 48# undef getservbyname
0e97f1e1 49struct servent *PASCAL getservbyname(const char *, const char *);
9a5d80cb 50# endif
0e97f1e1 51
9a5d80cb 52# ifdef _WIN64
0e97f1e1
RS
53/*
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.
59 */
9a5d80cb
RL
60# define socket(d,t,p) ((int)socket(d,t,p))
61# define accept(s,f,l) ((int)accept(s,f,l))
0e97f1e1
RS
62# endif
63
4ccb89bb
RL
64/* Windows have other names for shutdown() reasons */
65# ifndef SHUT_RD
66# define SHUT_RD SD_RECEIVE
67# endif
68# ifndef SHUT_WR
69# define SHUT_WR SD_SEND
70# endif
71# ifndef SHUT_RDWR
72# define SHUT_RDWR SD_BOTH
73# endif
74
0e97f1e1 75# else
664e096c
HL
76# if defined(__APPLE__)
77 /*
78 * This must be defined before including <netinet/in6.h> to get
79 * IPV6_RECVPKTINFO
80 */
81# define __APPLE_USE_RFC_3542
82# endif
0e97f1e1
RS
83
84# ifndef NO_SYS_PARAM_H
85# include <sys/param.h>
86# endif
87# ifdef OPENSSL_SYS_VXWORKS
88# include <time.h>
89# endif
90
91# include <netdb.h>
3ae4686b
RL
92# if defined(OPENSSL_SYS_VMS)
93typedef size_t socklen_t; /* Currently appears to be missing on VMS */
94# endif
0e97f1e1
RS
95# if defined(OPENSSL_SYS_VMS_NODECC)
96# include <socket.h>
97# include <in.h>
98# include <inet.h>
99# else
100# include <sys/socket.h>
081f3484 101# if !defined(NO_SYS_UN_H) && defined(AF_UNIX) && !defined(OPENSSL_NO_UNIX_SOCK)
5c8b7b4c 102# include <sys/un.h>
0e97f1e1
RS
103# ifndef UNIX_PATH_MAX
104# define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
105# endif
106# endif
107# ifdef FILIO_H
108# include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
109# endif
110# include <netinet/in.h>
111# include <arpa/inet.h>
112# include <netinet/tcp.h>
113# endif
114
115# ifdef OPENSSL_SYS_AIX
116# include <sys/select.h>
117# endif
118
16b220dd 119# ifdef OPENSSL_SYS_UNIX
c4ce0e33 120# include <poll.h>
16b220dd
HL
121# include <errno.h>
122# endif
123
0e97f1e1
RS
124# ifndef VMS
125# include <sys/ioctl.h>
126# else
127# if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
128 /* ioctl is only in VMS > 7.0 and when socketshr is not used */
129# include <sys/ioctl.h>
130# endif
131# include <unixio.h>
132# if defined(TCPIP_TYPE_SOCKETSHR)
133# include <socketshr.h>
134# endif
135# endif
136
137# ifndef INVALID_SOCKET
138# define INVALID_SOCKET (-1)
139# endif
140# endif
141
142/*
617b49db
RS
143 * Some IPv6 implementations are broken, you can disable them in known
144 * bad versions.
0e97f1e1
RS
145 */
146# if !defined(OPENSSL_USE_IPV6)
a5a0f328
RS
147# if defined(AF_INET6)
148# define OPENSSL_USE_IPV6 1
149# else
150# define OPENSSL_USE_IPV6 0
151# endif
0e97f1e1
RS
152# endif
153
081f3484
MB
154/*
155 * Some platforms define AF_UNIX, but don't support it
156 */
157# if !defined(OPENSSL_NO_UNIX_SOCK)
158# if !defined(AF_UNIX) || defined(NO_SYS_UN_H)
159# define OPENSSL_NO_UNIX_SOCK
160# endif
161# endif
162
384cdd46
RL
163# define get_last_socket_error() errno
164# define clear_socket_error() errno=0
8c94cf38 165# define get_last_socket_error_is_eintr() (get_last_socket_error() == EINTR)
384cdd46
RL
166
167# if defined(OPENSSL_SYS_WINDOWS)
168# undef get_last_socket_error
169# undef clear_socket_error
8c94cf38 170# undef get_last_socket_error_is_eintr
384cdd46
RL
171# define get_last_socket_error() WSAGetLastError()
172# define clear_socket_error() WSASetLastError(0)
8c94cf38 173# define get_last_socket_error_is_eintr() (get_last_socket_error() == WSAEINTR)
384cdd46
RL
174# define readsocket(s,b,n) recv((s),(b),(n),0)
175# define writesocket(s,b,n) send((s),(b),(n),0)
176# elif defined(__DJGPP__)
384cdd46
RL
177# define closesocket(s) close_s(s)
178# define readsocket(s,b,n) read_s(s,b,n)
179# define writesocket(s,b,n) send(s,b,n,0)
180# elif defined(OPENSSL_SYS_VMS)
181# define ioctlsocket(a,b,c) ioctl(a,b,c)
182# define closesocket(s) close(s)
183# define readsocket(s,b,n) recv((s),(b),(n),0)
184# define writesocket(s,b,n) send((s),(b),(n),0)
185# elif defined(OPENSSL_SYS_VXWORKS)
186# define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
187# define closesocket(s) close(s)
188# define readsocket(s,b,n) read((s),(b),(n))
189# define writesocket(s,b,n) write((s),(char *)(b),(n))
cdb5129e 190# elif defined(OPENSSL_SYS_TANDEM)
08073700
RB
191# if defined(OPENSSL_TANDEM_FLOSS)
192# include <floss.h(floss_read, floss_write)>
193# define readsocket(s,b,n) floss_read((s),(b),(n))
194# define writesocket(s,b,n) floss_write((s),(b),(n))
195# else
196# define readsocket(s,b,n) read((s),(b),(n))
197# define writesocket(s,b,n) write((s),(b),(n))
198# endif
199# define ioctlsocket(a,b,c) ioctl(a,b,c)
200# define closesocket(s) close(s)
384cdd46
RL
201# else
202# define ioctlsocket(a,b,c) ioctl(a,b,c)
203# define closesocket(s) close(s)
204# define readsocket(s,b,n) read((s),(b),(n))
205# define writesocket(s,b,n) write((s),(b),(n))
206# endif
0e97f1e1 207
bcbb30af
DDO
208/* also in apps/include/apps.h */
209# if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE)
8c10e1b6 210# define openssl_fdset(a, b) FD_SET((unsigned int)(a), b)
bcbb30af 211# else
8c10e1b6 212# define openssl_fdset(a, b) FD_SET(a, b)
bcbb30af
DDO
213# endif
214
0e97f1e1 215#endif