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