00001 // $Id: LLAddressing.cci 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 // Custom includes 00028 #include <sys/socket.h> 00029 #include <netinet/in.h> 00030 00031 #define prefix_ inline 00032 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00033 00034 prefix_ senf::LLSocketAddress::LLSocketAddress() 00035 : BSDSocketAddress (sizeof(sockaddr_ll), AF_PACKET) 00036 {} 00037 00038 prefix_ senf::LLSocketAddress::LLSocketAddress(unsigned prot, std::string const & iface) 00039 : BSDSocketAddress (sizeof(sockaddr_ll), AF_PACKET) 00040 { 00041 protocol(prot); 00042 interface(iface); 00043 } 00044 00045 prefix_ senf::LLSocketAddress::LLSocketAddress(std::string const &iface) 00046 : BSDSocketAddress (sizeof(sockaddr_ll), AF_PACKET) 00047 { 00048 interface(iface); 00049 } 00050 00051 prefix_ senf::LLSocketAddress::LLSocketAddress(MACAddress const & addr, 00052 std::string const & iface) 00053 : BSDSocketAddress (sizeof(sockaddr_ll), AF_PACKET) 00054 { 00055 address(addr); 00056 interface(iface); 00057 } 00058 00059 prefix_ senf::LLSocketAddress::LLSocketAddress(const LLSocketAddress& other) 00060 : BSDSocketAddress (other) 00061 {} 00062 00063 prefix_ senf::LLSocketAddress& senf::LLSocketAddress::operator=(const LLSocketAddress& other) 00064 { 00065 BSDSocketAddress::operator=(other); 00066 return *this; 00067 } 00068 00069 prefix_ unsigned senf::LLSocketAddress::protocol() 00070 const 00071 { 00072 return ntohs(addr_.sll_protocol); 00073 } 00074 00075 prefix_ void senf::LLSocketAddress::protocol(unsigned prot) 00076 { 00077 addr_.sll_protocol = htons(prot); 00078 } 00079 00080 prefix_ unsigned senf::LLSocketAddress::arptype() 00081 const 00082 { 00083 return ntohs(addr_.sll_hatype); 00084 } 00085 00086 prefix_ senf::LLSocketAddress::PktType senf::LLSocketAddress::pkttype() 00087 const 00088 { 00089 return PktType(ntohs(addr_.sll_pkttype)); 00090 } 00091 00092 prefix_ senf::MACAddress senf::LLSocketAddress::address() 00093 const 00094 { 00095 return MACAddress::from_data(&addr_.sll_addr[0]); 00096 } 00097 00098 prefix_ void senf::LLSocketAddress::address(MACAddress const & addr) 00099 { 00100 std::copy(addr.begin(), addr.end(), &addr_.sll_addr[0]); 00101 } 00102 00103 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00104 #undef prefix_ 00105 00106 00107 // Local Variables: 00108 // mode: c++ 00109 // fill-column: 100 00110 // c-file-style: "senf" 00111 // indent-tabs-mode: nil 00112 // ispell-local-dictionary: "american" 00113 // compile-command: "scons -u test" 00114 // comment-column: 40 00115 // End: