Skip to content

Commit 63f4bfa

Browse files
committed
fixed NetworkInterface for WinCE
code cleanup in NetworkInterface class IPAddress: do not format IPv6 loopback address as IPv4 compatible workaround for WEC2013 getsockname() issue testsuite fixes for WEC2013
1 parent 67b206f commit 63f4bfa

File tree

8 files changed

+119
-34
lines changed

8 files changed

+119
-34
lines changed

Net/src/IPAddress.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,19 @@ IPAddress::IPAddress(unsigned prefix, Family family)
159159
{
160160
if (prefix <= 32)
161161
newIPv4(prefix);
162+
else
163+
throw Poco::InvalidArgumentException("Invalid prefix length passed to IPAddress()");
162164
}
163165
#if defined(POCO_HAVE_IPv6)
164166
else if (family == IPv6)
165167
{
166168
if (prefix <= 128)
167169
newIPv6(prefix);
170+
else
171+
throw Poco::InvalidArgumentException("Invalid prefix length passed to IPAddress()");
168172
}
169173
#endif
170174
else throw Poco::InvalidArgumentException("Invalid or unsupported address family passed to IPAddress()");
171-
if (!pImpl()) throw Poco::InvalidArgumentException("Invalid prefix length passed to IPAddress()");
172175
}
173176

174177

Net/src/IPAddressImpl.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ namespace Poco {
5656
namespace Net {
5757
namespace Impl {
5858

59+
5960
//
6061
// IPAddressImpl
6162
//
@@ -75,6 +76,7 @@ IPAddressImpl::~IPAddressImpl()
7576
// IPv4AddressImpl
7677
//
7778

79+
7880
IPv4AddressImpl::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+
351354
IPv6AddressImpl::IPv6AddressImpl(const void* addr): _scope(0)
352355
{
353356
std::memcpy(&_addr, addr, sizeof(_addr));
354357
}
355358

359+
356360
IPv6AddressImpl::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+
399404
std::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+
463469
poco_socklen_t IPv6AddressImpl::length() const
464470
{
465471
return sizeof(_addr);
466472
}
467473

474+
468475
const void* IPv6AddressImpl::addr() const
469476
{
470477
return &_addr;
471478
}
472479

480+
473481
IPAddressImpl::Family IPv6AddressImpl::family() const
474482
{
475483
return IPAddressImpl::IPv6;
476484
}
477485

486+
478487
int IPv6AddressImpl::af() const
479488
{
480489
return AF_INET6;
481490
}
482491

492+
483493
unsigned IPv6AddressImpl::prefixLength() const
484494
{
485495
unsigned bits = 0;
@@ -510,91 +520,106 @@ Poco::UInt32 IPv6AddressImpl::scope() const
510520
return _scope;
511521
}
512522

523+
513524
bool 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+
520532
bool IPv6AddressImpl::isBroadcast() const
521533
{
522534
return false;
523535
}
524536

537+
525538
bool 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+
532546
bool IPv6AddressImpl::isMulticast() const
533547
{
534548
const UInt16* words = reinterpret_cast<const UInt16*>(&_addr);
535549
return (ntohs(words[0]) & 0xFFE0) == 0xFF00;
536550
}
537-
551+
552+
538553
bool IPv6AddressImpl::isLinkLocal() const
539554
{
540555
const UInt16* words = reinterpret_cast<const UInt16*>(&_addr);
541556
return (ntohs(words[0]) & 0xFFE0) == 0xFE80;
542557
}
543558

559+
544560
bool 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+
550567
bool 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+
556574
bool 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+
562581
bool IPv6AddressImpl::isWellKnownMC() const
563582
{
564583
const UInt16* words = reinterpret_cast<const UInt16*>(&_addr);
565584
return (ntohs(words[0]) & 0xFFF0) == 0xFF00;
566585
}
567586

587+
568588
bool IPv6AddressImpl::isNodeLocalMC() const
569589
{
570590
const UInt16* words = reinterpret_cast<const UInt16*>(&_addr);
571591
return (ntohs(words[0]) & 0xFFEF) == 0xFF01;
572592
}
573593

594+
574595
bool IPv6AddressImpl::isLinkLocalMC() const
575596
{
576597
const UInt16* words = reinterpret_cast<const UInt16*>(&_addr);
577598
return (ntohs(words[0]) & 0xFFEF) == 0xFF02;
578599
}
579600

601+
580602
bool IPv6AddressImpl::isSiteLocalMC() const
581603
{
582604
const UInt16* words = reinterpret_cast<const UInt16*>(&_addr);
583605
return (ntohs(words[0]) & 0xFFEF) == 0xFF05;
584606
}
585607

608+
586609
bool IPv6AddressImpl::isOrgLocalMC() const
587610
{
588611
const UInt16* words = reinterpret_cast<const UInt16*>(&_addr);
589612
return (ntohs(words[0]) & 0xFFEF) == 0xFF08;
590613
}
591614

615+
592616
bool IPv6AddressImpl::isGlobalMC() const
593617
{
594618
const UInt16* words = reinterpret_cast<const UInt16*>(&_addr);
595619
return (ntohs(words[0]) & 0xFFEF) == 0xFF0F;
596620
}
597621

622+
598623
IPv6AddressImpl 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+
640666
void IPv6AddressImpl::mask(const IPAddressImpl* pMask, const IPAddressImpl* pSet)
641667
{
642668
throw Poco::NotImplementedException("mask() is only supported for IPv4 addresses");
643669
}
644670

671+
645672
IPAddressImpl* IPv6AddressImpl::clone() const
646673
{
647674
return new IPv6AddressImpl(&_addr, _scope);
648675
}
649676

677+
650678
IPv6AddressImpl 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+
671700
IPv6AddressImpl 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+
692722
IPv6AddressImpl 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+
713744
IPv6AddressImpl IPv6AddressImpl::operator ~ () const
714745
{
715746
IPv6AddressImpl result(&_addr);

0 commit comments

Comments
 (0)