nettypes.h 1.2 KB

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