sockets.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright 1995-2018 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 HEADER_INTERNAL_SOCKETS
  10. # define HEADER_INTERNAL_SOCKETS
  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. # ifdef OPENSSL_SYS_VXWORKS
  67. # include <streams/un.h>
  68. # else
  69. # include <sys/un.h>
  70. # endif
  71. # ifndef UNIX_PATH_MAX
  72. # define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
  73. # endif
  74. # endif
  75. # ifdef FILIO_H
  76. # include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
  77. # endif
  78. # include <netinet/in.h>
  79. # include <arpa/inet.h>
  80. # include <netinet/tcp.h>
  81. # endif
  82. # ifdef OPENSSL_SYS_AIX
  83. # include <sys/select.h>
  84. # endif
  85. # ifndef VMS
  86. # include <sys/ioctl.h>
  87. # else
  88. # if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
  89. /* ioctl is only in VMS > 7.0 and when socketshr is not used */
  90. # include <sys/ioctl.h>
  91. # endif
  92. # include <unixio.h>
  93. # if defined(TCPIP_TYPE_SOCKETSHR)
  94. # include <socketshr.h>
  95. # endif
  96. # endif
  97. # ifndef INVALID_SOCKET
  98. # define INVALID_SOCKET (-1)
  99. # endif
  100. # endif
  101. /*
  102. * Some IPv6 implementations are broken, you can disable them in known
  103. * bad versions.
  104. */
  105. # if !defined(OPENSSL_USE_IPV6)
  106. # if defined(AF_INET6)
  107. # define OPENSSL_USE_IPV6 1
  108. # else
  109. # define OPENSSL_USE_IPV6 0
  110. # endif
  111. # endif
  112. # define get_last_socket_error() errno
  113. # define clear_socket_error() errno=0
  114. # if defined(OPENSSL_SYS_WINDOWS)
  115. # undef get_last_socket_error
  116. # undef clear_socket_error
  117. # define get_last_socket_error() WSAGetLastError()
  118. # define clear_socket_error() WSASetLastError(0)
  119. # define readsocket(s,b,n) recv((s),(b),(n),0)
  120. # define writesocket(s,b,n) send((s),(b),(n),0)
  121. # elif defined(__DJGPP__)
  122. # define WATT32
  123. # define WATT32_NO_OLDIES
  124. # define closesocket(s) close_s(s)
  125. # define readsocket(s,b,n) read_s(s,b,n)
  126. # define writesocket(s,b,n) send(s,b,n,0)
  127. # elif defined(OPENSSL_SYS_VMS)
  128. # define ioctlsocket(a,b,c) ioctl(a,b,c)
  129. # define closesocket(s) close(s)
  130. # define readsocket(s,b,n) recv((s),(b),(n),0)
  131. # define writesocket(s,b,n) send((s),(b),(n),0)
  132. # elif defined(OPENSSL_SYS_VXWORKS)
  133. # define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
  134. # define closesocket(s) close(s)
  135. # define readsocket(s,b,n) read((s),(b),(n))
  136. # define writesocket(s,b,n) write((s),(char *)(b),(n))
  137. # else
  138. # define ioctlsocket(a,b,c) ioctl(a,b,c)
  139. # define closesocket(s) close(s)
  140. # define readsocket(s,b,n) read((s),(b),(n))
  141. # define writesocket(s,b,n) write((s),(b),(n))
  142. # endif
  143. #endif