X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FProtocols%2FINet%2FINet6Address.cc;h=c662115a5fd6f0188c8f065a661abab6a83e9675;hb=6f50bf49e282c0528f51faa0a245bbfa2b867399;hp=7dfa6428705723ee5a63e9f5f791402c35f3c0ab;hpb=ced8f321adf904c31149162de5f6258c971c7466;p=senf.git diff --git a/Socket/Protocols/INet/INet6Address.cc b/Socket/Protocols/INet/INet6Address.cc index 7dfa642..c662115 100644 --- a/Socket/Protocols/INet/INet6Address.cc +++ b/Socket/Protocols/INet/INet6Address.cc @@ -1,8 +1,8 @@ // $Id$ // // Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -32,6 +32,7 @@ #include #include #include +#include //#include "INet6Address.mpp" #define prefix_ @@ -46,10 +47,14 @@ prefix_ senf::INet6Address senf::INet6Address::from_string(std::string const & s struct in6_addr ina; if (::inet_pton(AF_INET6,s.c_str(),&ina) > 0) return senf::INet6Address::from_data(&ina.s6_addr[0]); + + if (s.empty()) + throw SyntaxException(); + int herr (0); // If available, we use the reentrant GNU variant. This has the additional advantage, that we - // can explicitly ask for IpV4 addresses + // can explicitly ask for IPv4 addresses # ifdef __GLIBC__ @@ -74,16 +79,16 @@ prefix_ senf::INet6Address senf::INet6Address::from_string(std::string const & s return senf::INet6Address::from_data( &reinterpret_cast(*(ent->h_addr_list))->s6_addr[0]); - ///\todo Throw better exceptions here ? - if (resolve == ResolveINet4) try { return from_inet4address(INet4Address::from_string(s)); } catch (INet4Address::SyntaxException const & ex) { throw SyntaxException(); + } catch (INet4Address::UnknownHostnameException const & ex) { + throw UnknownHostnameException(); } else - throw SyntaxException(); + throw UnknownHostnameException(); } prefix_ std::ostream & senf::operator<<(std::ostream & os, INet6Address const & addr) @@ -92,7 +97,7 @@ prefix_ std::ostream & senf::operator<<(std::ostream & os, INet6Address const & char buffer[5*8]; std::copy(addr.begin(),addr.end(),&ina.s6_addr[0]); ::inet_ntop(AF_INET6,&ina,buffer,sizeof(buffer)); - buffer[5*8] = 0; + buffer[sizeof(buffer)-1] = 0; os << buffer; return os; } @@ -102,6 +107,25 @@ 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); senf::INet6Address const senf::INet6Address::AllRouters (0xFF02u,0u,0u,0u,0u,0u,0u,2u); +/////////////////////////////////////////////////////////////////////////// +// senf::INet6Network + +prefix_ senf::INet6Network::INet6Network(std::string s) +{ + using boost::lambda::_1; + using boost::lambda::_2; + std::string::size_type i (s.find('/')); + if (i == std::string::npos) + throw INet6Address::SyntaxException(); + try { + prefix_len_ = boost::lexical_cast(std::string(s,i+1)); + } catch (boost::bad_lexical_cast const &) { + throw INet6Address::SyntaxException(); + } + address_ = INet6Address::from_string(std::string(s, 0, i)); + detail::apply_mask(prefix_len_, address_.begin(), address_.end(), _1 &= _2); +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "INet6Address.mpp"