]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/internal/sockets.h
BIO_dgram support for BIO_sendmmsg/BIO_recvmmsg
[thirdparty/openssl.git] / include / internal / sockets.h
CommitLineData
0e97f1e1 1/*
fecb3aae 2 * Copyright 1995-2022 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
RL
30# if defined(__DJGPP__)
31# include <sys/socket.h>
32# include <sys/un.h>
33# include <tcp.h>
34# include <netdb.h>
b9b211fc
JMG
35# include <arpa/inet.h>
36# include <netinet/tcp.h>
9a5d80cb
RL
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
0e97f1e1 45 /* this is used to be wcecompat/include/winsock_extras.h */
9a5d80cb 46# undef getservbyname
0e97f1e1 47struct servent *PASCAL getservbyname(const char *, const char *);
9a5d80cb 48# endif
0e97f1e1 49
9a5d80cb 50# ifdef _WIN64
0e97f1e1
RS
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 */
9a5d80cb
RL
58# define socket(d,t,p) ((int)socket(d,t,p))
59# define accept(s,f,l) ((int)accept(s,f,l))
0e97f1e1
RS
60# endif
61
62# else
664e096c
HL
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
0e97f1e1
RS
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>
081f3484 85# if !defined(NO_SYS_UN_H) && defined(AF_UNIX) && !defined(OPENSSL_NO_UNIX_SOCK)
5c8b7b4c 86# include <sys/un.h>
0e97f1e1
RS
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
0e97f1e1
RS
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/*
617b49db
RS
122 * Some IPv6 implementations are broken, you can disable them in known
123 * bad versions.
0e97f1e1
RS
124 */
125# if !defined(OPENSSL_USE_IPV6)
a5a0f328
RS
126# if defined(AF_INET6)
127# define OPENSSL_USE_IPV6 1
128# else
129# define OPENSSL_USE_IPV6 0
130# endif
0e97f1e1
RS
131# endif
132
081f3484
MB
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
384cdd46
RL
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))
cdb5129e 168# elif defined(OPENSSL_SYS_TANDEM)
08073700
RB
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)
384cdd46
RL
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
0e97f1e1 185
bcbb30af
DDO
186/* also in apps/include/apps.h */
187# if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE)
8c10e1b6 188# define openssl_fdset(a, b) FD_SET((unsigned int)(a), b)
bcbb30af 189# else
8c10e1b6 190# define openssl_fdset(a, b) FD_SET(a, b)
bcbb30af
DDO
191# endif
192
0e97f1e1 193#endif