Tor  0.4.7.0-alpha-dev
inaddr_st.h
Go to the documentation of this file.
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 */
5 
6 /**
7  * \file inaddr_st.h
8  *
9  * \brief Define in6_addr, its members, and related types on platforms that
10  * lack it.
11  **/
12 
13 #ifndef TOR_INADDR_ST_H
14 #define TOR_INADDR_ST_H
15 
16 #include "orconfig.h"
17 #include <stddef.h>
18 
19 #ifdef HAVE_ARPA_INET_H
20 #include <arpa/inet.h>
21 #endif
22 #ifdef HAVE_NETINET_IN_H
23 #include <netinet/in.h>
24 #endif
25 #ifdef HAVE_NETINET_IN6_H
26 #include <netinet/in6.h>
27 #endif
28 #ifdef HAVE_SYS_SOCKET_H
29 #include <sys/socket.h>
30 #endif
31 #ifdef HAVE_SYS_PARAM_H
32 #include <sys/param.h>
33 #endif
34 
35 #ifdef _WIN32
36 #include <winsock2.h>
37 #include <ws2tcpip.h>
38 #include <windows.h>
39 #endif
40 
41 #include "lib/cc/torint.h"
42 
43 struct in_addr;
44 
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
48  * addresses. */
49 #if !defined(HAVE_STRUCT_IN6_ADDR)
50 struct in6_addr
51 {
52  union {
53  uint8_t u6_addr8[16];
54  uint16_t u6_addr16[8];
55  uint32_t u6_addr32[4];
56  } in6_u;
57 #define s6_addr in6_u.u6_addr8
58 #define s6_addr16 in6_u.u6_addr16
59 #define s6_addr32 in6_u.u6_addr32
60 };
61 #endif /* !defined(HAVE_STRUCT_IN6_ADDR) */
62 
63 /** @{ */
64 /** Many BSD variants seem not to define these. */
65 #if defined(__APPLE__) || defined(__darwin__) || \
66  defined(__FreeBSD__) || defined(__NetBSD__) || defined(OpenBSD)
67 #ifndef s6_addr16
68 #define s6_addr16 __u6_addr.__u6_addr16
69 #endif
70 #ifndef s6_addr32
71 #define s6_addr32 __u6_addr.__u6_addr32
72 #endif
73 #endif /* defined(__APPLE__) || defined(__darwin__) || ... */
74 /** @} */
75 
76 #ifndef HAVE_SA_FAMILY_T
77 typedef uint16_t sa_family_t;
78 #endif
79 
80 /** @{ */
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)
85 #else
86 #define S6_ADDR32(x) ((uint32_t*)((char*)&(x).s6_addr))
87 #endif
88 #ifdef HAVE_STRUCT_IN6_ADDR_S6_ADDR16
89 #define S6_ADDR16(x) ((uint16_t*)(x).s6_addr16)
90 #else
91 #define S6_ADDR16(x) ((uint16_t*)((char*)&(x).s6_addr))
92 #endif
93 /** @} */
94 
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)
98 struct sockaddr_in6 {
99  sa_family_t sin6_family;
100  uint16_t sin6_port;
101  // uint32_t sin6_flowinfo;
102  struct in6_addr sin6_addr;
103  // uint32_t sin6_scope_id;
104 };
105 #endif /* !defined(HAVE_STRUCT_SOCKADDR_IN6) */
106 
107 #endif /* !defined(TOR_INADDR_ST_H) */
uint16_t sa_family_t
Definition: inaddr_st.h:77
Integer definitions used throughout Tor.