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.
23 // Definition of non-inline non-template functions
25 #include "LLAddressing.hh"
26 #include "LLAddressing.ih"
30 #include <sys/socket.h>
32 #include <boost/algorithm/string/classification.hpp>
33 #include <boost/algorithm/string/finder.hpp>
35 #include "Utils/Exception.hh"
37 //#include "LLAddressing.mpp"
39 ///////////////////////////////cc.p////////////////////////////////////////
41 prefix_ unsigned char satcom::lib::detail::hexnibble(char c)
49 throw InvalidLLSocketAddressException();
52 prefix_ std::string satcom::lib::LLSocketAddress::interface()
55 if (addr_.sll_ifindex == 0)
58 if (! ::if_indextoname(addr_.sll_ifindex, name))
59 throw InvalidLLSocketAddressException();
60 return std::string(name);
65 if (addr_.sll_halen == 0)
69 unsigned char const * i = &addr_.sll_addr[0];
71 s << std::hex << std::setw(2) << std::setfill('0') << unsigned(*i);
73 if (i == &addr_.sll_addr[addr_.sll_halen]) break;
82 prefix_ void satcom::lib::LLSocketAddress::address(std::string address)
84 typedef boost::split_iterator<std::string::iterator> StringSplitIterator;
85 StringSplitIterator i = boost::make_split_iterator(address, boost::token_finder(boost::is_any_of("-: ")));
86 unsigned char * j = &addr_.sll_addr[0];
87 for (; ! i.eof() && addr_.sll_halen<8; ++i, ++j, ++addr_.sll_halen) {
88 if ( i->size() != 2 || ! boost::all(*i, boost::is_xdigit()) )
89 throw InvalidLLSocketAddressException();
93 throw InvalidLLSocketAddressException();
97 prefix_ void satcom::lib::LLSocketAddress::interface(std::string interface)
99 if (! interface.empty()) {
100 addr_.sll_ifindex = if_nametoindex(interface.c_str());
101 if (addr_.sll_ifindex == 0)
102 throw InvalidLLSocketAddressException();
107 prefix_ satcom::lib::detail::LLAddressFromStringRange
108 satcom::lib::llAddress(std::string address)
110 detail::StringSplitIterator i =
111 boost::make_split_iterator(address, boost::token_finder(boost::is_any_of("-: ")));
112 detail::StringSplitIterator i_end;
114 detail::HexSplitIterator j (i,detail::HexConverter());
115 detail::HexSplitIterator j_end (i_end);
117 return detail::LLAddressFromStringRange(j,j_end);
120 ///////////////////////////////cc.e////////////////////////////////////////
122 //#include "LLAddressing.mpp"
127 // c-file-style: "satcom"