BNetworkAddress::IsEmpty() now detects empty ipv4/6.
* Until now, only AF_UNSPEC addresses could be empty. * Now, the unspecified IPV4/IPv6 address is considered empty, too. * This corresponds to how the kernel modules handles this.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2013, Axel Dörfler, [email protected].
|
* Copyright 2010-2015, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -617,7 +617,27 @@ BNetworkAddress::SockAddr()
|
|||||||
bool
|
bool
|
||||||
BNetworkAddress::IsEmpty() const
|
BNetworkAddress::IsEmpty() const
|
||||||
{
|
{
|
||||||
return fAddress.ss_len == 0 || fAddress.ss_family == AF_UNSPEC;
|
if (fAddress.ss_len == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
switch (fAddress.ss_family) {
|
||||||
|
case AF_UNSPEC:
|
||||||
|
return true;
|
||||||
|
case AF_INET:
|
||||||
|
{
|
||||||
|
sockaddr_in& sin = (sockaddr_in&)fAddress;
|
||||||
|
return sin.sin_addr.s_addr == INADDR_ANY && sin.sin_port == 0;
|
||||||
|
}
|
||||||
|
case AF_INET6:
|
||||||
|
{
|
||||||
|
sockaddr_in6& sin6 = (sockaddr_in6&)fAddress;
|
||||||
|
return IN6_IS_ADDR_UNSPECIFIED(&sin6.sin6_addr)
|
||||||
|
&& sin6.sin6_port == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2011, Axel Dörfler, [email protected].
|
* Copyright 2010-2015, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -73,9 +73,13 @@ NetworkAddressTest::TestWildcard()
|
|||||||
CPPUNIT_ASSERT(wildcard.Port() == 0);
|
CPPUNIT_ASSERT(wildcard.Port() == 0);
|
||||||
CPPUNIT_ASSERT(((sockaddr_in&)wildcard.SockAddr()).sin_addr.s_addr
|
CPPUNIT_ASSERT(((sockaddr_in&)wildcard.SockAddr()).sin_addr.s_addr
|
||||||
== INADDR_ANY);
|
== INADDR_ANY);
|
||||||
|
CPPUNIT_ASSERT(wildcard.IsEmpty());
|
||||||
|
|
||||||
BNetworkAddress null(AF_INET, NULL);
|
BNetworkAddress null(AF_INET, NULL);
|
||||||
CPPUNIT_ASSERT(wildcard == null);
|
CPPUNIT_ASSERT(wildcard == null);
|
||||||
|
|
||||||
|
wildcard.SetPort(555);
|
||||||
|
CPPUNIT_ASSERT(!wildcard.IsEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user