Export/import flags for FFC params changed to seperate fields.
[openssl.git] / include / internal / sockets.h
1 /*
2  * Copyright 1995-2021 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
11 #ifndef OSSL_INTERNAL_SOCKETS_H
12 # define OSSL_INTERNAL_SOCKETS_H
13 # pragma once
14
15 # if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
16 #  define NO_SYS_PARAM_H
17 # endif
18 # ifdef WIN32
19 #  define NO_SYS_UN_H
20 # endif
21 # ifdef OPENSSL_SYS_VMS
22 #  define NO_SYS_PARAM_H
23 #  define NO_SYS_UN_H
24 # endif
25
26 # ifdef OPENSSL_NO_SOCK
27
28 # elif defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)
29 #  if defined(__DJGPP__)
30 #   include <sys/socket.h>
31 #   include <sys/un.h>
32 #   include <tcp.h>
33 #   include <netdb.h>
34 #  elif defined(_WIN32_WCE) && _WIN32_WCE<410
35 #   define getservbyname _masked_declaration_getservbyname
36 #  endif
37 #  if !defined(IPPROTO_IP)
38     /* winsock[2].h was included already? */
39 #   include <winsock.h>
40 #  endif
41 #  ifdef getservbyname
42      /* this is used to be wcecompat/include/winsock_extras.h */
43 #   undef getservbyname
44 struct servent *PASCAL getservbyname(const char *, const char *);
45 #  endif
46
47 #  ifdef _WIN64
48 /*
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.
54  */
55 #   define socket(d,t,p)   ((int)socket(d,t,p))
56 #   define accept(s,f,l)   ((int)accept(s,f,l))
57 #  endif
58
59 # else
60
61 #  ifndef NO_SYS_PARAM_H
62 #   include <sys/param.h>
63 #  endif
64 #  ifdef OPENSSL_SYS_VXWORKS
65 #   include <time.h>
66 #  endif
67
68 #  include <netdb.h>
69 #  if defined(OPENSSL_SYS_VMS_NODECC)
70 #   include <socket.h>
71 #   include <in.h>
72 #   include <inet.h>
73 #  else
74 #   include <sys/socket.h>
75 #   ifndef NO_SYS_UN_H
76 #    include <sys/un.h>
77 #    ifndef UNIX_PATH_MAX
78 #     define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
79 #    endif
80 #   endif
81 #   ifdef FILIO_H
82 #    include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
83 #   endif
84 #   include <netinet/in.h>
85 #   include <arpa/inet.h>
86 #   include <netinet/tcp.h>
87 #  endif
88
89 #  ifdef OPENSSL_SYS_AIX
90 #   include <sys/select.h>
91 #  endif
92
93 #  ifndef VMS
94 #   include <sys/ioctl.h>
95 #  else
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>
99 #   endif
100 #   include <unixio.h>
101 #   if defined(TCPIP_TYPE_SOCKETSHR)
102 #    include <socketshr.h>
103 #   endif
104 #  endif
105
106 #  ifndef INVALID_SOCKET
107 #   define INVALID_SOCKET      (-1)
108 #  endif
109 # endif
110
111 /*
112  * Some IPv6 implementations are broken, you can disable them in known
113  * bad versions.
114  */
115 # if !defined(OPENSSL_USE_IPV6)
116 #  if defined(AF_INET6)
117 #   define OPENSSL_USE_IPV6 1
118 #  else
119 #   define OPENSSL_USE_IPV6 0
120 #  endif
121 # endif
122
123 # define get_last_socket_error() errno
124 # define clear_socket_error()    errno=0
125
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__)
134 #  define WATT32
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))
154 #  else
155 #   define readsocket(s,b,n)       read((s),(b),(n))
156 #   define writesocket(s,b,n)      write((s),(b),(n))
157 #  endif
158 #  define ioctlsocket(a,b,c)      ioctl(a,b,c)
159 #  define closesocket(s)          close(s)
160 # else
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))
165 # endif
166
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)
170 # else
171 #  define openssl_fdset(a, b) FD_SET(a, b)
172 # endif
173
174 #endif