return senf::INet4Address::from_inaddr(ina.s_addr);
if (s.empty())
- throw SyntaxException();
+ throw AddressSyntaxException();
int herr (0);
{
std::string::size_type i (s.find('/'));
if (i == std::string::npos)
- throw INet4Address::SyntaxException();
+ throw AddressSyntaxException();
try {
prefix_len_ = boost::lexical_cast<unsigned>(std::string(s,i+1));
} catch (boost::bad_lexical_cast const &) {
- throw INet4Address::SyntaxException();
+ throw AddressSyntaxException();
}
address_ = INet4Address(INet4Address::from_string(std::string(s, 0, i)).address() & mask());
}
#include <boost/operators.hpp>
#include "../../../Utils/safe_bool.hh"
#include "../../../Utils/Tags.hh"
+#include "../AddressExceptions.hh"
//#include "INet4Address.mpp"
///////////////////////////////hh.p////////////////////////////////////////
\attention This call may block if \a s represents a
hostname which must be looked up via some network
protocol like DNS or NIS
- \throws SyntaxException if the address cannot be
+ \throws AddressSyntaxException if the address cannot be
converted for some reason
\param[in] s Address literal or hostname */
////@}
- /** \brief Base-class for INet4Address exceptions */
- struct AddressException : public std::exception {};
-
- /** \brief Invalid INet4 address syntax */
- struct SyntaxException : public AddressException
- { virtual char const * what() const throw()
- { return "invalid INet4 address syntax"; } };
-
- /** \brief Resolver failure */
- struct UnknownHostnameException : public AddressException
- { virtual char const * what() const throw()
- { return "failed to resolve INet4 hostname"; } };
-
private:
enum InAddr_t { IsInAddr };
INet4Address(inaddr_type addr, InAddr_t);
return senf::INet6Address::from_data(&ina.s6_addr[0]);
if (s.empty())
- throw SyntaxException();
+ throw AddressSyntaxException();
int herr (0);
&reinterpret_cast<in6_addr*>(*(ent->h_addr_list))->s6_addr[0]);
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();
- }
+ return from_inet4address(INet4Address::from_string(s));
else
throw UnknownHostnameException();
}
using boost::lambda::_2;
std::string::size_type i (s.find('/'));
if (i == std::string::npos)
- throw INet6Address::SyntaxException();
+ throw AddressSyntaxException();
try {
prefix_len_ = boost::lexical_cast<unsigned>(std::string(s,i+1));
} catch (boost::bad_lexical_cast const &) {
- throw INet6Address::SyntaxException();
+ throw AddressSyntaxException();
}
address_ = INet6Address::from_string(std::string(s, 0, i));
detail::apply_mask(prefix_len_, address_.begin(), address_.end(), _1 &= _2);
#include "../../../Utils/safe_bool.hh"
#include "../../../Utils/Tags.hh"
#include "INet4Address.hh"
+#include "../AddressExceptions.hh"
//#include "INet6Address.mpp"
#include "INet6Address.ih"
\attention This call may block if \a s represents a
hostname which must be looked up via some network
protocol like DNS or NIS
- \throws SyntaxException if the address cannot be
+ \throws AddressSyntaxException if the address cannot be
converted for some reason
\param[in] s Address literal or hostname
\param[in] resolve If this is set to \c ResolveINet4,
///@}
- /** \brief Base-class for INet6Address exceptions */
- struct AddressException : public std::exception {};
-
- /** \brief Invalid INet4 address syntax */
- struct SyntaxException : public AddressException
- { virtual char const * what() const throw()
- { return "invalid INet6 address syntax"; } };
-
- /** \brief Resolver failure */
- struct UnknownHostnameException : public AddressException
- { virtual char const * what() const throw()
- { return "failed to resolve INet6 hostname"; } };
};
/** \brief Output INet6Address instance as it's string representation
{
using senf::INet6Address;
using senf::INet4Address;
+ using senf::AddressSyntaxException;
+ using senf::UnknownHostnameException;
{
INet6Address addr1 (INet6Address::from_string("0102:0304:0506:0708:090A:0B0C:0D0E:0F00"));
addr1 = INet6Address::None;
addr2 = INet6Address::from_string("::");
BOOST_CHECK_EQUAL( addr1, addr2 );
- BOOST_CHECK_THROW( INet6Address::from_string(""), INet6Address::SyntaxException );
+ BOOST_CHECK_THROW( INet6Address::from_string(""), AddressSyntaxException );
BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(addr1), "::" );
unsigned char data[] = { 0x12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x21, 0 };
INet6Address addr3 (INet6Address::from_data(data));
BOOST_CHECK_EQUAL( INet6Address::from_inet4address(INet4Address(0x01020304)),
INet6Address::from_string("::ffff:1.2.3.4") );
- BOOST_CHECK_THROW( INet6Address::from_string("1.2.3.4"), INet6Address::UnknownHostnameException );
+ BOOST_CHECK_THROW( INet6Address::from_string("1.2.3.4"), UnknownHostnameException );
BOOST_CHECK_EQUAL( INet6Address::from_string("1.2.3.4", INet6Address::ResolveINet4),
INet6Address::from_string("::ffff:1.2.3.4") );
}
clear();
unsigned i = addr.find(':');
if (i == std::string::npos)
- throw SyntaxException();
+ throw AddressSyntaxException();
try {
port(boost::lexical_cast< ::u_int16_t >(std::string(addr,i+1)));
}
catch (boost::bad_lexical_cast const &) {
- throw SyntaxException();
- }
- try {
- address(INet4Address::from_string(std::string(addr,0,i)));
- }
- catch (INet4Address::SyntaxException const &) {
- throw SyntaxException();
+ throw AddressSyntaxException();
}
+ address(INet4Address::from_string(std::string(addr,0,i)));
}
prefix_ senf::INet4SocketAddress::INet4SocketAddress(INet4Address const & addr, unsigned p)
boost::smatch match;
if (! regex_match(addr, match, addressRx))
- throw SyntaxException();
+ throw AddressSyntaxException();
if (match[ZoneId].matched)
assignIface(match[ZoneId]);
sockaddr_.sin6_port = htons(boost::lexical_cast<boost::uint16_t>(match[Port]));
- try {
- INet6Address a (INet6Address::from_string(
- match[NumericAddr].matched ? match[NumericAddr] : match[Hostname],
- resolve));
- std::copy(a.begin(), a.end(), &sockaddr_.sin6_addr.s6_addr[0]);
- } catch (INet6Address::SyntaxException const &) {
- throw SyntaxException();
- }
+ INet6Address a (INet6Address::from_string(
+ match[NumericAddr].matched ? match[NumericAddr] : match[Hostname],
+ resolve));
+ std::copy(a.begin(), a.end(), &sockaddr_.sin6_addr.s6_addr[0]);
}
prefix_ bool senf::INet6SocketAddress::operator==(INet6SocketAddress const & other)
else {
sockaddr_.sin6_scope_id = if_nametoindex(iface.c_str());
if (sockaddr_.sin6_scope_id == 0)
- throw SyntaxException();
+ throw AddressSyntaxException();
}
}
initialize the host and port members. Since it uses the
INet4Address::from_string constructor, this call may
block while waiting for the resolver.
- \throws SyntaxException if the address syntax is
+ \throws AddressSyntaxException if the address syntax is
invalid
- \throws INet4Address::UnknownHostnameException if the
+ \throws UnknownHostnameException if the
address cannot be resolved. */
INet4SocketAddress(INet4Address const & addr, unsigned port);
/// @}
- struct SyntaxException : public std::exception
- { virtual char const * what() const throw()
- { return "Invalid IPv4 socket address syntax"; } };
-
private:
struct ::sockaddr_in addr_;
};
explicit INet6SocketAddress(std::string const & addr,
INet6Address::Resolve_t resolve = INet6Address::ResolveINet6);
///< Initialize/convert from string representation
- /**< \throws SyntaxException if the address syntax is
+ /**< \throws AddressSyntaxException if the address syntax is
invalid
- \throws INet6Address::UnknownHostnameException if the
+ \throws UnknownHostnameException if the
address cannot be resolved.
\param[in] addr Address to parse
\param[in] resolve If this is
///@}
- struct SyntaxException : public std::exception
- { virtual char const * what() const throw()
- { return "Invalid IPv6 socket address syntax"; } };
-
protected:
private:
{
using senf::INet4SocketAddress;
using senf::INet4Address;
+ using senf::AddressSyntaxException;
{
INet4SocketAddress addr;
BOOST_CHECK_EQUAL( INet4SocketAddress("127.0.0.1:12345"),
INet4SocketAddress(INet4Address::Loopback,12345) );
- BOOST_CHECK_THROW( INet4SocketAddress("127.0.0.1"), INet4SocketAddress::SyntaxException );
- BOOST_CHECK_THROW( INet4SocketAddress("foo:bar"), INet4SocketAddress::SyntaxException );
- BOOST_CHECK_THROW( INet4SocketAddress(":12345"), INet4SocketAddress::SyntaxException );
- BOOST_CHECK_THROW( INet4SocketAddress("127.0.0.1:1234a"), INet4SocketAddress::SyntaxException );
+ BOOST_CHECK_THROW( INet4SocketAddress("127.0.0.1"), AddressSyntaxException );
+ BOOST_CHECK_THROW( INet4SocketAddress("foo:bar"), AddressSyntaxException );
+ BOOST_CHECK_THROW( INet4SocketAddress(":12345"), AddressSyntaxException );
+ BOOST_CHECK_THROW( INet4SocketAddress("127.0.0.1:1234a"), AddressSyntaxException );
BOOST_CHECK_EQUAL( INet4SocketAddress("127.0.0.1:12345").address(), INet4Address::Loopback );
BOOST_CHECK_EQUAL( INet4SocketAddress("127.0.0.1:12345").port(), 12345u );
{
using senf::INet6Address;
using senf::INet6SocketAddress;
+ using senf::AddressSyntaxException;
{
INet6SocketAddress addr;
BOOST_CHECK_EQUAL( addr.port(), 100u );
addr.address(INet6Address::from_string("::2"));
BOOST_CHECK_EQUAL( addr.address(), INet6Address::from_string("::2") );
- BOOST_CHECK_THROW( senf::INet6SocketAddress(""), INet6SocketAddress::SyntaxException );
+ BOOST_CHECK_THROW( senf::INet6SocketAddress(""), AddressSyntaxException );
BOOST_CHECK_THROW( senf::INet6SocketAddress("[::1]"),
- INet6SocketAddress::SyntaxException );
+ AddressSyntaxException );
BOOST_CHECK_THROW( senf::INet6SocketAddress("[::1]1234"),
- INet6SocketAddress::SyntaxException );
+ AddressSyntaxException );
addr = senf::INet6SocketAddress("[12::21%lo]:12345");
BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(addr), "[12::21%lo]:12345" );
BOOST_CHECK_EQUAL( addr.address(), INet6Address::from_string("12::21") );
#include <boost/algorithm/string/finder.hpp>
#include "../../../Utils/Exception.hh"
+#include "../AddressExceptions.hh"
//#include "LLAddressing.mpp"
#define prefix_
return std::string();
char name[IFNAMSIZ];
if (! ::if_indextoname(addr_.sll_ifindex, name))
- throw InvalidLLSocketAddressException();
+ throw AddressSyntaxException();
return std::string(name);
}
else {
addr_.sll_ifindex = if_nametoindex(iface.c_str());
if (addr_.sll_ifindex == 0)
- throw InvalidLLSocketAddressException();
+ throw AddressSyntaxException();
}
}
struct ::sockaddr_ll addr_;
};
- /** \brief Signal invalid link local address syntax
- \related LLSocketAddress
- */
- struct InvalidLLSocketAddressException : public std::exception
- { char const * what() const throw() { return "invalid ll address"; } };
-
/// @}
/// \addtogroup policy_impl_group
boost::uint8_t hexToNibble(char c)
{
if (c<'0')
- throw senf::MACAddress::SyntaxException();
+ throw senf::AddressSyntaxException();
else if (c<='9')
return c-'0';
else if (c<'A')
- throw senf::MACAddress::SyntaxException();
+ throw senf::AddressSyntaxException();
else if (c<='F')
return c-'A'+10;
else if (c<'a')
- throw senf::MACAddress::SyntaxException();
+ throw senf::AddressSyntaxException();
else if (c<='f')
return c-'a'+10;
else
- throw senf::MACAddress::SyntaxException();
+ throw senf::AddressSyntaxException();
}
template <class Range>
boost::uint8_t hexToByte(Range const & range)
{
if (boost::size(range) != 2)
- throw senf::MACAddress::SyntaxException();
+ throw senf::AddressSyntaxException();
typename boost::range_const_iterator<Range>::type i (boost::begin(range));
return hexToNibble(i[0])*16+hexToNibble(i[1]);
}
for (; i!=i_end && j!=j_end; ++i, ++j)
*j = hexToByte(*i);
if (i!=i_end || j!=j_end)
- throw SyntaxException();
+ throw AddressSyntaxException();
return mac;
}
prefix_ senf::MACAddress senf::MACAddress::from_eui64(boost::uint64_t v)
{
if ( boost::uint16_t(v>>24) != 0xfffe )
- throw SyntaxException();
+ throw AddressSyntaxException();
MACAddress mac (senf::noinit);
mac[0] = boost::uint8_t( v>>56 );
mac[1] = boost::uint8_t( v>>48 );
#include <boost/type_traits.hpp>
#include "../../../Utils/safe_bool.hh"
#include "../../../Utils/Tags.hh"
+#include "../AddressExceptions.hh"
//#include "MACAddress.mpp"
///////////////////////////////hh.p////////////////////////////////////////
to a MAC address. This conversion is only possible, if
the EUI-64 is MAC compatible: the 4th/5th byte (in
transmission order) must be 0xFFFE.
- \throws SyntaxException if \a v is not a MAC compatible
- EUI-64. */
+ \throws AddressSyntaxException if \a v is not a MAC
+ compatible EUI-64. */
bool local() const; ///< \c true, if address is locally administered
bool multicast() const; ///< \c true, if address is a group/multicast address
boost::uint64_t eui64() const; ///< Build EUI-64 from the MAC address
- /** \brief Bad MAC address syntax or conversion */
- struct SyntaxException : public std::exception
- { virtual char const * what() const throw() { return "invalid MAC address syntax"; } };
};
/** \brief Write MAC address
BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(mac2), "a1:b2:c3:d4:e5:f6" );
BOOST_CHECK_THROW( senf::MACAddress::from_string("1:2:3:4:5:6"),
- senf::MACAddress::SyntaxException );
+ senf::AddressSyntaxException );
BOOST_CHECK_THROW( senf::MACAddress::from_string("01:02:03:04:05"),
- senf::MACAddress::SyntaxException );
+ senf::AddressSyntaxException );
BOOST_CHECK_THROW( senf::MACAddress::from_string("01:02:03:04:05:z6"),
- senf::MACAddress::SyntaxException );
+ senf::AddressSyntaxException );
BOOST_CHECK_EQUAL( mac, senf::MACAddress::from_eui64(0xa1b2c3fffed4e5f6llu) );
- BOOST_CHECK_THROW( senf::MACAddress::from_eui64(0u), senf::MACAddress::SyntaxException );
+ BOOST_CHECK_THROW( senf::MACAddress::from_eui64(0u), senf::AddressSyntaxException );
}
///////////////////////////////cc.e////////////////////////////////////////