@@ -56,6 +56,7 @@ namespace Poco {
5656namespace Net {
5757namespace Impl {
5858
59+
5960//
6061// IPAddressImpl
6162//
@@ -75,6 +76,7 @@ IPAddressImpl::~IPAddressImpl()
7576// IPv4AddressImpl
7677//
7778
79+
7880IPv4AddressImpl::IPv4AddressImpl ()
7981{
8082 std::memset (&_addr, 0 , sizeof (_addr));
@@ -348,11 +350,13 @@ IPv6AddressImpl::IPv6AddressImpl(): _scope(0)
348350 std::memset (&_addr, 0 , sizeof (_addr));
349351}
350352
353+
351354IPv6AddressImpl::IPv6AddressImpl (const void * addr): _scope(0 )
352355{
353356 std::memcpy (&_addr, addr, sizeof (_addr));
354357}
355358
359+
356360IPv6AddressImpl::IPv6AddressImpl (const void * addr, Poco::UInt32 scope): _scope(scope)
357361{
358362 std::memcpy (&_addr, addr, sizeof (_addr));
@@ -396,10 +400,11 @@ IPv6AddressImpl::IPv6AddressImpl(unsigned prefix):
396400#endif
397401}
398402
403+
399404std::string IPv6AddressImpl::toString () const
400405{
401406 const UInt16* words = reinterpret_cast <const UInt16*>(&_addr);
402- if (isIPv4Compatible () || isIPv4Mapped ())
407+ if (( isIPv4Compatible () && ! isLoopback () ) || isIPv4Mapped ())
403408 {
404409 std::string result;
405410 result.reserve (24 );
@@ -460,26 +465,31 @@ std::string IPv6AddressImpl::toString() const
460465 }
461466}
462467
468+
463469poco_socklen_t IPv6AddressImpl::length () const
464470{
465471 return sizeof (_addr);
466472}
467473
474+
468475const void * IPv6AddressImpl::addr () const
469476{
470477 return &_addr;
471478}
472479
480+
473481IPAddressImpl::Family IPv6AddressImpl::family () const
474482{
475483 return IPAddressImpl::IPv6;
476484}
477485
486+
478487int IPv6AddressImpl::af () const
479488{
480489 return AF_INET6;
481490}
482491
492+
483493unsigned IPv6AddressImpl::prefixLength () const
484494{
485495 unsigned bits = 0 ;
@@ -510,91 +520,106 @@ Poco::UInt32 IPv6AddressImpl::scope() const
510520 return _scope;
511521}
512522
523+
513524bool IPv6AddressImpl::isWildcard () const
514525{
515526 const UInt16* words = reinterpret_cast <const UInt16*>(&_addr);
516527 return words[0 ] == 0 && words[1 ] == 0 && words[2 ] == 0 && words[3 ] == 0 &&
517528 words[4 ] == 0 && words[5 ] == 0 && words[6 ] == 0 && words[7 ] == 0 ;
518529}
519530
531+
520532bool IPv6AddressImpl::isBroadcast () const
521533{
522534 return false ;
523535}
524536
537+
525538bool IPv6AddressImpl::isLoopback () const
526539{
527540 const UInt16* words = reinterpret_cast <const UInt16*>(&_addr);
528541 return words[0 ] == 0 && words[1 ] == 0 && words[2 ] == 0 && words[3 ] == 0 &&
529542 words[4 ] == 0 && words[5 ] == 0 && words[6 ] == 0 && ntohs (words[7 ]) == 0x0001 ;
530543}
531544
545+
532546bool IPv6AddressImpl::isMulticast () const
533547{
534548 const UInt16* words = reinterpret_cast <const UInt16*>(&_addr);
535549 return (ntohs (words[0 ]) & 0xFFE0 ) == 0xFF00 ;
536550}
537-
551+
552+
538553bool IPv6AddressImpl::isLinkLocal () const
539554{
540555 const UInt16* words = reinterpret_cast <const UInt16*>(&_addr);
541556 return (ntohs (words[0 ]) & 0xFFE0 ) == 0xFE80 ;
542557}
543558
559+
544560bool IPv6AddressImpl::isSiteLocal () const
545561{
546562 const UInt16* words = reinterpret_cast <const UInt16*>(&_addr);
547563 return ((ntohs (words[0 ]) & 0xFFE0 ) == 0xFEC0 ) || ((ntohs (words[0 ]) & 0xFF00 ) == 0xFC00 );
548564}
549565
566+
550567bool IPv6AddressImpl::isIPv4Compatible () const
551568{
552569 const UInt16* words = reinterpret_cast <const UInt16*>(&_addr);
553570 return words[0 ] == 0 && words[1 ] == 0 && words[2 ] == 0 && words[3 ] == 0 && words[4 ] == 0 && words[5 ] == 0 ;
554571}
555572
573+
556574bool IPv6AddressImpl::isIPv4Mapped () const
557575{
558576 const UInt16* words = reinterpret_cast <const UInt16*>(&_addr);
559577 return words[0 ] == 0 && words[1 ] == 0 && words[2 ] == 0 && words[3 ] == 0 && words[4 ] == 0 && ntohs (words[5 ]) == 0xFFFF ;
560578}
561579
580+
562581bool IPv6AddressImpl::isWellKnownMC () const
563582{
564583 const UInt16* words = reinterpret_cast <const UInt16*>(&_addr);
565584 return (ntohs (words[0 ]) & 0xFFF0 ) == 0xFF00 ;
566585}
567586
587+
568588bool IPv6AddressImpl::isNodeLocalMC () const
569589{
570590 const UInt16* words = reinterpret_cast <const UInt16*>(&_addr);
571591 return (ntohs (words[0 ]) & 0xFFEF ) == 0xFF01 ;
572592}
573593
594+
574595bool IPv6AddressImpl::isLinkLocalMC () const
575596{
576597 const UInt16* words = reinterpret_cast <const UInt16*>(&_addr);
577598 return (ntohs (words[0 ]) & 0xFFEF ) == 0xFF02 ;
578599}
579600
601+
580602bool IPv6AddressImpl::isSiteLocalMC () const
581603{
582604 const UInt16* words = reinterpret_cast <const UInt16*>(&_addr);
583605 return (ntohs (words[0 ]) & 0xFFEF ) == 0xFF05 ;
584606}
585607
608+
586609bool IPv6AddressImpl::isOrgLocalMC () const
587610{
588611 const UInt16* words = reinterpret_cast <const UInt16*>(&_addr);
589612 return (ntohs (words[0 ]) & 0xFFEF ) == 0xFF08 ;
590613}
591614
615+
592616bool IPv6AddressImpl::isGlobalMC () const
593617{
594618 const UInt16* words = reinterpret_cast <const UInt16*>(&_addr);
595619 return (ntohs (words[0 ]) & 0xFFEF ) == 0xFF0F ;
596620}
597621
622+
598623IPv6AddressImpl IPv6AddressImpl::parse (const std::string& addr)
599624{
600625 if (addr.empty ()) return IPv6AddressImpl ();
@@ -637,16 +662,19 @@ IPv6AddressImpl IPv6AddressImpl::parse(const std::string& addr)
637662#endif
638663}
639664
665+
640666void IPv6AddressImpl::mask (const IPAddressImpl* pMask, const IPAddressImpl* pSet)
641667{
642668 throw Poco::NotImplementedException (" mask() is only supported for IPv4 addresses" );
643669}
644670
671+
645672IPAddressImpl* IPv6AddressImpl::clone () const
646673{
647674 return new IPv6AddressImpl (&_addr, _scope);
648675}
649676
677+
650678IPv6AddressImpl IPv6AddressImpl::operator & (const IPv6AddressImpl& addr) const
651679{
652680 IPv6AddressImpl result (&_addr);
@@ -668,6 +696,7 @@ IPv6AddressImpl IPv6AddressImpl::operator & (const IPv6AddressImpl& addr) const
668696 return result;
669697}
670698
699+
671700IPv6AddressImpl IPv6AddressImpl::operator | (const IPv6AddressImpl& addr) const
672701{
673702 IPv6AddressImpl result (&_addr);
@@ -689,6 +718,7 @@ IPv6AddressImpl IPv6AddressImpl::operator | (const IPv6AddressImpl& addr) const
689718 return result;
690719}
691720
721+
692722IPv6AddressImpl IPv6AddressImpl::operator ^ (const IPv6AddressImpl& addr) const
693723{
694724 IPv6AddressImpl result (&_addr);
@@ -710,6 +740,7 @@ IPv6AddressImpl IPv6AddressImpl::operator ^ (const IPv6AddressImpl& addr) const
710740 return result;
711741}
712742
743+
713744IPv6AddressImpl IPv6AddressImpl::operator ~ () const
714745{
715746 IPv6AddressImpl result (&_addr);
0 commit comments