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