00001 // $Id: LLAddressing.hh 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 #ifndef HH_SENF_Socket_Protocols_Raw_LLAddressing_ 00028 #define HH_SENF_Socket_Protocols_Raw_LLAddressing_ 1 00029 00030 // Custom includes 00031 #include <sys/socket.h> 00032 #include <netpacket/packet.h> 00033 #include <senf/Socket/Protocols/BSDAddressingPolicy.hh> 00034 #include <senf/Socket/Protocols/BSDSocketAddress.hh> 00035 #include "MACAddress.hh" 00036 00037 //#include "LLAddressing.mpp" 00038 //#include "LLAddressing.ih" 00039 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00040 00041 namespace senf { 00042 00044 //\{ 00045 00055 class LLSocketAddress 00056 : public BSDSocketAddress 00057 { 00058 public: 00059 static short const addressFamily = AF_PACKET; 00060 00065 enum PktType { Undefined = 0 00066 , Host = PACKET_HOST 00067 , Broadcast = PACKET_BROADCAST 00068 , Multicast = PACKET_MULTICAST 00070 , OtherHost = PACKET_OTHERHOST 00071 , Outgoing = PACKET_OUTGOING 00072 }; 00073 00074 //-//////////////////////////////////////////////////////////////////////// 00076 //\{ 00077 00078 LLSocketAddress(); 00079 explicit LLSocketAddress(unsigned proto, std::string const & iface=""); 00081 00085 explicit LLSocketAddress(std::string const & iface); 00087 00093 // This constructor is for sending packets 00094 explicit LLSocketAddress(MACAddress const & addr, std::string const & iface=""); 00096 00104 LLSocketAddress(LLSocketAddress const & other); 00105 LLSocketAddress& operator=(LLSocketAddress const & other); 00106 00107 //\} 00108 //-//////////////////////////////////////////////////////////////////////// 00109 00110 MACAddress address() const; 00111 std::string interface() const; 00112 unsigned protocol() const; 00113 00114 unsigned arptype() const; 00115 PktType pkttype() const; 00116 00117 // The mutating interface is purposely restricted to allow only 00118 // changing those members, which are sensible to be changed. 00119 00120 void address(MACAddress const & addr); 00121 void interface(std::string const & iface); 00122 00124 void protocol(unsigned prot); 00125 00126 using BSDSocketAddress::sockaddr_p; 00127 using BSDSocketAddress::socklen_p; 00128 00129 private: 00130 struct ::sockaddr_ll addr_; 00131 }; 00132 00133 //\} 00134 00136 //\{ 00137 00151 struct LLAddressingPolicy 00152 : public BSDAddressingPolicy, 00153 private BSDAddressingPolicyMixin<LLSocketAddress> 00154 { 00155 typedef LLSocketAddress Address; 00156 00157 using BSDAddressingPolicyMixin<LLSocketAddress>::local; 00158 using BSDAddressingPolicyMixin<LLSocketAddress>::bind; 00159 }; 00160 00161 //\} 00162 00166 std::ostream & operator<<(std::ostream & os, LLSocketAddress const & llAddr); 00167 } 00168 00169 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00170 #include "LLAddressing.cci" 00171 //#include "LLAddressing.ct" 00172 //#include "LLAddressing.cti" 00173 //#include "LLAddressing.mpp" 00174 #endif 00175 00176 00177 // Local Variables: 00178 // mode: c++ 00179 // fill-column: 100 00180 // c-file-style: "senf" 00181 // indent-tabs-mode: nil 00182 // ispell-local-dictionary: "american" 00183 // compile-command: "scons -u test" 00184 // comment-column: 40 00185 // End: