Fix IPAddr/IPPrefix serialization bugs. (all unit tests pass)

This commit is contained in:
Jon Siwek 2012-02-17 12:01:00 -06:00
parent c227563baf
commit 06e59e1398
3 changed files with 8 additions and 9 deletions

View file

@ -104,7 +104,7 @@ string IPAddr::AsString() const
char s[INET6_ADDRSTRLEN];
if ( inet_ntop(AF_INET6, in6.s6_addr, s, INET6_ADDRSTRLEN) == NULL )
return "<bad IPv64 address conversion";
return "<bad IPv6 address conversion";
else
return s;
}

View file

@ -411,8 +411,8 @@ public:
{
// No self-assignment check here because it's correct without it and
// makes the common case faster.
prefix = other.Prefix();
length = other.Length();
prefix = other.prefix;
length = other.length;
return *this;
}

View file

@ -243,11 +243,10 @@ bool BinarySerializationFormat::Read(IPAddr* addr, const char* tag)
for ( int i = 0; i < n; ++i )
{
uint32_t i = 0;
if ( ! Read(&i, "addr-part") )
if ( ! Read(&raw[i], "addr-part") )
return false;
raw[n] = htonl(i);
raw[i] = htonl(raw[i]);
}
if ( n == 1 )
@ -260,13 +259,13 @@ bool BinarySerializationFormat::Read(IPAddr* addr, const char* tag)
bool BinarySerializationFormat::Read(IPPrefix* prefix, const char* tag)
{
string s;
IPAddr addr;
int len;
if ( ! (Read(&s, tag) && Read(&len, tag)) )
if ( ! (Read(&addr, "prefix") && Read(&len, "width")) )
return false;
*prefix = IPPrefix(IPAddr(s), len);
*prefix = IPPrefix(addr, len);
return true;
}