1 /* Copyright (c) 2003-2004, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2021, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
9 * \brief Define in6_addr, its members, and related types on platforms that
13 #ifndef TOR_INADDR_ST_H
14 #define TOR_INADDR_ST_H
19 #ifdef HAVE_ARPA_INET_H
20 #include <arpa/inet.h>
22 #ifdef HAVE_NETINET_IN_H
23 #include <netinet/in.h>
25 #ifdef HAVE_NETINET_IN6_H
26 #include <netinet/in6.h>
28 #ifdef HAVE_SYS_SOCKET_H
29 #include <sys/socket.h>
31 #ifdef HAVE_SYS_PARAM_H
32 #include <sys/param.h>
41 #include "lib/cc/torint.h"
45 /** Implementation of struct in6_addr for platforms that do not have it.
46 * Generally, these platforms are ones without IPv6 support, but we want to
47 * have a working in6_addr there anyway, so we can use it to parse IPv6
49 #if !defined(HAVE_STRUCT_IN6_ADDR)
54 uint16_t u6_addr16
[8];
55 uint32_t u6_addr32
[4];
57 #define s6_addr in6_u.u6_addr8
58 #define s6_addr16 in6_u.u6_addr16
59 #define s6_addr32 in6_u.u6_addr32
61 #endif /* !defined(HAVE_STRUCT_IN6_ADDR) */
64 /** Many BSD variants seem not to define these. */
65 #if defined(__APPLE__) || defined(__darwin__) || \
66 defined(__FreeBSD__) || defined(__NetBSD__) || defined(OpenBSD)
68 #define s6_addr16 __u6_addr.__u6_addr16
71 #define s6_addr32 __u6_addr.__u6_addr32
73 #endif /* defined(__APPLE__) || defined(__darwin__) || ... */
76 #ifndef HAVE_SA_FAMILY_T
77 typedef uint16_t sa_family_t
;
81 /** Apparently, MS and Solaris don't define s6_addr16 or s6_addr32; these
82 * macros get you a pointer to s6_addr32 or local equivalent. */
83 #ifdef HAVE_STRUCT_IN6_ADDR_S6_ADDR32
84 #define S6_ADDR32(x) ((uint32_t*)(x).s6_addr32)
86 #define S6_ADDR32(x) ((uint32_t*)((char*)&(x).s6_addr))
88 #ifdef HAVE_STRUCT_IN6_ADDR_S6_ADDR16
89 #define S6_ADDR16(x) ((uint16_t*)(x).s6_addr16)
91 #define S6_ADDR16(x) ((uint16_t*)((char*)&(x).s6_addr))
95 /** Implementation of struct sockaddr_in6 on platforms that do not have
96 * it. See notes on struct in6_addr. */
97 #if !defined(HAVE_STRUCT_SOCKADDR_IN6)
99 sa_family_t sin6_family
;
101 // uint32_t sin6_flowinfo;
102 struct in6_addr sin6_addr
;
103 // uint32_t sin6_scope_id;
105 #endif /* !defined(HAVE_STRUCT_SOCKADDR_IN6) */
107 #endif /* !defined(TOR_INADDR_ST_H) */