InetAddress.hpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2024-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #ifndef ZT_INETADDRESS_HPP
  14. #define ZT_INETADDRESS_HPP
  15. #include <cstdlib>
  16. #include <cstring>
  17. #include <cstdint>
  18. #include "Constants.hpp"
  19. #include "Utils.hpp"
  20. #include "MAC.hpp"
  21. #include "TriviallyCopyable.hpp"
  22. namespace ZeroTier {
  23. #define ZT_INETADDRESS_MARSHAL_SIZE_MAX 19
  24. #define ZT_INETADDRESS_STRING_SIZE_MAX 64
  25. /**
  26. * Extends sockaddr_storage with friendly C++ methods
  27. *
  28. * This is basically a "mixin" for sockaddr_storage. It adds methods and
  29. * operators, but does not modify the structure. This can be cast to/from
  30. * sockaddr_storage and used interchangeably. DO NOT change this by e.g.
  31. * adding non-static fields, since much code depends on this identity.
  32. */
  33. struct InetAddress : public sockaddr_storage,public TriviallyCopyable
  34. {
  35. private:
  36. // Internal function to copy any sockaddr_X structure to this one even if it's smaller and unpadded.
  37. template<typename SA>
  38. ZT_ALWAYS_INLINE void copySockaddrToThis(const SA *sa) noexcept
  39. {
  40. memcpy(reinterpret_cast<void *>(this),sa,sizeof(SA));
  41. if (sizeof(SA) < sizeof(InetAddress))
  42. memset(reinterpret_cast<uint8_t *>(this) + sizeof(SA),0,sizeof(InetAddress) - sizeof(SA));
  43. }
  44. public:
  45. /**
  46. * Loopback IPv4 address (no port)
  47. */
  48. static const InetAddress LO4;
  49. /**
  50. * Loopback IPV6 address (no port)
  51. */
  52. static const InetAddress LO6;
  53. /**
  54. * Null address
  55. */
  56. static const InetAddress NIL;
  57. /**
  58. * IP address scope
  59. *
  60. * Note that these values are in ascending order of path preference and
  61. * MUST remain that way or Path must be changed to reflect. Also be sure
  62. * to change ZT_INETADDRESS_MAX_SCOPE if the max changes.
  63. */
  64. enum IpScope
  65. {
  66. IP_SCOPE_NONE = 0, // NULL or not an IP address
  67. IP_SCOPE_MULTICAST = 1, // 224.0.0.0 and other V4/V6 multicast IPs
  68. IP_SCOPE_LOOPBACK = 2, // 127.0.0.1, ::1, etc.
  69. IP_SCOPE_PSEUDOPRIVATE = 3, // 28.x.x.x, etc. -- unofficially unrouted IPv4 blocks often "bogarted"
  70. IP_SCOPE_GLOBAL = 4, // globally routable IP address (all others)
  71. IP_SCOPE_LINK_LOCAL = 5, // 169.254.x.x, IPv6 LL
  72. IP_SCOPE_SHARED = 6, // currently unused, formerly used for carrier-grade NAT ranges
  73. IP_SCOPE_PRIVATE = 7 // 10.x.x.x, 192.168.x.x, etc.
  74. };
  75. // Hasher for unordered sets and maps in C++11
  76. struct Hasher { ZT_ALWAYS_INLINE std::size_t operator()(const InetAddress &a) const noexcept { return (std::size_t)a.hashCode(); } };
  77. ZT_ALWAYS_INLINE InetAddress() noexcept { memoryZero(this); }
  78. ZT_ALWAYS_INLINE InetAddress(const InetAddress &a) noexcept { memoryCopy(this,&a); }
  79. explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr_storage &ss) noexcept { *this = ss; }
  80. explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr_storage *ss) noexcept { *this = ss; }
  81. explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr &sa) noexcept { *this = sa; }
  82. explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr *sa) noexcept { *this = sa; }
  83. explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr_in &sa) noexcept { *this = sa; }
  84. explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr_in *sa) noexcept { *this = sa; }
  85. explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr_in6 &sa) noexcept { *this = sa; }
  86. explicit ZT_ALWAYS_INLINE InetAddress(const sockaddr_in6 *sa) noexcept { *this = sa; }
  87. ZT_ALWAYS_INLINE InetAddress(const void *ipBytes,unsigned int ipLen,unsigned int port) noexcept { this->set(ipBytes,ipLen,port); }
  88. ZT_ALWAYS_INLINE InetAddress(const uint32_t ipv4,unsigned int port) noexcept { this->set(&ipv4,4,port); }
  89. explicit ZT_ALWAYS_INLINE InetAddress(const char *ipSlashPort) noexcept { this->fromString(ipSlashPort); }
  90. ZT_ALWAYS_INLINE void clear() noexcept { memoryZero(this); }
  91. ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr_storage &ss) noexcept
  92. {
  93. memoryCopyUnsafe(this,&ss);
  94. return *this;
  95. }
  96. ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr_storage *ss) noexcept
  97. {
  98. if (ss)
  99. memoryCopyUnsafe(this,ss);
  100. else memoryZero(this);
  101. return *this;
  102. }
  103. ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr_in &sa) noexcept
  104. {
  105. copySockaddrToThis(&sa);
  106. return *this;
  107. }
  108. ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr_in *sa) noexcept
  109. {
  110. if (sa)
  111. copySockaddrToThis(sa);
  112. else memset(reinterpret_cast<void *>(this),0,sizeof(InetAddress));
  113. return *this;
  114. }
  115. ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr_in6 &sa) noexcept
  116. {
  117. copySockaddrToThis(&sa);
  118. return *this;
  119. }
  120. ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr_in6 *sa) noexcept
  121. {
  122. if (sa)
  123. copySockaddrToThis(sa);
  124. else memset(reinterpret_cast<void *>(this),0,sizeof(InetAddress));
  125. return *this;
  126. }
  127. ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr &sa) noexcept
  128. {
  129. if (sa.sa_family == AF_INET)
  130. copySockaddrToThis(reinterpret_cast<const sockaddr_in *>(&sa));
  131. else if (sa.sa_family == AF_INET6)
  132. copySockaddrToThis(reinterpret_cast<const sockaddr_in6 *>(&sa));
  133. else memset(reinterpret_cast<void *>(this),0,sizeof(InetAddress));
  134. return *this;
  135. }
  136. ZT_ALWAYS_INLINE InetAddress &operator=(const sockaddr *sa) noexcept
  137. {
  138. if (sa) {
  139. if (sa->sa_family == AF_INET)
  140. copySockaddrToThis(reinterpret_cast<const sockaddr_in *>(sa));
  141. else if (sa->sa_family == AF_INET6)
  142. copySockaddrToThis(reinterpret_cast<const sockaddr_in6 *>(sa));
  143. else memoryZero(this);
  144. } else {
  145. memoryZero(this);
  146. }
  147. return *this;
  148. }
  149. /**
  150. * @return IP scope classification (e.g. loopback, link-local, private, global)
  151. */
  152. IpScope ipScope() const noexcept;
  153. /**
  154. * Set from a raw IP and port number
  155. *
  156. * @param ipBytes Bytes of IP address in network byte order
  157. * @param ipLen Length of IP address: 4 or 16
  158. * @param port Port number or 0 for none
  159. */
  160. void set(const void *ipBytes,unsigned int ipLen,unsigned int port) noexcept;
  161. /**
  162. * Set the port component
  163. *
  164. * @param port Port, 0 to 65535
  165. */
  166. ZT_ALWAYS_INLINE void setPort(unsigned int port) noexcept
  167. {
  168. switch(ss_family) {
  169. case AF_INET:
  170. reinterpret_cast<struct sockaddr_in *>(this)->sin_port = Utils::hton((uint16_t)port);
  171. break;
  172. case AF_INET6:
  173. reinterpret_cast<struct sockaddr_in6 *>(this)->sin6_port = Utils::hton((uint16_t)port);
  174. break;
  175. }
  176. }
  177. /**
  178. * @return True if this network/netmask route describes a default route (e.g. 0.0.0.0/0)
  179. */
  180. bool isDefaultRoute() const noexcept;
  181. /**
  182. * @return ASCII IP/port format representation
  183. */
  184. char *toString(char buf[ZT_INETADDRESS_STRING_SIZE_MAX]) const noexcept;
  185. /**
  186. * @return IP portion only, in ASCII string format
  187. */
  188. char *toIpString(char buf[ZT_INETADDRESS_STRING_SIZE_MAX]) const noexcept;
  189. /**
  190. * @param ipSlashPort IP/port (port is optional, will be 0 if not included)
  191. * @return True if address appeared to be valid
  192. */
  193. bool fromString(const char *ipSlashPort) noexcept;
  194. /**
  195. * @return Port or 0 if no port component defined
  196. */
  197. ZT_ALWAYS_INLINE unsigned int port() const noexcept
  198. {
  199. switch(ss_family) {
  200. case AF_INET: return Utils::ntoh((uint16_t)(reinterpret_cast<const struct sockaddr_in *>(this)->sin_port));
  201. case AF_INET6: return Utils::ntoh((uint16_t)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port));
  202. default: return 0;
  203. }
  204. }
  205. /**
  206. * Alias for port()
  207. *
  208. * This just aliases port() to make code more readable when netmask bits
  209. * are stuffed there, as they are in Network, EthernetTap, and a few other
  210. * spots.
  211. *
  212. * @return Netmask bits
  213. */
  214. ZT_ALWAYS_INLINE unsigned int netmaskBits() const noexcept { return port(); }
  215. /**
  216. * @return True if netmask bits is valid for the address type
  217. */
  218. ZT_ALWAYS_INLINE bool netmaskBitsValid() const noexcept
  219. {
  220. const unsigned int n = port();
  221. switch(ss_family) {
  222. case AF_INET: return (n <= 32);
  223. case AF_INET6: return (n <= 128);
  224. }
  225. return false;
  226. }
  227. /**
  228. * Alias for port()
  229. *
  230. * This just aliases port() because for gateways we use this field to
  231. * store the gateway metric.
  232. *
  233. * @return Gateway metric
  234. */
  235. ZT_ALWAYS_INLINE unsigned int metric() const noexcept { return port(); }
  236. /**
  237. * Construct a full netmask as an InetAddress
  238. *
  239. * @return Netmask such as 255.255.255.0 if this address is /24 (port field will be unchanged)
  240. */
  241. InetAddress netmask() const noexcept;
  242. /**
  243. * Constructs a broadcast address from a network/netmask address
  244. *
  245. * This is only valid for IPv4 and will return a NULL InetAddress for other
  246. * address families.
  247. *
  248. * @return Broadcast address (only IP portion is meaningful)
  249. */
  250. InetAddress broadcast() const noexcept;
  251. /**
  252. * Return the network -- a.k.a. the IP ANDed with the netmask
  253. *
  254. * @return Network e.g. 10.0.1.0/24 from 10.0.1.200/24
  255. */
  256. InetAddress network() const noexcept;
  257. /**
  258. * Test whether this IPv6 prefix matches the prefix of a given IPv6 address
  259. *
  260. * @param addr Address to check
  261. * @return True if this IPv6 prefix matches the prefix of a given IPv6 address
  262. */
  263. bool isEqualPrefix(const InetAddress &addr) const noexcept;
  264. /**
  265. * Test whether this IP/netmask contains this address
  266. *
  267. * @param addr Address to check
  268. * @return True if this IP/netmask (route) contains this address
  269. */
  270. bool containsAddress(const InetAddress &addr) const noexcept;
  271. /**
  272. * @return True if this is an IPv4 address
  273. */
  274. ZT_ALWAYS_INLINE bool isV4() const noexcept { return (ss_family == AF_INET); }
  275. /**
  276. * @return True if this is an IPv6 address
  277. */
  278. ZT_ALWAYS_INLINE bool isV6() const noexcept { return (ss_family == AF_INET6); }
  279. /**
  280. * @return pointer to raw address bytes or NULL if not available
  281. */
  282. ZT_ALWAYS_INLINE const void *rawIpData() const noexcept
  283. {
  284. switch(ss_family) {
  285. case AF_INET: return (const void *)&(reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr);
  286. case AF_INET6: return (const void *)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
  287. default: return nullptr;
  288. }
  289. }
  290. /**
  291. * @return InetAddress containing only the IP portion of this address and a zero port, or NULL if not IPv4 or IPv6
  292. */
  293. ZT_ALWAYS_INLINE InetAddress ipOnly() const noexcept
  294. {
  295. InetAddress r;
  296. switch(ss_family) {
  297. case AF_INET:
  298. r.ss_family = AF_INET;
  299. reinterpret_cast<struct sockaddr_in *>(&r)->sin_addr.s_addr = reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr;
  300. break;
  301. case AF_INET6:
  302. r.ss_family = AF_INET6;
  303. memcpy(reinterpret_cast<struct sockaddr_in6 *>(&r)->sin6_addr.s6_addr,reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,16);
  304. break;
  305. }
  306. return r;
  307. }
  308. /**
  309. * Performs an IP-only comparison or, if that is impossible, a memcmp()
  310. *
  311. * @param a InetAddress to compare again
  312. * @return True if only IP portions are equal (false for non-IP or null addresses)
  313. */
  314. ZT_ALWAYS_INLINE bool ipsEqual(const InetAddress &a) const noexcept
  315. {
  316. if (ss_family == a.ss_family) {
  317. if (ss_family == AF_INET)
  318. return (reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr == reinterpret_cast<const struct sockaddr_in *>(&a)->sin_addr.s_addr);
  319. if (ss_family == AF_INET6)
  320. return (memcmp(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,reinterpret_cast<const struct sockaddr_in6 *>(&a)->sin6_addr.s6_addr,16) == 0);
  321. return (memcmp(this,&a,sizeof(InetAddress)) == 0);
  322. }
  323. return false;
  324. }
  325. /**
  326. * Performs an IP-only comparison or, if that is impossible, a memcmp()
  327. *
  328. * This version compares only the first 64 bits of IPv6 addresses.
  329. *
  330. * @param a InetAddress to compare again
  331. * @return True if only IP portions are equal (false for non-IP or null addresses)
  332. */
  333. ZT_ALWAYS_INLINE bool ipsEqual2(const InetAddress &a) const noexcept
  334. {
  335. if (ss_family == a.ss_family) {
  336. if (ss_family == AF_INET)
  337. return (reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr == reinterpret_cast<const struct sockaddr_in *>(&a)->sin_addr.s_addr);
  338. if (ss_family == AF_INET6)
  339. return (memcmp(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,reinterpret_cast<const struct sockaddr_in6 *>(&a)->sin6_addr.s6_addr,8) == 0);
  340. return (memcmp(this,&a,sizeof(InetAddress)) == 0);
  341. }
  342. return false;
  343. }
  344. unsigned long hashCode() const noexcept;
  345. /**
  346. * Fill out a ZT_TraceEventPathAddress from this InetAddress
  347. *
  348. * @param ta ZT_TraceEventPathAddress to fill
  349. */
  350. void forTrace(ZT_TraceEventPathAddress &ta) const noexcept;
  351. /**
  352. * Check whether this is a network/route rather than an IP assignment
  353. *
  354. * A network is an IP/netmask where everything after the netmask is
  355. * zero e.g. 10.0.0.0/8.
  356. *
  357. * @return True if everything after netmask bits is zero
  358. */
  359. bool isNetwork() const noexcept;
  360. /**
  361. * @return True if address family is non-zero
  362. */
  363. explicit ZT_ALWAYS_INLINE operator bool() const noexcept { return (ss_family != 0); }
  364. static constexpr int marshalSizeMax() noexcept { return ZT_INETADDRESS_MARSHAL_SIZE_MAX; }
  365. int marshal(uint8_t data[ZT_INETADDRESS_MARSHAL_SIZE_MAX]) const noexcept;
  366. int unmarshal(const uint8_t *restrict data,int len) noexcept;
  367. bool operator==(const InetAddress &a) const noexcept;
  368. bool operator<(const InetAddress &a) const noexcept;
  369. ZT_ALWAYS_INLINE bool operator!=(const InetAddress &a) const noexcept { return !(*this == a); }
  370. ZT_ALWAYS_INLINE bool operator>(const InetAddress &a) const noexcept { return (a < *this); }
  371. ZT_ALWAYS_INLINE bool operator<=(const InetAddress &a) const noexcept { return !(a < *this); }
  372. ZT_ALWAYS_INLINE bool operator>=(const InetAddress &a) const noexcept { return !(*this < a); }
  373. /**
  374. * Compute an IPv6 link-local address
  375. *
  376. * @param mac MAC address seed
  377. * @return IPv6 link-local address
  378. */
  379. static InetAddress makeIpv6LinkLocal(const MAC &mac) noexcept;
  380. /**
  381. * Compute private IPv6 unicast address from network ID and ZeroTier address
  382. *
  383. * This generates a private unicast IPv6 address that is mostly compliant
  384. * with the letter of RFC4193 and certainly compliant in spirit.
  385. *
  386. * RFC4193 specifies a format of:
  387. *
  388. * | 7 bits |1| 40 bits | 16 bits | 64 bits |
  389. * | Prefix |L| Global ID | Subnet ID | Interface ID |
  390. *
  391. * The 'L' bit is set to 1, yielding an address beginning with 0xfd. Then
  392. * the network ID is filled into the global ID, subnet ID, and first byte
  393. * of the "interface ID" field. Since the first 40 bits of the network ID
  394. * is the unique ZeroTier address of its controller, this makes a very
  395. * good random global ID. Since network IDs have 24 more bits, we let it
  396. * overflow into the interface ID.
  397. *
  398. * After that we pad with two bytes: 0x99, 0x93, namely the default ZeroTier
  399. * port in hex.
  400. *
  401. * Finally we fill the remaining 40 bits of the interface ID field with
  402. * the 40-bit unique ZeroTier device ID of the network member.
  403. *
  404. * This yields a valid RFC4193 address with a random global ID, a
  405. * meaningful subnet ID, and a unique interface ID, all mappable back onto
  406. * ZeroTier space.
  407. *
  408. * This in turn could allow us, on networks numbered this way, to emulate
  409. * IPv6 NDP and eliminate all multicast. This could be beneficial for
  410. * small devices and huge networks, e.g. IoT applications.
  411. *
  412. * The returned address is given an odd prefix length of /88, since within
  413. * a given network only the last 40 bits (device ID) are variable. This
  414. * is a bit unusual but as far as we know should not cause any problems with
  415. * any non-braindead IPv6 stack.
  416. *
  417. * @param nwid 64-bit network ID
  418. * @param zeroTierAddress 40-bit device address (in least significant 40 bits, highest 24 bits ignored)
  419. * @return IPv6 private unicast address with /88 netmask
  420. */
  421. static InetAddress makeIpv6rfc4193(uint64_t nwid,uint64_t zeroTierAddress) noexcept;
  422. /**
  423. * Compute a private IPv6 "6plane" unicast address from network ID and ZeroTier address
  424. */
  425. static InetAddress makeIpv66plane(uint64_t nwid,uint64_t zeroTierAddress) noexcept;
  426. };
  427. static ZT_ALWAYS_INLINE InetAddress *asInetAddress(sockaddr_in *p) noexcept { return reinterpret_cast<InetAddress *>(p); }
  428. static ZT_ALWAYS_INLINE InetAddress *asInetAddress(sockaddr_in6 *p) noexcept { return reinterpret_cast<InetAddress *>(p); }
  429. static ZT_ALWAYS_INLINE InetAddress *asInetAddress(sockaddr *p) noexcept { return reinterpret_cast<InetAddress *>(p); }
  430. static ZT_ALWAYS_INLINE InetAddress *asInetAddress(sockaddr_storage *p) noexcept { return reinterpret_cast<InetAddress *>(p); }
  431. static ZT_ALWAYS_INLINE const InetAddress *asInetAddress(const sockaddr_in *p) noexcept { return reinterpret_cast<const InetAddress *>(p); }
  432. static ZT_ALWAYS_INLINE const InetAddress *asInetAddress(const sockaddr_in6 *p) noexcept { return reinterpret_cast<const InetAddress *>(p); }
  433. static ZT_ALWAYS_INLINE const InetAddress *asInetAddress(const sockaddr *p) noexcept { return reinterpret_cast<const InetAddress *>(p); }
  434. static ZT_ALWAYS_INLINE const InetAddress *asInetAddress(const sockaddr_storage *p) noexcept { return reinterpret_cast<const InetAddress *>(p); }
  435. static ZT_ALWAYS_INLINE InetAddress &asInetAddress(sockaddr_in &p) noexcept { return *reinterpret_cast<InetAddress *>(&p); }
  436. static ZT_ALWAYS_INLINE InetAddress &asInetAddress(sockaddr_in6 &p) noexcept { return *reinterpret_cast<InetAddress *>(&p); }
  437. static ZT_ALWAYS_INLINE InetAddress &asInetAddress(sockaddr &p) noexcept { return *reinterpret_cast<InetAddress *>(&p); }
  438. static ZT_ALWAYS_INLINE InetAddress &asInetAddress(sockaddr_storage &p) noexcept { return *reinterpret_cast<InetAddress *>(&p); }
  439. static ZT_ALWAYS_INLINE const InetAddress &asInetAddress(const sockaddr_in &p) noexcept { return *reinterpret_cast<const InetAddress *>(&p); }
  440. static ZT_ALWAYS_INLINE const InetAddress &asInetAddress(const sockaddr_in6 &p) noexcept { return *reinterpret_cast<const InetAddress *>(&p); }
  441. static ZT_ALWAYS_INLINE const InetAddress &asInetAddress(const sockaddr &p) noexcept { return *reinterpret_cast<const InetAddress *>(&p); }
  442. static ZT_ALWAYS_INLINE const InetAddress &asInetAddress(const sockaddr_storage &p) noexcept { return *reinterpret_cast<const InetAddress *>(&p); }
  443. } // namespace ZeroTier
  444. #endif