Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Socket / Protocols / Raw / LLAddressing.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief LLSocketAddress and LLAddressingPolicy public header
25  */
26
27 #ifndef HH_SENF_Socket_Protocols_Raw_LLAddressing_
28 #define HH_SENF_Socket_Protocols_Raw_LLAddressing_ 1
29
30 // Custom includes
31 #include <sys/socket.h>
32 #include <netpacket/packet.h>
33 #include <senf/Socket/Protocols/BSDAddressingPolicy.hh>
34 #include <senf/Socket/Protocols/BSDSocketAddress.hh>
35 #include "MACAddress.hh"
36
37 //#include "LLAddressing.mpp"
38 //#include "LLAddressing.ih"
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40
41 namespace senf {
42
43     /// \addtogroup addr_group
44     //\{
45
46     /** \brief Link local address
47
48         LLSocketAddress wraps the standard sockaddr_ll data type. An LLSocketAddress provides quite
49         some information, only part of which is necessary for sending packets. The LLSocketAddress
50         class only allows changing those fields which need to be changed. The other fields are
51         read-only. They are filled by the operating system when receiving a packet
52
53         \nosubgrouping
54      */
55     class LLSocketAddress
56         : public BSDSocketAddress
57     {
58     public:
59         static short const addressFamily = AF_PACKET;
60
61         /** \brief Valid pkttype() values
62
63             These are the possible values returned by pkttype()
64          */
65         enum PktType { Undefined = 0
66                      , Host      = PACKET_HOST      /**< Packet destined for this host */
67                      , Broadcast = PACKET_BROADCAST /**< Packet sent to the broadcast address */
68                      , Multicast = PACKET_MULTICAST /**< Packet sent to a (link local) multicast
69                                                          address */
70                      , OtherHost = PACKET_OTHERHOST /**< Packet sent to another host (promisc) */
71                      , Outgoing  = PACKET_OUTGOING  /**< Packet sent out from this host */
72         };
73
74         //-////////////////////////////////////////////////////////////////////////
75         ///\name Structors and default members
76         //\{
77
78         LLSocketAddress();              ///< Create empty address
79         explicit LLSocketAddress(unsigned proto, std::string const & iface="");
80                                         ///< Create address for \c bind()
81                                         /**< This constructs an LLSocketAddress valid for calling
82                                              PacketSocketHandle::bind() with.
83                                              \param[in] proto Protocol (Ethertype) to listen for
84                                              \param[in] iface Interface name to bind to */
85         explicit LLSocketAddress(std::string const & iface);
86                                         ///< Create address for \c bind()
87                                         /**< This constructs an LLSocketAddress valid for calling
88                                              \c PacketSocketHandle::bind() with.
89                                              \param[in] iface Interface name to bind to
90                                              \throws UnknownInterfaceException if \a iface is not
91                                                  a valid interface name. */
92
93         // This constructor is for sending packets
94         explicit LLSocketAddress(MACAddress const & addr, std::string const & iface="");
95                                         ///< Create address valid to send raw packets
96                                         /**< Addresses created with this constructor are valid for
97                                              use with \c PacketSocketHandle::sendto() on a \c
98                                              SOCK_DGRAM packet socket.
99                                              \param addr Address to send data to
100                                              \param iface Interface to send packet from
101                                              \throws UnknownInterfaceException if \a iface is not
102                                                  a valid interface name. */
103
104         LLSocketAddress(LLSocketAddress const & other);
105         LLSocketAddress& operator=(LLSocketAddress const & other);
106
107         //\}
108         //-////////////////////////////////////////////////////////////////////////
109
110         MACAddress address() const;     ///< Return address
111         std::string interface() const;  ///< Return interface name
112         unsigned protocol() const;      ///< Return address protocol (ethertype)
113
114         unsigned arptype() const;       ///< Return the arptype field (ARP hardware type)
115         PktType pkttype() const;        ///< Return type of packet
116
117         // The mutating interface is purposely restricted to allow only
118         // changing those members, which are sensible to be changed.
119
120         void address(MACAddress const & addr); ///< Change address
121         void interface(std::string const & iface); ///< Change interface
122                                                    /**< \throws UnknownInterfaceException if \a iface
123                                                              is not a valid interface name. */
124         void protocol(unsigned prot);   ///< Change protocol
125
126         using BSDSocketAddress::sockaddr_p;
127         using BSDSocketAddress::socklen_p;
128
129     private:
130         struct ::sockaddr_ll addr_;
131     };
132
133     //\}
134
135     /// \addtogroup policy_impl_group
136     //\{
137
138     /** \brief Addressing policy supporting link-local addressing
139
140         \par Address Type:
141             LLSocketAddress
142
143         This addressing policy implements generic link local
144         addressing. The predominant type of link local addressing is
145         Ethernet addressing.
146
147         Since the link layer does not support the notion of
148         connections, link local addresses do not support the connect()
149         or peer() members.
150      */
151     struct LLAddressingPolicy
152         : public BSDAddressingPolicy,
153           private BSDAddressingPolicyMixin<LLSocketAddress>
154     {
155         typedef LLSocketAddress Address;
156
157         using BSDAddressingPolicyMixin<LLSocketAddress>::local;
158         using BSDAddressingPolicyMixin<LLSocketAddress>::bind;
159     };
160
161     //\}
162
163     /** \brief Write link layer address
164         \related LLSocketAddress
165      */
166     std::ostream & operator<<(std::ostream & os, LLSocketAddress const & llAddr);
167 }
168
169 //-/////////////////////////////////////////////////////////////////////////////////////////////////
170 #include "LLAddressing.cci"
171 //#include "LLAddressing.ct"
172 //#include "LLAddressing.cti"
173 //#include "LLAddressing.mpp"
174 #endif
175
176 \f
177 // Local Variables:
178 // mode: c++
179 // fill-column: 100
180 // c-file-style: "senf"
181 // indent-tabs-mode: nil
182 // ispell-local-dictionary: "american"
183 // compile-command: "scons -u test"
184 // comment-column: 40
185 // End: