00001 // $Id: LLAddressing.cc 1742 2010-11-04 14:51:56Z g0dil $ 00002 // 00003 // Copyright (C) 2006 00004 // Fraunhofer (FOKUS) 00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY 00006 // Stefan Bund <g0dil@berlios.de> 00007 // 00008 // This program is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the 00020 // Free Software Foundation, Inc., 00021 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00027 #include "LLAddressing.hh" 00028 //#include "LLAddressing.ih" 00029 00030 // Custom includes 00031 #include <net/if.h> 00032 #include <sys/socket.h> 00033 00034 #include <boost/algorithm/string/classification.hpp> 00035 #include <boost/algorithm/string/finder.hpp> 00036 00037 #include <senf/Socket/Protocols/AddressExceptions.hh> 00038 00039 //#include "LLAddressing.mpp" 00040 #define prefix_ 00041 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00042 00043 prefix_ std::string senf::LLSocketAddress::interface() 00044 const 00045 { 00046 if (addr_.sll_ifindex == 0) 00047 return std::string(); 00048 char name[IFNAMSIZ]; 00049 ::bzero(name, IFNAMSIZ); 00050 if (! ::if_indextoname(addr_.sll_ifindex, name)) 00051 throw UnknownInterfaceException(); 00052 return std::string(name); 00053 } 00054 00055 prefix_ void senf::LLSocketAddress::interface(std::string const & iface) 00056 { 00057 if (iface.empty()) 00058 addr_.sll_ifindex = 0; 00059 else { 00060 addr_.sll_ifindex = if_nametoindex(iface.c_str()); 00061 if (addr_.sll_ifindex == 0) 00062 throw UnknownInterfaceException(iface); 00063 } 00064 } 00065 00066 prefix_ std::ostream & senf::operator<<(std::ostream & os, LLSocketAddress const & llAddr) 00067 { 00068 os << "[" << llAddr.address() 00069 << '%' << llAddr.interface() 00070 << ' ' << llAddr.protocol() 00071 << ' ' << llAddr.arptype() 00072 << ( llAddr.pkttype() == senf::LLSocketAddress::Host ? " Host" : 00073 llAddr.pkttype() == senf::LLSocketAddress::Broadcast ? " Broadcast" : 00074 llAddr.pkttype() == senf::LLSocketAddress::Multicast ? " Multicast" : 00075 llAddr.pkttype() == senf::LLSocketAddress::OtherHost ? " OtherHost" : 00076 llAddr.pkttype() == senf::LLSocketAddress::Outgoing ? " Outgoing" : 00077 llAddr.pkttype() == senf::LLSocketAddress::Broadcast ? "Broadcast" : "" ) 00078 << "]"; 00079 return os; 00080 } 00081 00082 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00083 #undef prefix_ 00084 //#include "LLAddressing.mpp" 00085 00086 00087 // Local Variables: 00088 // mode: c++ 00089 // fill-column: 100 00090 // c-file-style: "senf" 00091 // indent-tabs-mode: nil 00092 // ispell-local-dictionary: "american" 00093 // compile-command: "scons -u test" 00094 // comment-column: 40 00095 // End: