inaddr_st.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 inaddr_st.h
  7. *
  8. * \brief Define in6_addr, its members, and related types on platforms that
  9. * lack it.
  10. **/
  11. #ifndef TOR_INADDR_ST_H
  12. #define TOR_INADDR_ST_H
  13. #ifdef HAVE_NETINET_IN6_H
  14. #include <netinet/in6.h>
  15. #endif
  16. #ifdef _WIN32
  17. #include <winsock2.h>
  18. #include <ws2tcpip.h>
  19. #include <windows.h>
  20. #endif
  21. #include "lib/cc/torint.h"
  22. struct in_addr;
  23. /** Implementation of struct in6_addr for platforms that do not have it.
  24. * Generally, these platforms are ones without IPv6 support, but we want to
  25. * have a working in6_addr there anyway, so we can use it to parse IPv6
  26. * addresses. */
  27. #if !defined(HAVE_STRUCT_IN6_ADDR)
  28. struct in6_addr
  29. {
  30. union {
  31. uint8_t u6_addr8[16];
  32. uint16_t u6_addr16[8];
  33. uint32_t u6_addr32[4];
  34. } in6_u;
  35. #define s6_addr in6_u.u6_addr8
  36. #define s6_addr16 in6_u.u6_addr16
  37. #define s6_addr32 in6_u.u6_addr32
  38. };
  39. #endif /* !defined(HAVE_STRUCT_IN6_ADDR) */
  40. /** @{ */
  41. /** Many BSD variants seem not to define these. */
  42. #if defined(__APPLE__) || defined(__darwin__) || \
  43. defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
  44. #ifndef s6_addr16
  45. #define s6_addr16 __u6_addr.__u6_addr16
  46. #endif
  47. #ifndef s6_addr32
  48. #define s6_addr32 __u6_addr.__u6_addr32
  49. #endif
  50. #endif /* defined(__APPLE__) || defined(__darwin__) || ... */
  51. /** @} */
  52. #ifndef HAVE_SA_FAMILY_T
  53. typedef uint16_t sa_family_t;
  54. #endif
  55. /** @{ */
  56. /** Apparently, MS and Solaris don't define s6_addr16 or s6_addr32; these
  57. * macros get you a pointer to s6_addr32 or local equivalent. */
  58. #ifdef HAVE_STRUCT_IN6_ADDR_S6_ADDR32
  59. #define S6_ADDR32(x) ((uint32_t*)(x).s6_addr32)
  60. #else
  61. #define S6_ADDR32(x) ((uint32_t*)((char*)&(x).s6_addr))
  62. #endif
  63. #ifdef HAVE_STRUCT_IN6_ADDR_S6_ADDR16
  64. #define S6_ADDR16(x) ((uint16_t*)(x).s6_addr16)
  65. #else
  66. #define S6_ADDR16(x) ((uint16_t*)((char*)&(x).s6_addr))
  67. #endif
  68. /** @} */
  69. /** Implementation of struct sockaddr_in6 on platforms that do not have
  70. * it. See notes on struct in6_addr. */
  71. #if !defined(HAVE_STRUCT_SOCKADDR_IN6)
  72. struct sockaddr_in6 {
  73. sa_family_t sin6_family;
  74. uint16_t sin6_port;
  75. // uint32_t sin6_flowinfo;
  76. struct in6_addr sin6_addr;
  77. // uint32_t sin6_scope_id;
  78. };
  79. #endif /* !defined(HAVE_STRUCT_SOCKADDR_IN6) */
  80. #endif /* TOR_INADDR_ST_H */