4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief LLSocketAddress and LLAddressingPolicy public header
32 #ifndef HH_SENF_Socket_Protocols_Raw_LLAddressing_
33 #define HH_SENF_Socket_Protocols_Raw_LLAddressing_ 1
36 #include <sys/socket.h>
37 #include <linux/if_packet.h>
38 #include <senf/Socket/Protocols/BSDAddressingPolicy.hh>
39 #include <senf/Socket/Protocols/BSDSocketAddress.hh>
40 #include "MACAddress.hh"
42 //#include "LLAddressing.mpp"
43 //#include "LLAddressing.ih"
44 //-/////////////////////////////////////////////////////////////////////////////////////////////////
48 /// \addtogroup addr_group
51 /** \brief Link local address
53 LLSocketAddress wraps the standard sockaddr_ll data type. An LLSocketAddress provides quite
54 some information, only part of which is necessary for sending packets. The LLSocketAddress
55 class only allows changing those fields which need to be changed. The other fields are
56 read-only. They are filled by the operating system when receiving a packet
61 : public BSDSocketAddress
64 static short const addressFamily = AF_PACKET;
66 /** \brief Valid pkttype() values
68 These are the possible values returned by pkttype()
70 enum PktType { Undefined = 0
71 , Host = PACKET_HOST /**< Packet destined for this host */
72 , Broadcast = PACKET_BROADCAST /**< Packet sent to the broadcast address */
73 , Multicast = PACKET_MULTICAST /**< Packet sent to a (link local) multicast
75 , OtherHost = PACKET_OTHERHOST /**< Packet sent to another host (promisc) */
76 , Outgoing = PACKET_OUTGOING /**< Packet sent out from this host */
79 //-////////////////////////////////////////////////////////////////////////
80 ///\name Structors and default members
83 LLSocketAddress(); ///< Create empty address
84 explicit LLSocketAddress(unsigned proto, std::string const & iface="");
85 ///< Create address for \c bind()
86 /**< This constructs an LLSocketAddress valid for calling
87 PacketSocketHandle::bind() with.
88 \param[in] proto Protocol (Ethertype) to listen for
89 \param[in] iface Interface name to bind to */
90 explicit LLSocketAddress(std::string const & iface);
91 ///< Create address for \c bind()
92 /**< This constructs an LLSocketAddress valid for calling
93 \c PacketSocketHandle::bind() with.
94 \param[in] iface Interface name to bind to
95 \throws UnknownInterfaceException if \a iface is not
96 a valid interface name. */
98 // This constructor is for sending packets
99 explicit LLSocketAddress(MACAddress const & addr, std::string const & iface="");
100 ///< Create address valid to send raw packets
101 /**< Addresses created with this constructor are valid for
102 use with \c PacketSocketHandle::sendto() on a \c
103 SOCK_DGRAM packet socket.
104 \param addr Address to send data to
105 \param iface Interface to send packet from
106 \throws UnknownInterfaceException if \a iface is not
107 a valid interface name. */
109 LLSocketAddress(LLSocketAddress const & other);
110 LLSocketAddress& operator=(LLSocketAddress const & other);
113 //-////////////////////////////////////////////////////////////////////////
115 MACAddress address() const; ///< Return address
116 std::string interface() const; ///< Return interface name
117 unsigned protocol() const; ///< Return address protocol (ethertype)
119 unsigned arptype() const; ///< Return the arptype field (ARP hardware type)
120 PktType pkttype() const; ///< Return type of packet
122 // The mutating interface is purposely restricted to allow only
123 // changing those members, which are sensible to be changed.
125 void address(MACAddress const & addr); ///< Change address
126 void interface(std::string const & iface); ///< Change interface
127 /**< \throws UnknownInterfaceException if \a iface
128 is not a valid interface name. */
129 void protocol(unsigned prot); ///< Change protocol
131 using BSDSocketAddress::sockaddr_p;
132 using BSDSocketAddress::socklen_p;
135 struct ::sockaddr_ll addr_;
140 /// \addtogroup policy_impl_group
143 /** \brief Addressing policy supporting link-local addressing
148 This addressing policy implements generic link local
149 addressing. The predominant type of link local addressing is
152 Since the link layer does not support the notion of
153 connections, link local addresses do not support the connect()
156 struct LLAddressingPolicy
157 : public BSDAddressingPolicy,
158 private BSDAddressingPolicyMixin<LLSocketAddress>
160 typedef LLSocketAddress Address;
162 using BSDAddressingPolicyMixin<LLSocketAddress>::local;
163 using BSDAddressingPolicyMixin<LLSocketAddress>::bind;
168 /** \brief Write link layer address
169 \related LLSocketAddress
171 std::ostream & operator<<(std::ostream & os, LLSocketAddress const & llAddr);
174 //-/////////////////////////////////////////////////////////////////////////////////////////////////
175 #include "LLAddressing.cci"
176 //#include "LLAddressing.ct"
177 //#include "LLAddressing.cti"
178 //#include "LLAddressing.mpp"
185 // c-file-style: "senf"
186 // indent-tabs-mode: nil
187 // ispell-local-dictionary: "american"
188 // compile-command: "scons -u test"
189 // comment-column: 40