sockets.h 4.4 KB

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