From b5e293ed59d3005517b4192b7f00a8bf037b7c59 Mon Sep 17 00:00:00 2001 From: dw6 <dw6@wiback.org> Date: Wed, 18 Jun 2008 12:41:49 +0000 Subject: [PATCH] adding toString and toin6_addr --- Socket/Protocols/INet/INet6Address.cc | 20 +++++++++++++++----- Socket/Protocols/INet/INet6Address.hh | 6 ++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Socket/Protocols/INet/INet6Address.cc b/Socket/Protocols/INet/INet6Address.cc index 6631ec494..6c76f7741 100644 --- a/Socket/Protocols/INet/INet6Address.cc +++ b/Socket/Protocols/INet/INet6Address.cc @@ -85,17 +85,27 @@ prefix_ senf::INet6Address senf::INet6Address::from_string(std::string const & s throw UnknownHostnameException(s); } -prefix_ std::ostream & senf::operator<<(std::ostream & os, INet6Address const & addr) -{ +prefix_ in6_addr senf:: INet6Address::toin6_addr() const { ::in6_addr ina; + std::copy((*this).begin(), (*this).end(), &ina.s6_addr[0]); + return ina; +} + +prefix_ std::string senf::INet6Address::toString() const { char buffer[5*8]; - std::copy(addr.begin(),addr.end(),&ina.s6_addr[0]); - ::inet_ntop(AF_INET6,&ina,buffer,sizeof(buffer)); + ::in6_addr ina = (*this).toin6_addr(); + ::inet_ntop(AF_INET6, & ina , buffer, sizeof(buffer)); buffer[sizeof(buffer)-1] = 0; - os << buffer; + return buffer; +} + +prefix_ std::ostream & senf::operator<<(std::ostream & os, INet6Address const & addr) +{ + os << addr.toString(); return os; } + senf::INet6Address const senf::INet6Address::None; senf::INet6Address const senf::INet6Address::Loopback (0u,0u,0u,0u,0u,0u,0u,1u); senf::INet6Address const senf::INet6Address::AllNodes (0xFF02u,0u,0u,0u,0u,0u,0u,1u); diff --git a/Socket/Protocols/INet/INet6Address.hh b/Socket/Protocols/INet/INet6Address.hh index 383f87f4f..aa29b2905 100644 --- a/Socket/Protocols/INet/INet6Address.hh +++ b/Socket/Protocols/INet/INet6Address.hh @@ -203,6 +203,12 @@ namespace senf { \par INet4 compatible INet6 addresses are not directly supported, they are deprecated in the RFC. */ + std::string toString() const; + ///< get the string representation of this INet6Address + in6_addr toin6_addr() const; + ///< get the linux in6_addr struct (convinience only) + + ///@} /////////////////////////////////////////////////////////////////////////// ///\name Accessors -- GitLab