// $Id$
//
// Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@berlios.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
#include <net/if.h>
#include <boost/lexical_cast.hpp>
#include <boost/regex.hpp>
+#include "../../../Utils/senfassert.hh"
//#include "INetAddressing.mpp"
#define prefix_
clear();
unsigned i = addr.find(':');
if (i == std::string::npos)
- throw SyntaxException();
- address(INet4Address::from_string(std::string(addr,0,i)));
+ throw AddressSyntaxException();
try {
port(boost::lexical_cast< ::u_int16_t >(std::string(addr,i+1)));
}
catch (boost::bad_lexical_cast const &) {
- throw SyntaxException();
+ throw AddressSyntaxException();
}
+ address(INet4Address::from_string(std::string(addr,0,i)));
}
prefix_ senf::INet4SocketAddress::INet4SocketAddress(INet4Address const & addr, unsigned p)
///////////////////////////////////////////////////////////////////////////
// senf::INet6SocketAddress
+prefix_ senf::INet6SocketAddress::INet6SocketAddress(std::string const & addr,
+ INet6Address::Resolve_t resolve)
+{
+ clear();
+
+ // Format of addr: "[" address [ "%" interface ] "]" ":" port
+ // or: host ":" port
+
+ static boost::regex const addressRx ("(?:\\[([a-f0-9A-F:]+)(?:%(.+))?\\]|(.+)):([0-9]+)");
+ // Subexpression numbers:
+ enum { NumericAddr = 1,
+ ZoneId = 2,
+ Hostname = 3,
+ Port = 4 };
+
+ boost::smatch match;
+ if (! regex_match(addr, match, addressRx))
+ throw AddressSyntaxException();
+
+ if (match[ZoneId].matched)
+ assignIface(match[ZoneId]);
+
+ sockaddr_.sin6_port = htons(boost::lexical_cast<boost::uint16_t>(match[Port]));
+
+ 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)
const
{
if (sockaddr_.sin6_scope_id == 0)
return "";
char buffer[IFNAMSIZ];
- BOOST_ASSERT( if_indextoname(sockaddr_.sin6_scope_id,buffer) );
+#ifndef SENF_NO_DEBUG
+ SENF_ASSERT( if_indextoname(sockaddr_.sin6_scope_id,buffer) );
+#else
+ if_indextoname(sockaddr_.sin6_scope_id,buffer);
+#endif
return std::string(buffer);
}
-prefix_ void senf::INet6SocketAddress::assignAddr(std::string const & addr)
-{
- // Format of addr: "[" address [ "%" interface ] "]" ":" port
- // or: host ":" port
-
- static boost::regex const addressRx ("(?:\\[([a-f0-9A-F:]+)(?:%(.+))?\\]|(.+)):([0-9]+)");
- // Subexpression numbers:
- enum { NumericAddr = 1,
- ZoneId = 2,
- Hostname = 3,
- Port = 4 };
-
- boost::smatch match;
- if (! regex_match(addr, match, addressRx))
- throw SyntaxException();
-
- INet6Address a (INet6Address::from_string(
- match[NumericAddr].matched ? match[NumericAddr] : match[Hostname]));
- std::copy(a.begin(), a.end(), &sockaddr_.sin6_addr.s6_addr[0]);
-
- if (match[ZoneId].matched)
- assignIface(match[ZoneId]);
-
- sockaddr_.sin6_port = htons(boost::lexical_cast<boost::uint16_t>(match[Port]));
-}
-
prefix_ void senf::INet6SocketAddress::assignIface(std::string const & iface)
{
if (iface.empty())
else {
sockaddr_.sin6_scope_id = if_nametoindex(iface.c_str());
if (sockaddr_.sin6_scope_id == 0)
- throw SyntaxException();
+ throw AddressSyntaxException();
}
}