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