mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Fix IPAddr/IPPrefix serialization bugs. (all unit tests pass)
This commit is contained in:
parent
c227563baf
commit
06e59e1398
3 changed files with 8 additions and 9 deletions
|
@ -104,7 +104,7 @@ string IPAddr::AsString() const
|
||||||
char s[INET6_ADDRSTRLEN];
|
char s[INET6_ADDRSTRLEN];
|
||||||
|
|
||||||
if ( inet_ntop(AF_INET6, in6.s6_addr, s, INET6_ADDRSTRLEN) == NULL )
|
if ( inet_ntop(AF_INET6, in6.s6_addr, s, INET6_ADDRSTRLEN) == NULL )
|
||||||
return "<bad IPv64 address conversion";
|
return "<bad IPv6 address conversion";
|
||||||
else
|
else
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -411,8 +411,8 @@ public:
|
||||||
{
|
{
|
||||||
// No self-assignment check here because it's correct without it and
|
// No self-assignment check here because it's correct without it and
|
||||||
// makes the common case faster.
|
// makes the common case faster.
|
||||||
prefix = other.Prefix();
|
prefix = other.prefix;
|
||||||
length = other.Length();
|
length = other.length;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -243,11 +243,10 @@ bool BinarySerializationFormat::Read(IPAddr* addr, const char* tag)
|
||||||
|
|
||||||
for ( int i = 0; i < n; ++i )
|
for ( int i = 0; i < n; ++i )
|
||||||
{
|
{
|
||||||
uint32_t i = 0;
|
if ( ! Read(&raw[i], "addr-part") )
|
||||||
if ( ! Read(&i, "addr-part") )
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
raw[n] = htonl(i);
|
raw[i] = htonl(raw[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( n == 1 )
|
if ( n == 1 )
|
||||||
|
@ -260,13 +259,13 @@ bool BinarySerializationFormat::Read(IPAddr* addr, const char* tag)
|
||||||
|
|
||||||
bool BinarySerializationFormat::Read(IPPrefix* prefix, const char* tag)
|
bool BinarySerializationFormat::Read(IPPrefix* prefix, const char* tag)
|
||||||
{
|
{
|
||||||
string s;
|
IPAddr addr;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if ( ! (Read(&s, tag) && Read(&len, tag)) )
|
if ( ! (Read(&addr, "prefix") && Read(&len, "width")) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*prefix = IPPrefix(IPAddr(s), len);
|
*prefix = IPPrefix(addr, len);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue