diff --git a/include/Nazara/Network/IpAddress.hpp b/include/Nazara/Network/IpAddress.hpp index c4189b2e2..a5679a4bc 100644 --- a/include/Nazara/Network/IpAddress.hpp +++ b/include/Nazara/Network/IpAddress.hpp @@ -49,7 +49,7 @@ namespace Nz inline IPv4 ToIPv4() const; inline IPv6 ToIPv6() const; - std::string ToString() const; + std::string ToString(bool includesPort = true) const; inline UInt32 ToUInt32() const; inline explicit operator bool() const; diff --git a/src/Nazara/Network/IpAddress.cpp b/src/Nazara/Network/IpAddress.cpp index d38f2973b..fd215559e 100644 --- a/src/Nazara/Network/IpAddress.cpp +++ b/src/Nazara/Network/IpAddress.cpp @@ -104,8 +104,7 @@ namespace Nz * * \remark Produces a NazaraAssert if internal protocol is invalid (should never happen) */ - - std::string IpAddress::ToString() const + std::string IpAddress::ToString(bool includesPort) const { std::ostringstream stream; @@ -155,7 +154,7 @@ namespace Nz } // We need brackets around our IPv6 address if we have a port - if (m_port != 0) + if (m_port != 0 && includesPort) stream << '['; // IPv4-mapped IPv6? @@ -195,12 +194,12 @@ namespace Nz } - if (m_port != 0) + if (m_port != 0 && includesPort) stream << ']'; break; } - if (m_port != 0) + if (m_port != 0 && includesPort) stream << ':' << m_port; }