sockets.h 5.0 KB

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