sockets.h 4.9 KB

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