compat.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Copyright (c) 2003-2004, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #ifndef TOR_COMPAT_H
  6. #define TOR_COMPAT_H
  7. #include "orconfig.h"
  8. #ifdef _WIN32
  9. #include <winsock2.h>
  10. #include <ws2tcpip.h>
  11. #ifndef SIO_IDEAL_SEND_BACKLOG_QUERY
  12. #define SIO_IDEAL_SEND_BACKLOG_QUERY 0x4004747b
  13. #endif
  14. #endif
  15. #include "lib/cc/torint.h"
  16. #include "lib/testsupport/testsupport.h"
  17. #ifdef HAVE_SYS_PARAM_H
  18. #include <sys/param.h>
  19. #endif
  20. #ifdef HAVE_SYS_TYPES_H
  21. #include <sys/types.h>
  22. #endif
  23. #ifdef HAVE_SYS_TIME_H
  24. #include <sys/time.h>
  25. #endif
  26. #ifdef HAVE_TIME_H
  27. #include <time.h>
  28. #endif
  29. #ifdef HAVE_STRING_H
  30. #include <string.h>
  31. #endif
  32. #include <stdarg.h>
  33. #ifdef HAVE_SYS_RESOURCE_H
  34. #include <sys/resource.h>
  35. #endif
  36. #ifdef HAVE_SYS_SOCKET_H
  37. #include <sys/socket.h>
  38. #endif
  39. #ifdef HAVE_NETINET_IN_H
  40. #include <netinet/in.h>
  41. #endif
  42. #ifdef HAVE_NETINET6_IN6_H
  43. #include <netinet6/in6.h>
  44. #endif
  45. #include "lib/cc/compat_compiler.h"
  46. #include "lib/arch/bytes.h"
  47. #include "common/compat_time.h"
  48. #include "lib/string/compat_ctype.h"
  49. #include "lib/string/compat_string.h"
  50. #include "lib/string/printf.h"
  51. #include "lib/log/win32err.h"
  52. #include "lib/net/socket.h"
  53. #include "lib/net/ipv4.h"
  54. #include "lib/net/ipv6.h"
  55. #include "lib/net/resolve.h"
  56. #include "lib/fs/files.h"
  57. #include "lib/fs/mmap.h"
  58. #include "lib/fs/userdb.h"
  59. #include "lib/wallclock/timeval.h"
  60. #include <stdio.h>
  61. #include <errno.h>
  62. /* ===== Time compatibility */
  63. /* ===== File compatibility */
  64. /* ===== Net compatibility */
  65. /** Specified SOCKS5 status codes. */
  66. typedef enum {
  67. SOCKS5_SUCCEEDED = 0x00,
  68. SOCKS5_GENERAL_ERROR = 0x01,
  69. SOCKS5_NOT_ALLOWED = 0x02,
  70. SOCKS5_NET_UNREACHABLE = 0x03,
  71. SOCKS5_HOST_UNREACHABLE = 0x04,
  72. SOCKS5_CONNECTION_REFUSED = 0x05,
  73. SOCKS5_TTL_EXPIRED = 0x06,
  74. SOCKS5_COMMAND_NOT_SUPPORTED = 0x07,
  75. SOCKS5_ADDRESS_TYPE_NOT_SUPPORTED = 0x08,
  76. } socks5_reply_status_t;
  77. /* ===== OS compatibility */
  78. MOCK_DECL(const char *, get_uname, (void));
  79. #if !defined(HAVE_RLIM_T)
  80. typedef unsigned long rlim_t;
  81. #endif
  82. int set_max_file_descriptors(rlim_t limit, int *max);
  83. MOCK_DECL(int, get_total_system_memory, (size_t *mem_out));
  84. /** Macros for MIN/MAX. Never use these when the arguments could have
  85. * side-effects.
  86. * {With GCC extensions we could probably define a safer MIN/MAX. But
  87. * depending on that safety would be dangerous, since not every platform
  88. * has it.}
  89. **/
  90. #ifndef MAX
  91. #define MAX(a,b) ( ((a)<(b)) ? (b) : (a) )
  92. #endif
  93. #ifndef MIN
  94. #define MIN(a,b) ( ((a)>(b)) ? (b) : (a) )
  95. #endif
  96. /*for some reason my compiler doesn't have these version flags defined
  97. a nice homework assignment for someone one day is to define the rest*/
  98. //these are the values as given on MSDN
  99. #ifdef _WIN32
  100. #ifndef VER_SUITE_EMBEDDEDNT
  101. #define VER_SUITE_EMBEDDEDNT 0x00000040
  102. #endif
  103. #ifndef VER_SUITE_SINGLEUSERTS
  104. #define VER_SUITE_SINGLEUSERTS 0x00000100
  105. #endif
  106. #endif /* defined(_WIN32) */
  107. ssize_t tor_getpass(const char *prompt, char *output, size_t buflen);
  108. /* This needs some of the declarations above so we include it here. */
  109. #include "lib/thread/threads.h"
  110. #endif /* !defined(TOR_COMPAT_H) */