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