fixed GH #1570: IPv6AddressImpl::toString() returns wrong output for IPv6 address "::"

This commit is contained in:
Guenter Obiltschnig 2017-02-11 19:01:12 +01:00
parent d35677790f
commit aa803f3657
2 changed files with 14 additions and 7 deletions

View File

@ -432,13 +432,16 @@ std::string IPv6AddressImpl::toString() const
else
result.append("::ffff:");
const UInt8* bytes = reinterpret_cast<const UInt8*>(&_addr);
NumberFormatter::append(result, bytes[12]);
result.append(".");
NumberFormatter::append(result, bytes[13]);
result.append(".");
NumberFormatter::append(result, bytes[14]);
result.append(".");
NumberFormatter::append(result, bytes[15]);
if (bytes[12] != 0) // only 0.0.0.0 can start with zero
{
NumberFormatter::append(result, bytes[12]);
result.append(".");
NumberFormatter::append(result, bytes[13]);
result.append(".");
NumberFormatter::append(result, bytes[14]);
result.append(".");
NumberFormatter::append(result, bytes[15]);
}
return result;
}
else

View File

@ -85,6 +85,10 @@ void IPAddressTest::testStringConv6()
IPAddress ia6(32, IPAddress::IPv6);
assert (ia6.family() == IPAddress::IPv6);
assert (ia6.toString() == "ffff:ffff::");
IPAddress ia7("::");
assert (ia7.family() == IPAddress::IPv6);
assert (ia7.toString() == "::");
#endif
}