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