Coverage Report

Created: 2024-01-20 12:35

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