summaryrefslogtreecommitdiff
path: root/networkAddress.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'networkAddress.cpp')
-rw-r--r--networkAddress.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/networkAddress.cpp b/networkAddress.cpp
index d87f5ba..8be45e2 100644
--- a/networkAddress.cpp
+++ b/networkAddress.cpp
@@ -91,6 +91,26 @@ network_address_type_t NetworkAddress::getNetworkAddressType()
return network_address_type_;
}
+std::string NetworkAddress::toString() const
+{
+ if (network_address_type_==ipv4){
+ char buf[INET_ADDRSTRLEN];
+ if(!inet_ntop(AF_INET, &ipv4_address_, buf, sizeof(buf)))
+ return std::string("");
+ return std::string(buf);
+ }
+ else if (network_address_type_==ipv6) {
+ char buf[INET6_ADDRSTRLEN];
+ if(!inet_ntop(AF_INET6, &ipv6_address_, buf, sizeof(buf)))
+ return std::string("");
+ return std::string(buf);
+ }
+ else if (network_address_type_==ethernet) {
+ // TODO
+ }
+ return std::string("");
+}
+
bool NetworkAddress::operator<(const NetworkAddress &right) const
{
if (network_address_type_!=right.network_address_type_)