113d40330Schristos /* 2d3425df3Schristos * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved. 313d40330Schristos * 4*b0d17251Schristos * Licensed under the Apache License 2.0 (the "License"). You may not use 513d40330Schristos * this file except in compliance with the License. You can obtain a copy 613d40330Schristos * in the file LICENSE in the source distribution or at 713d40330Schristos * https://www.openssl.org/source/license.html 813d40330Schristos */ 913d40330Schristos 107d004720Schristos #ifndef OSSL_INTERNAL_SOCKETS_H 117d004720Schristos # define OSSL_INTERNAL_SOCKETS_H 12*b0d17251Schristos # pragma once 13*b0d17251Schristos 14*b0d17251Schristos # include <openssl/opensslconf.h> 1513d40330Schristos 1613d40330Schristos # if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI) 1713d40330Schristos # define NO_SYS_PARAM_H 1813d40330Schristos # endif 1913d40330Schristos # ifdef WIN32 2013d40330Schristos # define NO_SYS_UN_H 2113d40330Schristos # endif 2213d40330Schristos # ifdef OPENSSL_SYS_VMS 2313d40330Schristos # define NO_SYS_PARAM_H 2413d40330Schristos # define NO_SYS_UN_H 2513d40330Schristos # endif 2613d40330Schristos 2713d40330Schristos # ifdef OPENSSL_NO_SOCK 2813d40330Schristos 2913d40330Schristos # elif defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) 3013d40330Schristos # if defined(__DJGPP__) 31*b0d17251Schristos # define WATT32 32*b0d17251Schristos # define WATT32_NO_OLDIES 3313d40330Schristos # include <sys/socket.h> 3413d40330Schristos # include <sys/un.h> 3513d40330Schristos # include <tcp.h> 3613d40330Schristos # include <netdb.h> 37d3425df3Schristos # include <arpa/inet.h> 38d3425df3Schristos # include <netinet/tcp.h> 3913d40330Schristos # elif defined(_WIN32_WCE) && _WIN32_WCE<410 4013d40330Schristos # define getservbyname _masked_declaration_getservbyname 4113d40330Schristos # endif 4213d40330Schristos # if !defined(IPPROTO_IP) 4313d40330Schristos /* winsock[2].h was included already? */ 4413d40330Schristos # include <winsock.h> 4513d40330Schristos # endif 4613d40330Schristos # ifdef getservbyname 4713d40330Schristos /* this is used to be wcecompat/include/winsock_extras.h */ 4813d40330Schristos # undef getservbyname 4913d40330Schristos struct servent *PASCAL getservbyname(const char *, const char *); 5013d40330Schristos # endif 5113d40330Schristos 5213d40330Schristos # ifdef _WIN64 5313d40330Schristos /* 5413d40330Schristos * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because 5513d40330Schristos * the value constitutes an index in per-process table of limited size 5613d40330Schristos * and not a real pointer. And we also depend on fact that all processors 5713d40330Schristos * Windows run on happen to be two's-complement, which allows to 5813d40330Schristos * interchange INVALID_SOCKET and -1. 5913d40330Schristos */ 6013d40330Schristos # define socket(d,t,p) ((int)socket(d,t,p)) 6113d40330Schristos # define accept(s,f,l) ((int)accept(s,f,l)) 6213d40330Schristos # endif 6313d40330Schristos 6413d40330Schristos # else 6513d40330Schristos 6613d40330Schristos # ifndef NO_SYS_PARAM_H 6713d40330Schristos # include <sys/param.h> 6813d40330Schristos # endif 6913d40330Schristos # ifdef OPENSSL_SYS_VXWORKS 7013d40330Schristos # include <time.h> 7113d40330Schristos # endif 7213d40330Schristos 7313d40330Schristos # include <netdb.h> 7413d40330Schristos # if defined(OPENSSL_SYS_VMS_NODECC) 7513d40330Schristos # include <socket.h> 7613d40330Schristos # include <in.h> 7713d40330Schristos # include <inet.h> 7813d40330Schristos # else 7913d40330Schristos # include <sys/socket.h> 8013d40330Schristos # ifndef NO_SYS_UN_H 8113d40330Schristos # include <sys/un.h> 8213d40330Schristos # ifndef UNIX_PATH_MAX 8313d40330Schristos # define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path) 8413d40330Schristos # endif 8513d40330Schristos # endif 8613d40330Schristos # ifdef FILIO_H 8713d40330Schristos # include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */ 8813d40330Schristos # endif 8913d40330Schristos # include <netinet/in.h> 9013d40330Schristos # include <arpa/inet.h> 9113d40330Schristos # include <netinet/tcp.h> 9213d40330Schristos # endif 9313d40330Schristos 9413d40330Schristos # ifdef OPENSSL_SYS_AIX 9513d40330Schristos # include <sys/select.h> 9613d40330Schristos # endif 9713d40330Schristos 9813d40330Schristos # ifndef VMS 9913d40330Schristos # include <sys/ioctl.h> 10013d40330Schristos # else 10113d40330Schristos # if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000) 10213d40330Schristos /* ioctl is only in VMS > 7.0 and when socketshr is not used */ 10313d40330Schristos # include <sys/ioctl.h> 10413d40330Schristos # endif 10513d40330Schristos # include <unixio.h> 10613d40330Schristos # if defined(TCPIP_TYPE_SOCKETSHR) 10713d40330Schristos # include <socketshr.h> 10813d40330Schristos # endif 10913d40330Schristos # endif 11013d40330Schristos 11113d40330Schristos # ifndef INVALID_SOCKET 11213d40330Schristos # define INVALID_SOCKET (-1) 11313d40330Schristos # endif 11413d40330Schristos # endif 11513d40330Schristos 11613d40330Schristos /* 11713d40330Schristos * Some IPv6 implementations are broken, you can disable them in known 11813d40330Schristos * bad versions. 11913d40330Schristos */ 12013d40330Schristos # if !defined(OPENSSL_USE_IPV6) 12113d40330Schristos # if defined(AF_INET6) 12213d40330Schristos # define OPENSSL_USE_IPV6 1 12313d40330Schristos # else 12413d40330Schristos # define OPENSSL_USE_IPV6 0 12513d40330Schristos # endif 12613d40330Schristos # endif 12713d40330Schristos 12813d40330Schristos # define get_last_socket_error() errno 12913d40330Schristos # define clear_socket_error() errno=0 13013d40330Schristos 13113d40330Schristos # if defined(OPENSSL_SYS_WINDOWS) 13213d40330Schristos # undef get_last_socket_error 13313d40330Schristos # undef clear_socket_error 13413d40330Schristos # define get_last_socket_error() WSAGetLastError() 13513d40330Schristos # define clear_socket_error() WSASetLastError(0) 13613d40330Schristos # define readsocket(s,b,n) recv((s),(b),(n),0) 13713d40330Schristos # define writesocket(s,b,n) send((s),(b),(n),0) 13813d40330Schristos # elif defined(__DJGPP__) 13913d40330Schristos # define closesocket(s) close_s(s) 14013d40330Schristos # define readsocket(s,b,n) read_s(s,b,n) 14113d40330Schristos # define writesocket(s,b,n) send(s,b,n,0) 14213d40330Schristos # elif defined(OPENSSL_SYS_VMS) 14313d40330Schristos # define ioctlsocket(a,b,c) ioctl(a,b,c) 14413d40330Schristos # define closesocket(s) close(s) 14513d40330Schristos # define readsocket(s,b,n) recv((s),(b),(n),0) 14613d40330Schristos # define writesocket(s,b,n) send((s),(b),(n),0) 14713d40330Schristos # elif defined(OPENSSL_SYS_VXWORKS) 14813d40330Schristos # define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c)) 14913d40330Schristos # define closesocket(s) close(s) 15013d40330Schristos # define readsocket(s,b,n) read((s),(b),(n)) 15113d40330Schristos # define writesocket(s,b,n) write((s),(char *)(b),(n)) 152*b0d17251Schristos # elif defined(OPENSSL_SYS_TANDEM) 153*b0d17251Schristos # if defined(OPENSSL_TANDEM_FLOSS) 154*b0d17251Schristos # include <floss.h(floss_read, floss_write)> 155*b0d17251Schristos # define readsocket(s,b,n) floss_read((s),(b),(n)) 156*b0d17251Schristos # define writesocket(s,b,n) floss_write((s),(b),(n)) 157*b0d17251Schristos # else 158*b0d17251Schristos # define readsocket(s,b,n) read((s),(b),(n)) 159*b0d17251Schristos # define writesocket(s,b,n) write((s),(b),(n)) 160*b0d17251Schristos # endif 161*b0d17251Schristos # define ioctlsocket(a,b,c) ioctl(a,b,c) 162*b0d17251Schristos # define closesocket(s) close(s) 16313d40330Schristos # else 16413d40330Schristos # define ioctlsocket(a,b,c) ioctl(a,b,c) 16513d40330Schristos # define closesocket(s) close(s) 16613d40330Schristos # define readsocket(s,b,n) read((s),(b),(n)) 16713d40330Schristos # define writesocket(s,b,n) write((s),(b),(n)) 16813d40330Schristos # endif 16913d40330Schristos 170*b0d17251Schristos /* also in apps/include/apps.h */ 171*b0d17251Schristos # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINCE) 172*b0d17251Schristos # define openssl_fdset(a, b) FD_SET((unsigned int)(a), b) 173*b0d17251Schristos # else 174*b0d17251Schristos # define openssl_fdset(a, b) FD_SET(a, b) 175*b0d17251Schristos # endif 176*b0d17251Schristos 17713d40330Schristos #endif 178