X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FSocket%2FProtocols%2FINet%2FINet6Address.cc;h=9319489d2b7b911e998c9712b96ea8fc7c437f59;hb=cb50871835b7a5c37e4fd32d38de67fa12570ebc;hp=9d16e19516277bed2f250a95a8a368f1f9c2bd81;hpb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;p=senf.git diff --git a/senf/Socket/Protocols/INet/INet6Address.cc b/senf/Socket/Protocols/INet/INet6Address.cc index 9d16e19..9319489 100644 --- a/senf/Socket/Protocols/INet/INet6Address.cc +++ b/senf/Socket/Protocols/INet/INet6Address.cc @@ -33,6 +33,9 @@ #include #include #include +#include +#include +#include //#include "INet6Address.mpp" #define prefix_ @@ -49,7 +52,7 @@ prefix_ senf::INet6Address senf::INet6Address::from_string(std::string const & s return senf::INet6Address::from_data(&ina.s6_addr[0]); if (s.empty()) - throw AddressSyntaxException(); + throw AddressSyntaxException() << ": empty string"; int herr (0); @@ -91,6 +94,38 @@ prefix_ in6_addr senf:: INet6Address::toin6_addr() const { return ina; } +prefix_ senf::INet6Address senf::INet6Address::from_mac(MACAddress const & mac) +{ + INet6Address addr; + addr[0] = 0xfe; + addr[1] = 0x80; + addr[8] = mac[0] ^ 0x2; // invert the "u" (universal/local) bit; see RFC 4291 Appx. A + addr[9] = mac[1]; + addr[10] = mac[2]; + addr[11] = 0xff; + addr[12] = 0xfe; + addr[13] = mac[3]; + addr[14] = mac[4]; + addr[15] = mac[5]; + return addr; +} + +prefix_ senf::INet6Address senf::INet6Address::from_eui64(EUI64 const & eui) +{ + INet6Address addr; + addr[0] = 0xfe; + addr[1] = 0x80; + addr[8] = eui[0] ^ 0x2; // invert the "u" (universal/local) bit; see RFC 4291 Appx. A + std::copy(eui.begin()+1, eui.end(), addr.begin()+9); + return addr; +} + +prefix_ senf::EUI64 senf::INet6Address::id() + const +{ + return EUI64::from_data(begin()+8); +} + prefix_ std::ostream & senf::operator<<(std::ostream & os, INet6Address const & addr) { ::in6_addr ina; @@ -130,16 +165,30 @@ prefix_ senf::INet6Network::INet6Network(std::string const & s) using boost::lambda::_2; std::string::size_type i (s.find('/')); if (i == std::string::npos) - throw AddressSyntaxException(); + throw AddressSyntaxException(s); try { prefix_len_ = boost::lexical_cast(std::string(s,i+1)); } catch (boost::bad_lexical_cast const &) { - throw AddressSyntaxException(); + throw AddressSyntaxException(s); } address_ = INet6Address::from_string(std::string(s, 0, i)); detail::apply_mask(prefix_len_, address_.begin(), address_.end(), _1 &= _2); } +prefix_ std::istream & senf::operator>>(std::istream & is, INet6Network & addr) +{ + std::string s; + if (!(is >> s)) + return is; + try { + addr = INet6Network(s); + } + catch (AddressException &) { + is.setstate(std::ios::failbit); + } + return is; +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "INet6Address.mpp"