// $Id$ // // Copyright (C) 2006 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) // Kompetenzzentrum fuer Satelitenkommunikation (SatCom) // Stefan Bund // // 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 // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file \brief LLSocketAddress and LLAddressingPolicy non-inline template implementation */ #include "LLAddressing.ih" // Custom includes #include #include #include #define prefix_ ///////////////////////////////ct.p//////////////////////////////////////// template prefix_ void senf::LLSocketAddress::address(ForwardRange const & address) { if (boost::size(address) > sizeof(addr_.sll_addr)) throw InvalidLLSocketAddressException(); typename boost::range_const_iterator::type i (boost::begin(address)); ::memset(&addr_.sll_addr[0],sizeof(addr_.sll_addr),0); addr_.sll_halen = 0; for (; i != boost::end(address) && addr_.sll_halen<8; ++i, ++addr_.sll_halen) addr_.sll_addr[addr_.sll_halen] = *i; if (i != boost::end(address)) throw InvalidLLSocketAddressException(); } template prefix_ std::string senf::llAddress(ForwardRange const & address, typename boost::enable_if< boost::is_class >::type *) { if (boost::empty(address)) return std::string(); std::stringstream s; typename boost::range_const_iterator< ForwardRange >::type i (boost::begin(address)); while (1) { s << std::hex << std::setw(2) << std::setfill('0') << unsigned(*i); ++ i; if (i == boost::end(address)) break; s << '-'; } return s.str(); } template prefix_ unsigned char senf::detail::HexConverter::operator()(ForwardRange const & v) const { if (boost::size(v) != 2) throw InvalidLLSocketAddressException(); typename boost::range_iterator< ForwardRange >::type i (boost::begin(v)); unsigned char n1 = hexnibble(*i) << 4; return n1 + hexnibble(*(++i)); } ///////////////////////////////ct.e//////////////////////////////////////// #undef prefix_ // Local Variables: // mode: c++ // fill-column: 100 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // End: