sockets.h 4.3 KB

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