nettypes.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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_NET_TYPES_H
  6. #define TOR_NET_TYPES_H
  7. #include "orconfig.h"
  8. #ifdef HAVE_SYS_TYPES_H
  9. #include <sys/types.h>
  10. #endif
  11. #ifdef HAVE_SYS_SOCKET_H
  12. #include <sys/socket.h>
  13. #endif
  14. #if (SIZEOF_SOCKLEN_T == 0)
  15. typedef int socklen_t;
  16. #endif
  17. #ifdef _WIN32
  18. /* XXX Actually, this should arguably be SOCKET; we use intptr_t here so that
  19. * any inadvertent checks for the socket being <= 0 or > 0 will probably
  20. * still work. */
  21. #define tor_socket_t intptr_t
  22. #define TOR_SOCKET_T_FORMAT "%"PRIuPTR
  23. #define SOCKET_OK(s) ((SOCKET)(s) != INVALID_SOCKET)
  24. #define TOR_INVALID_SOCKET INVALID_SOCKET
  25. #else /* !(defined(_WIN32)) */
  26. /** Type used for a network socket. */
  27. #define tor_socket_t int
  28. #define TOR_SOCKET_T_FORMAT "%d"
  29. /** Macro: true iff 's' is a possible value for a valid initialized socket. */
  30. #define SOCKET_OK(s) ((s) >= 0)
  31. /** Error/uninitialized value for a tor_socket_t. */
  32. #define TOR_INVALID_SOCKET (-1)
  33. #endif /* defined(_WIN32) */
  34. #endif