moved IPAddress stream insertion operator to IPAddress.h, added stream insertion operator for SocketAddress, added BinaryWriter/BinaryReader insertion/extraction for SocketAddress, fixed serialization of IPAddress to BinaryWriter to support both IPv4 and IPv6 addresses

This commit is contained in:
Guenter Obiltschnig
2015-03-18 19:06:10 +01:00
parent c89cab6d6d
commit 2bbff0ca8f
6 changed files with 75 additions and 20 deletions

View File

@@ -563,19 +563,30 @@ IPAddress IPAddress::broadcast()
}
BinaryWriter& operator << (BinaryWriter& writer, const IPAddress& value)
} } // namespace Poco::Net
Poco::BinaryWriter& operator << (Poco::BinaryWriter& writer, const Poco::Net::IPAddress& value)
{
writer.stream().write((const char*) value.addr(), value.length());
writer << static_cast<Poco::UInt8>(value.length());
writer.writeRaw(reinterpret_cast<const char*>(value.addr()), value.length());
return writer;
}
BinaryReader& operator >> (BinaryReader& reader, IPAddress& value)
Poco::BinaryReader& operator >> (Poco::BinaryReader& reader, Poco::Net::IPAddress& value)
{
char buf[sizeof(struct in6_addr)];
reader.stream().read(buf, value.length());
value = IPAddress(buf, value.length());
Poco::UInt8 length;
reader >> length;
reader.readRaw(buf, length);
value = Poco::Net::IPAddress(buf, length);
return reader;
}
} } // namespace Poco::Net
std::ostream& operator << (std::ostream& ostr, const Poco::Net::IPAddress& addr)
{
ostr << addr.toString();
return ostr;
}