inaddr_st.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Copyright (c) 2003-2004, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2019, 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. #include "orconfig.h"
  14. #include <stddef.h>
  15. #ifdef HAVE_ARPA_INET_H
  16. #include <arpa/inet.h>
  17. #endif
  18. #ifdef HAVE_NETINET_IN_H
  19. #include <netinet/in.h>
  20. #endif
  21. #ifdef HAVE_NETINET_IN6_H
  22. #include <netinet/in6.h>
  23. #endif
  24. #ifdef HAVE_SYS_SOCKET_H
  25. #include <sys/socket.h>
  26. #endif
  27. #ifdef HAVE_SYS_PARAM_H
  28. #include <sys/param.h>
  29. #endif
  30. #ifdef _WIN32
  31. #include <winsock2.h>
  32. #include <ws2tcpip.h>
  33. #include <windows.h>
  34. #endif
  35. #include "lib/cc/torint.h"
  36. struct in_addr;
  37. /** Implementation of struct in6_addr for platforms that do not have it.
  38. * Generally, these platforms are ones without IPv6 support, but we want to
  39. * have a working in6_addr there anyway, so we can use it to parse IPv6
  40. * addresses. */
  41. #if !defined(HAVE_STRUCT_IN6_ADDR)
  42. struct in6_addr
  43. {
  44. union {
  45. uint8_t u6_addr8[16];
  46. uint16_t u6_addr16[8];
  47. uint32_t u6_addr32[4];
  48. } in6_u;
  49. #define s6_addr in6_u.u6_addr8
  50. #define s6_addr16 in6_u.u6_addr16
  51. #define s6_addr32 in6_u.u6_addr32
  52. };
  53. #endif /* !defined(HAVE_STRUCT_IN6_ADDR) */
  54. /** @{ */
  55. /** Many BSD variants seem not to define these. */
  56. #if defined(__APPLE__) || defined(__darwin__) || \
  57. defined(__FreeBSD__) || defined(__NetBSD__) || defined(OpenBSD)
  58. #ifndef s6_addr16
  59. #define s6_addr16 __u6_addr.__u6_addr16
  60. #endif
  61. #ifndef s6_addr32
  62. #define s6_addr32 __u6_addr.__u6_addr32
  63. #endif
  64. #endif /* defined(__APPLE__) || defined(__darwin__) || ... */
  65. /** @} */
  66. #ifndef HAVE_SA_FAMILY_T
  67. typedef uint16_t sa_family_t;
  68. #endif
  69. /** @{ */
  70. /** Apparently, MS and Solaris don't define s6_addr16 or s6_addr32; these
  71. * macros get you a pointer to s6_addr32 or local equivalent. */
  72. #ifdef HAVE_STRUCT_IN6_ADDR_S6_ADDR32
  73. #define S6_ADDR32(x) ((uint32_t*)(x).s6_addr32)
  74. #else
  75. #define S6_ADDR32(x) ((uint32_t*)((char*)&(x).s6_addr))
  76. #endif
  77. #ifdef HAVE_STRUCT_IN6_ADDR_S6_ADDR16
  78. #define S6_ADDR16(x) ((uint16_t*)(x).s6_addr16)
  79. #else
  80. #define S6_ADDR16(x) ((uint16_t*)((char*)&(x).s6_addr))
  81. #endif
  82. /** @} */
  83. /** Implementation of struct sockaddr_in6 on platforms that do not have
  84. * it. See notes on struct in6_addr. */
  85. #if !defined(HAVE_STRUCT_SOCKADDR_IN6)
  86. struct sockaddr_in6 {
  87. sa_family_t sin6_family;
  88. uint16_t sin6_port;
  89. // uint32_t sin6_flowinfo;
  90. struct in6_addr sin6_addr;
  91. // uint32_t sin6_scope_id;
  92. };
  93. #endif /* !defined(HAVE_STRUCT_SOCKADDR_IN6) */
  94. #endif /* TOR_INADDR_ST_H */