4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief LLSocketAddress and LLAddressingPolicy non-inline non-template implementation
27 #include "LLAddressing.hh"
28 #include "LLAddressing.ih"
32 #include <sys/socket.h>
34 #include <boost/algorithm/string/classification.hpp>
35 #include <boost/algorithm/string/finder.hpp>
37 #include "Utils/Exception.hh"
39 //#include "LLAddressing.mpp"
41 ///////////////////////////////cc.p////////////////////////////////////////
43 prefix_ unsigned char senf::detail::hexnibble(char c)
51 throw InvalidLLSocketAddressException();
54 prefix_ std::string senf::LLSocketAddress::interface()
57 if (addr_.sll_ifindex == 0)
60 if (! ::if_indextoname(addr_.sll_ifindex, name))
61 throw InvalidLLSocketAddressException();
62 return std::string(name);
67 if (addr_.sll_halen == 0)
71 unsigned char const * i = &addr_.sll_addr[0];
73 s << std::hex << std::setw(2) << std::setfill('0') << unsigned(*i);
75 if (i == &addr_.sll_addr[addr_.sll_halen]) break;
84 prefix_ void senf::LLSocketAddress::address(std::string address)
86 typedef boost::split_iterator<std::string::iterator> StringSplitIterator;
87 StringSplitIterator i = boost::make_split_iterator(address, boost::token_finder(boost::is_any_of("-: ")));
88 unsigned char * j = &addr_.sll_addr[0];
89 for (; ! i.eof() && addr_.sll_halen<8; ++i, ++j, ++addr_.sll_halen) {
90 if ( i->size() != 2 || ! boost::all(*i, boost::is_xdigit()) )
91 throw InvalidLLSocketAddressException();
95 throw InvalidLLSocketAddressException();
99 prefix_ void senf::LLSocketAddress::interface(std::string interface)
101 if (! interface.empty()) {
102 addr_.sll_ifindex = if_nametoindex(interface.c_str());
103 if (addr_.sll_ifindex == 0)
104 throw InvalidLLSocketAddressException();
109 prefix_ senf::detail::LLAddressFromStringRange
110 senf::llAddress(std::string address)
112 detail::StringSplitIterator i =
113 boost::make_split_iterator(address, boost::token_finder(boost::is_any_of("-: ")));
114 detail::StringSplitIterator i_end;
116 detail::HexSplitIterator j (i,detail::HexConverter());
117 detail::HexSplitIterator j_end (i_end);
119 return detail::LLAddressFromStringRange(j,j_end);
122 ///////////////////////////////cc.e////////////////////////////////////////
124 //#include "LLAddressing.mpp"
129 // c-file-style: "senf"