Dash Core  0.12.2.1
P2P Digital Currency
netaddress.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifdef HAVE_CONFIG_H
7 #include "config/dash-config.h"
8 #endif
9 
10 #include "netaddress.h"
11 #include "hash.h"
12 #include "utilstrencodings.h"
13 #include "tinyformat.h"
14 
15 static const unsigned char pchIPv4[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff };
16 static const unsigned char pchOnionCat[] = {0xFD,0x87,0xD8,0x7E,0xEB,0x43};
17 
19 {
20  memset(ip, 0, sizeof(ip));
21 }
22 
23 void CNetAddr::SetIP(const CNetAddr& ipIn)
24 {
25  memcpy(ip, ipIn.ip, sizeof(ip));
26 }
27 
28 void CNetAddr::SetRaw(Network network, const uint8_t *ip_in)
29 {
30  switch(network)
31  {
32  case NET_IPV4:
33  memcpy(ip, pchIPv4, 12);
34  memcpy(ip+12, ip_in, 4);
35  break;
36  case NET_IPV6:
37  memcpy(ip, ip_in, 16);
38  break;
39  default:
40  assert(!"invalid network");
41  }
42 }
43 
44 bool CNetAddr::SetSpecial(const std::string &strName)
45 {
46  if (strName.size()>6 && strName.substr(strName.size() - 6, 6) == ".onion") {
47  std::vector<unsigned char> vchAddr = DecodeBase32(strName.substr(0, strName.size() - 6).c_str());
48  if (vchAddr.size() != 16-sizeof(pchOnionCat))
49  return false;
50  memcpy(ip, pchOnionCat, sizeof(pchOnionCat));
51  for (unsigned int i=0; i<16-sizeof(pchOnionCat); i++)
52  ip[i + sizeof(pchOnionCat)] = vchAddr[i];
53  return true;
54  }
55  return false;
56 }
57 
59 {
60  Init();
61 }
62 
63 CNetAddr::CNetAddr(const struct in_addr& ipv4Addr)
64 {
65  SetRaw(NET_IPV4, (const uint8_t*)&ipv4Addr);
66 }
67 
68 CNetAddr::CNetAddr(const struct in6_addr& ipv6Addr)
69 {
70  SetRaw(NET_IPV6, (const uint8_t*)&ipv6Addr);
71 }
72 
73 unsigned int CNetAddr::GetByte(int n) const
74 {
75  return ip[15-n];
76 }
77 
78 bool CNetAddr::IsIPv4() const
79 {
80  return (memcmp(ip, pchIPv4, sizeof(pchIPv4)) == 0);
81 }
82 
83 bool CNetAddr::IsIPv6() const
84 {
85  return (!IsIPv4() && !IsTor());
86 }
87 
88 bool CNetAddr::IsRFC1918() const
89 {
90  return IsIPv4() && (
91  GetByte(3) == 10 ||
92  (GetByte(3) == 192 && GetByte(2) == 168) ||
93  (GetByte(3) == 172 && (GetByte(2) >= 16 && GetByte(2) <= 31)));
94 }
95 
96 bool CNetAddr::IsRFC2544() const
97 {
98  return IsIPv4() && GetByte(3) == 198 && (GetByte(2) == 18 || GetByte(2) == 19);
99 }
100 
102 {
103  return IsIPv4() && (GetByte(3) == 169 && GetByte(2) == 254);
104 }
105 
107 {
108  return IsIPv4() && GetByte(3) == 100 && GetByte(2) >= 64 && GetByte(2) <= 127;
109 }
110 
112 {
113  return IsIPv4() && ((GetByte(3) == 192 && GetByte(2) == 0 && GetByte(1) == 2) ||
114  (GetByte(3) == 198 && GetByte(2) == 51 && GetByte(1) == 100) ||
115  (GetByte(3) == 203 && GetByte(2) == 0 && GetByte(1) == 113));
116 }
117 
119 {
120  return GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0x0D && GetByte(12) == 0xB8;
121 }
122 
124 {
125  return (GetByte(15) == 0x20 && GetByte(14) == 0x02);
126 }
127 
129 {
130  static const unsigned char pchRFC6052[] = {0,0x64,0xFF,0x9B,0,0,0,0,0,0,0,0};
131  return (memcmp(ip, pchRFC6052, sizeof(pchRFC6052)) == 0);
132 }
133 
135 {
136  return (GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0 && GetByte(12) == 0);
137 }
138 
140 {
141  static const unsigned char pchRFC4862[] = {0xFE,0x80,0,0,0,0,0,0};
142  return (memcmp(ip, pchRFC4862, sizeof(pchRFC4862)) == 0);
143 }
144 
146 {
147  return ((GetByte(15) & 0xFE) == 0xFC);
148 }
149 
151 {
152  static const unsigned char pchRFC6145[] = {0,0,0,0,0,0,0,0,0xFF,0xFF,0,0};
153  return (memcmp(ip, pchRFC6145, sizeof(pchRFC6145)) == 0);
154 }
155 
157 {
158  return (GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0x00 && (GetByte(12) & 0xF0) == 0x10);
159 }
160 
161 bool CNetAddr::IsTor() const
162 {
163  return (memcmp(ip, pchOnionCat, sizeof(pchOnionCat)) == 0);
164 }
165 
166 bool CNetAddr::IsLocal() const
167 {
168  // IPv4 loopback
169  if (IsIPv4() && (GetByte(3) == 127 || GetByte(3) == 0))
170  return true;
171 
172  // IPv6 loopback (::1/128)
173  static const unsigned char pchLocal[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
174  if (memcmp(ip, pchLocal, 16) == 0)
175  return true;
176 
177  return false;
178 }
179 
181 {
182  return (IsIPv4() && (GetByte(3) & 0xF0) == 0xE0)
183  || (GetByte(15) == 0xFF);
184 }
185 
186 bool CNetAddr::IsValid() const
187 {
188  // Cleanup 3-byte shifted addresses caused by garbage in size field
189  // of addr messages from versions before 0.2.9 checksum.
190  // Two consecutive addr messages look like this:
191  // header20 vectorlen3 addr26 addr26 addr26 header20 vectorlen3 addr26 addr26 addr26...
192  // so if the first length field is garbled, it reads the second batch
193  // of addr misaligned by 3 bytes.
194  if (memcmp(ip, pchIPv4+3, sizeof(pchIPv4)-3) == 0)
195  return false;
196 
197  // unspecified IPv6 address (::/128)
198  unsigned char ipNone[16] = {};
199  if (memcmp(ip, ipNone, 16) == 0)
200  return false;
201 
202  // documentation IPv6 address
203  if (IsRFC3849())
204  return false;
205 
206  if (IsIPv4())
207  {
208  // INADDR_NONE
209  uint32_t ipNone = INADDR_NONE;
210  if (memcmp(ip+12, &ipNone, 4) == 0)
211  return false;
212 
213  // 0
214  ipNone = 0;
215  if (memcmp(ip+12, &ipNone, 4) == 0)
216  return false;
217  }
218 
219  return true;
220 }
221 
223 {
224  return IsValid() && !(IsRFC1918() || IsRFC2544() || IsRFC3927() || IsRFC4862() || IsRFC6598() || IsRFC5737() || (IsRFC4193() && !IsTor()) || IsRFC4843() || IsLocal());
225 }
226 
228 {
229  if (!IsRoutable())
230  return NET_UNROUTABLE;
231 
232  if (IsIPv4())
233  return NET_IPV4;
234 
235  if (IsTor())
236  return NET_TOR;
237 
238  return NET_IPV6;
239 }
240 
241 std::string CNetAddr::ToStringIP(bool fUseGetnameinfo) const
242 {
243  if (IsTor())
244  return EncodeBase32(&ip[6], 10) + ".onion";
245  if (fUseGetnameinfo)
246  {
247  CService serv(*this, 0);
248  struct sockaddr_storage sockaddr;
249  socklen_t socklen = sizeof(sockaddr);
250  if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) {
251  char name[1025] = "";
252  if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name, sizeof(name), NULL, 0, NI_NUMERICHOST))
253  return std::string(name);
254  }
255  }
256  if (IsIPv4())
257  return strprintf("%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0));
258  else
259  return strprintf("%x:%x:%x:%x:%x:%x:%x:%x",
260  GetByte(15) << 8 | GetByte(14), GetByte(13) << 8 | GetByte(12),
261  GetByte(11) << 8 | GetByte(10), GetByte(9) << 8 | GetByte(8),
262  GetByte(7) << 8 | GetByte(6), GetByte(5) << 8 | GetByte(4),
263  GetByte(3) << 8 | GetByte(2), GetByte(1) << 8 | GetByte(0));
264 }
265 
266 std::string CNetAddr::ToString() const
267 {
268  return ToStringIP();
269 }
270 
271 bool operator==(const CNetAddr& a, const CNetAddr& b)
272 {
273  return (memcmp(a.ip, b.ip, 16) == 0);
274 }
275 
276 bool operator!=(const CNetAddr& a, const CNetAddr& b)
277 {
278  return (memcmp(a.ip, b.ip, 16) != 0);
279 }
280 
281 bool operator<(const CNetAddr& a, const CNetAddr& b)
282 {
283  return (memcmp(a.ip, b.ip, 16) < 0);
284 }
285 
286 bool CNetAddr::GetInAddr(struct in_addr* pipv4Addr) const
287 {
288  if (!IsIPv4())
289  return false;
290  memcpy(pipv4Addr, ip+12, 4);
291  return true;
292 }
293 
294 bool CNetAddr::GetIn6Addr(struct in6_addr* pipv6Addr) const
295 {
296  memcpy(pipv6Addr, ip, 16);
297  return true;
298 }
299 
300 // get canonical identifier of an address' group
301 // no two connections will be attempted to addresses with the same group
302 std::vector<unsigned char> CNetAddr::GetGroup() const
303 {
304  std::vector<unsigned char> vchRet;
305  int nClass = NET_IPV6;
306  int nStartByte = 0;
307  int nBits = 16;
308 
309  // all local addresses belong to the same group
310  if (IsLocal())
311  {
312  nClass = 255;
313  nBits = 0;
314  }
315 
316  // all unroutable addresses belong to the same group
317  if (!IsRoutable())
318  {
319  nClass = NET_UNROUTABLE;
320  nBits = 0;
321  }
322  // for IPv4 addresses, '1' + the 16 higher-order bits of the IP
323  // includes mapped IPv4, SIIT translated IPv4, and the well-known prefix
324  else if (IsIPv4() || IsRFC6145() || IsRFC6052())
325  {
326  nClass = NET_IPV4;
327  nStartByte = 12;
328  }
329  // for 6to4 tunnelled addresses, use the encapsulated IPv4 address
330  else if (IsRFC3964())
331  {
332  nClass = NET_IPV4;
333  nStartByte = 2;
334  }
335  // for Teredo-tunnelled IPv6 addresses, use the encapsulated IPv4 address
336  else if (IsRFC4380())
337  {
338  vchRet.push_back(NET_IPV4);
339  vchRet.push_back(GetByte(3) ^ 0xFF);
340  vchRet.push_back(GetByte(2) ^ 0xFF);
341  return vchRet;
342  }
343  else if (IsTor())
344  {
345  nClass = NET_TOR;
346  nStartByte = 6;
347  nBits = 4;
348  }
349  // for he.net, use /36 groups
350  else if (GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0x04 && GetByte(12) == 0x70)
351  nBits = 36;
352  // for the rest of the IPv6 network, use /32 groups
353  else
354  nBits = 32;
355 
356  vchRet.push_back(nClass);
357  while (nBits >= 8)
358  {
359  vchRet.push_back(GetByte(15 - nStartByte));
360  nStartByte++;
361  nBits -= 8;
362  }
363  if (nBits > 0)
364  vchRet.push_back(GetByte(15 - nStartByte) | ((1 << (8 - nBits)) - 1));
365 
366  return vchRet;
367 }
368 
369 uint64_t CNetAddr::GetHash() const
370 {
371  uint256 hash = Hash(&ip[0], &ip[16]);
372  uint64_t nRet;
373  memcpy(&nRet, &hash, sizeof(nRet));
374  return nRet;
375 }
376 
377 // private extensions to enum Network, only returned by GetExtNetwork,
378 // and only used in GetReachabilityFrom
379 static const int NET_UNKNOWN = NET_MAX + 0;
380 static const int NET_TEREDO = NET_MAX + 1;
381 int static GetExtNetwork(const CNetAddr *addr)
382 {
383  if (addr == NULL)
384  return NET_UNKNOWN;
385  if (addr->IsRFC4380())
386  return NET_TEREDO;
387  return addr->GetNetwork();
388 }
389 
391 int CNetAddr::GetReachabilityFrom(const CNetAddr *paddrPartner) const
392 {
393  enum Reachability {
394  REACH_UNREACHABLE,
395  REACH_DEFAULT,
396  REACH_TEREDO,
397  REACH_IPV6_WEAK,
398  REACH_IPV4,
399  REACH_IPV6_STRONG,
400  REACH_PRIVATE
401  };
402 
403  if (!IsRoutable())
404  return REACH_UNREACHABLE;
405 
406  int ourNet = GetExtNetwork(this);
407  int theirNet = GetExtNetwork(paddrPartner);
408  bool fTunnel = IsRFC3964() || IsRFC6052() || IsRFC6145();
409 
410  switch(theirNet) {
411  case NET_IPV4:
412  switch(ourNet) {
413  default: return REACH_DEFAULT;
414  case NET_IPV4: return REACH_IPV4;
415  }
416  case NET_IPV6:
417  switch(ourNet) {
418  default: return REACH_DEFAULT;
419  case NET_TEREDO: return REACH_TEREDO;
420  case NET_IPV4: return REACH_IPV4;
421  case NET_IPV6: return fTunnel ? REACH_IPV6_WEAK : REACH_IPV6_STRONG; // only prefer giving our IPv6 address if it's not tunnelled
422  }
423  case NET_TOR:
424  switch(ourNet) {
425  default: return REACH_DEFAULT;
426  case NET_IPV4: return REACH_IPV4; // Tor users can connect to IPv4 as well
427  case NET_TOR: return REACH_PRIVATE;
428  }
429  case NET_TEREDO:
430  switch(ourNet) {
431  default: return REACH_DEFAULT;
432  case NET_TEREDO: return REACH_TEREDO;
433  case NET_IPV6: return REACH_IPV6_WEAK;
434  case NET_IPV4: return REACH_IPV4;
435  }
436  case NET_UNKNOWN:
437  case NET_UNROUTABLE:
438  default:
439  switch(ourNet) {
440  default: return REACH_DEFAULT;
441  case NET_TEREDO: return REACH_TEREDO;
442  case NET_IPV6: return REACH_IPV6_WEAK;
443  case NET_IPV4: return REACH_IPV4;
444  case NET_TOR: return REACH_PRIVATE; // either from Tor, or don't care about our address
445  }
446  }
447 }
448 
450 {
451  port = 0;
452 }
453 
455 {
456  Init();
457 }
458 
459 CService::CService(const CNetAddr& cip, unsigned short portIn) : CNetAddr(cip), port(portIn)
460 {
461 }
462 
463 CService::CService(const struct in_addr& ipv4Addr, unsigned short portIn) : CNetAddr(ipv4Addr), port(portIn)
464 {
465 }
466 
467 CService::CService(const struct in6_addr& ipv6Addr, unsigned short portIn) : CNetAddr(ipv6Addr), port(portIn)
468 {
469 }
470 
471 CService::CService(const struct sockaddr_in& addr) : CNetAddr(addr.sin_addr), port(ntohs(addr.sin_port))
472 {
473  assert(addr.sin_family == AF_INET);
474 }
475 
476 CService::CService(const struct sockaddr_in6 &addr) : CNetAddr(addr.sin6_addr), port(ntohs(addr.sin6_port))
477 {
478  assert(addr.sin6_family == AF_INET6);
479 }
480 
481 bool CService::SetSockAddr(const struct sockaddr *paddr)
482 {
483  switch (paddr->sa_family) {
484  case AF_INET:
485  *this = CService(*(const struct sockaddr_in*)paddr);
486  return true;
487  case AF_INET6:
488  *this = CService(*(const struct sockaddr_in6*)paddr);
489  return true;
490  default:
491  return false;
492  }
493 }
494 
495 unsigned short CService::GetPort() const
496 {
497  return port;
498 }
499 
500 bool operator==(const CService& a, const CService& b)
501 {
502  return (CNetAddr)a == (CNetAddr)b && a.port == b.port;
503 }
504 
505 bool operator!=(const CService& a, const CService& b)
506 {
507  return (CNetAddr)a != (CNetAddr)b || a.port != b.port;
508 }
509 
510 bool operator<(const CService& a, const CService& b)
511 {
512  return (CNetAddr)a < (CNetAddr)b || ((CNetAddr)a == (CNetAddr)b && a.port < b.port);
513 }
514 
515 bool CService::GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const
516 {
517  if (IsIPv4()) {
518  if (*addrlen < (socklen_t)sizeof(struct sockaddr_in))
519  return false;
520  *addrlen = sizeof(struct sockaddr_in);
521  struct sockaddr_in *paddrin = (struct sockaddr_in*)paddr;
522  memset(paddrin, 0, *addrlen);
523  if (!GetInAddr(&paddrin->sin_addr))
524  return false;
525  paddrin->sin_family = AF_INET;
526  paddrin->sin_port = htons(port);
527  return true;
528  }
529  if (IsIPv6()) {
530  if (*addrlen < (socklen_t)sizeof(struct sockaddr_in6))
531  return false;
532  *addrlen = sizeof(struct sockaddr_in6);
533  struct sockaddr_in6 *paddrin6 = (struct sockaddr_in6*)paddr;
534  memset(paddrin6, 0, *addrlen);
535  if (!GetIn6Addr(&paddrin6->sin6_addr))
536  return false;
537  paddrin6->sin6_family = AF_INET6;
538  paddrin6->sin6_port = htons(port);
539  return true;
540  }
541  return false;
542 }
543 
544 std::vector<unsigned char> CService::GetKey() const
545 {
546  std::vector<unsigned char> vKey;
547  vKey.resize(18);
548  memcpy(&vKey[0], ip, 16);
549  vKey[16] = port / 0x100;
550  vKey[17] = port & 0x0FF;
551  return vKey;
552 }
553 
554 std::string CService::ToStringPort() const
555 {
556  return strprintf("%u", port);
557 }
558 
559 std::string CService::ToStringIPPort(bool fUseGetnameinfo) const
560 {
561  if (IsIPv4() || IsTor()) {
562  return ToStringIP(fUseGetnameinfo) + ":" + ToStringPort();
563  } else {
564  return "[" + ToStringIP(fUseGetnameinfo) + "]:" + ToStringPort();
565  }
566 }
567 
568 std::string CService::ToString(bool fUseGetnameinfo) const
569 {
570  return ToStringIPPort(fUseGetnameinfo);
571 }
572 
573 void CService::SetPort(unsigned short portIn)
574 {
575  port = portIn;
576 }
577 
579  valid(false)
580 {
581  memset(netmask, 0, sizeof(netmask));
582 }
583 
584 CSubNet::CSubNet(const CNetAddr &addr, int32_t mask)
585 {
586  valid = true;
587  network = addr;
588  // Default to /32 (IPv4) or /128 (IPv6), i.e. match single address
589  memset(netmask, 255, sizeof(netmask));
590 
591  // IPv4 addresses start at offset 12, and first 12 bytes must match, so just offset n
592  const int astartofs = network.IsIPv4() ? 12 : 0;
593 
594  int32_t n = mask;
595  if(n >= 0 && n <= (128 - astartofs*8)) // Only valid if in range of bits of address
596  {
597  n += astartofs*8;
598  // Clear bits [n..127]
599  for (; n < 128; ++n)
600  netmask[n>>3] &= ~(1<<(7-(n&7)));
601  } else
602  valid = false;
603 
604  // Normalize network according to netmask
605  for(int x=0; x<16; ++x)
606  network.ip[x] &= netmask[x];
607 }
608 
609 CSubNet::CSubNet(const CNetAddr &addr, const CNetAddr &mask)
610 {
611  valid = true;
612  network = addr;
613  // Default to /32 (IPv4) or /128 (IPv6), i.e. match single address
614  memset(netmask, 255, sizeof(netmask));
615 
616  // IPv4 addresses start at offset 12, and first 12 bytes must match, so just offset n
617  const int astartofs = network.IsIPv4() ? 12 : 0;
618 
619  for(int x=astartofs; x<16; ++x)
620  netmask[x] = mask.ip[x];
621 
622  // Normalize network according to netmask
623  for(int x=0; x<16; ++x)
624  network.ip[x] &= netmask[x];
625 }
626 
628  valid(addr.IsValid())
629 {
630  memset(netmask, 255, sizeof(netmask));
631  network = addr;
632 }
633 
634 bool CSubNet::Match(const CNetAddr &addr) const
635 {
636  if (!valid || !addr.IsValid())
637  return false;
638  for(int x=0; x<16; ++x)
639  if ((addr.ip[x] & netmask[x]) != network.ip[x])
640  return false;
641  return true;
642 }
643 
644 static inline int NetmaskBits(uint8_t x)
645 {
646  switch(x) {
647  case 0x00: return 0; break;
648  case 0x80: return 1; break;
649  case 0xc0: return 2; break;
650  case 0xe0: return 3; break;
651  case 0xf0: return 4; break;
652  case 0xf8: return 5; break;
653  case 0xfc: return 6; break;
654  case 0xfe: return 7; break;
655  case 0xff: return 8; break;
656  default: return -1; break;
657  }
658 }
659 
660 std::string CSubNet::ToString() const
661 {
662  /* Parse binary 1{n}0{N-n} to see if mask can be represented as /n */
663  int cidr = 0;
664  bool valid_cidr = true;
665  int n = network.IsIPv4() ? 12 : 0;
666  for (; n < 16 && netmask[n] == 0xff; ++n)
667  cidr += 8;
668  if (n < 16) {
669  int bits = NetmaskBits(netmask[n]);
670  if (bits < 0)
671  valid_cidr = false;
672  else
673  cidr += bits;
674  ++n;
675  }
676  for (; n < 16 && valid_cidr; ++n)
677  if (netmask[n] != 0x00)
678  valid_cidr = false;
679 
680  /* Format output */
681  std::string strNetmask;
682  if (valid_cidr) {
683  strNetmask = strprintf("%u", cidr);
684  } else {
685  if (network.IsIPv4())
686  strNetmask = strprintf("%u.%u.%u.%u", netmask[12], netmask[13], netmask[14], netmask[15]);
687  else
688  strNetmask = strprintf("%x:%x:%x:%x:%x:%x:%x:%x",
689  netmask[0] << 8 | netmask[1], netmask[2] << 8 | netmask[3],
690  netmask[4] << 8 | netmask[5], netmask[6] << 8 | netmask[7],
691  netmask[8] << 8 | netmask[9], netmask[10] << 8 | netmask[11],
692  netmask[12] << 8 | netmask[13], netmask[14] << 8 | netmask[15]);
693  }
694 
695  return network.ToString() + "/" + strNetmask;
696 }
697 
698 bool CSubNet::IsValid() const
699 {
700  return valid;
701 }
702 
703 bool operator==(const CSubNet& a, const CSubNet& b)
704 {
705  return a.valid == b.valid && a.network == b.network && !memcmp(a.netmask, b.netmask, 16);
706 }
707 
708 bool operator!=(const CSubNet& a, const CSubNet& b)
709 {
710  return !(a==b);
711 }
712 
713 bool operator<(const CSubNet& a, const CSubNet& b)
714 {
715  return (a.network < b.network || (a.network == b.network && memcmp(a.netmask, b.netmask, 16) < 0));
716 }
bool IsRFC6052() const
Definition: netaddress.cpp:128
bool IsRFC5737() const
Definition: netaddress.cpp:111
bool IsLocal() const
Definition: netaddress.cpp:166
void Init()
Definition: netaddress.cpp:449
bool operator==(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:271
std::vector< unsigned char > GetKey() const
Definition: netaddress.cpp:544
bool IsRFC4862() const
Definition: netaddress.cpp:139
#define strprintf
Definition: tinyformat.h:1011
std::string ToStringIP(bool fUseGetnameinfo=true) const
Definition: netaddress.cpp:241
static const int NET_UNKNOWN
Definition: netaddress.cpp:379
std::string ToString() const
Definition: netaddress.cpp:660
string EncodeBase32(const unsigned char *pch, size_t len)
bool IsRFC4193() const
Definition: netaddress.cpp:145
bool IsRFC4843() const
Definition: netaddress.cpp:156
bool IsValid() const
Definition: netaddress.cpp:186
bool IsRFC2544() const
Definition: netaddress.cpp:96
uint8_t netmask[16]
Netmask, in network byte order.
Definition: netaddress.h:100
void SetRaw(Network network, const uint8_t *data)
Definition: netaddress.cpp:28
bool IsRFC3927() const
Definition: netaddress.cpp:101
std::vector< unsigned char > GetGroup() const
Definition: netaddress.cpp:302
bool IsRFC3849() const
Definition: netaddress.cpp:118
void SetIP(const CNetAddr &ip)
Definition: netaddress.cpp:23
unsigned short GetPort() const
Definition: netaddress.cpp:495
bool IsIPv6() const
Definition: netaddress.cpp:83
static const unsigned char pchOnionCat[]
Definition: netaddress.cpp:16
bool operator!=(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:276
static int GetExtNetwork(const CNetAddr *addr)
Definition: netaddress.cpp:381
bool IsIPv4() const
Definition: netaddress.cpp:78
std::string ToStringIPPort(bool fUseGetnameinfo=true) const
Definition: netaddress.cpp:559
CNetAddr network
Network (base) address.
Definition: netaddress.h:98
bool IsRFC6598() const
Definition: netaddress.cpp:106
const char * name
Definition: rest.cpp:37
void SetPort(unsigned short portIn)
Definition: netaddress.cpp:573
unsigned short port
Definition: netaddress.h:135
bool IsRFC6145() const
Definition: netaddress.cpp:150
void Init()
Definition: netaddress.cpp:18
int GetReachabilityFrom(const CNetAddr *paddrPartner=NULL) const
Definition: netaddress.cpp:391
Network
Definition: netaddress.h:19
bool GetIn6Addr(struct in6_addr *pipv6Addr) const
Definition: netaddress.cpp:294
bool valid
Is this value valid? (only used to signal parse errors)
Definition: netaddress.h:102
bool IsRFC3964() const
Definition: netaddress.cpp:123
uint256 Hash(const T1 pbegin, const T1 pend)
Definition: hash.h:123
uint64_t GetHash() const
Definition: netaddress.cpp:369
std::string ToStringPort() const
Definition: netaddress.cpp:554
bool SetSockAddr(const struct sockaddr *paddr)
Definition: netaddress.cpp:481
bool operator<(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:281
static int NetmaskBits(uint8_t x)
Definition: netaddress.cpp:644
bool IsValid() const
Definition: netaddress.cpp:698
bool IsRFC1918() const
Definition: netaddress.cpp:88
std::string ToString() const
Definition: netaddress.cpp:266
void * memcpy(void *a, const void *b, size_t c)
bool IsRoutable() const
Definition: netaddress.cpp:222
static const int NET_TEREDO
Definition: netaddress.cpp:380
unsigned int GetByte(int n) const
Definition: netaddress.cpp:73
bool SetSpecial(const std::string &strName)
Definition: netaddress.cpp:44
bool GetInAddr(struct in_addr *pipv4Addr) const
Definition: netaddress.cpp:286
bool IsMulticast() const
Definition: netaddress.cpp:180
bool IsRFC4380() const
Definition: netaddress.cpp:134
enum Network GetNetwork() const
Definition: netaddress.cpp:227
vector< unsigned char > DecodeBase32(const char *p, bool *pfInvalid)
int port
Definition: zmq_sub.py:8
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
Definition: netaddress.cpp:515
bool Match(const CNetAddr &addr) const
Definition: netaddress.cpp:634
static const unsigned char pchIPv4[12]
Definition: netaddress.cpp:15
unsigned char ip[16]
Definition: netaddress.h:33
bool IsTor() const
Definition: netaddress.cpp:161