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