Move include files in debian packge into 'senf' subdirectory
[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      */
55     class LLSocketAddress
56     {
57     public:
58         /** \brief Valid pkttype() values
59
60             These are the possible values returned by arptype() 
61          */
62         enum PktType { Undefined = 0
63                      , Host      = PACKET_HOST      /**< Packet destined for this host */
64                      , Broadcast = PACKET_BROADCAST /**< Packet sent to the broadcast address */
65                      , Multicast = PACKET_MULTICAST /**< Packet sent to a (link local) multicast
66                                                          address */
67                      , OtherHost = PACKET_OTHERHOST /**< Packet sent to another host (promisc) */
68                      , Outgoing  = PACKET_OUTGOING  /**< Packet sent out from this host */
69         };
70         
71         LLSocketAddress();              ///< Create empty address
72         explicit LLSocketAddress(unsigned proto, std::string const & iface="");
73                                         ///< Create address for \c bind()
74                                         /**< This constructs an LLSocketAddress valid for calling
75                                              PacketSocketHandle::bind() with.
76                                              \param[in] proto Protocol (Ethertype) to listen for
77                                              \param[in] iface Interface name to bind to */
78         explicit LLSocketAddress(std::string const &iface);
79                                         ///< Create address for \c bind()
80                                         /**< This constructs an LLSocketAddress valid for calling
81                                              \c PacketSocketHandle::bind() with.
82                                              \param[in] iface Interface name to bind to */
83
84         // This constructor is for sending packets
85         explicit LLSocketAddress(MACAddress const & addr, std::string const & iface="");
86                                         ///< Create address valid to send raw packets
87                                         /**< Addresses created with this constructor are valid for
88                                              use with \c PacketSocketHandle::sendto() on a \c
89                                              SOCK_DGRAM packet socket.
90                                              \param addr Address to send data to
91                                              \param iface Interface to send packet from */
92
93         void clear();                   ///< Clear the address
94
95         unsigned protocol() const;      ///< Return address protocol (ethertype)
96         std::string interface() const;  ///< Return interface name
97         unsigned arptype() const;       ///< Return the hatype field (ARP hardware type)
98         PktType pkttype() const;        ///< Return type of packet
99         MACAddress address() const;     ///< Return address
100
101         // The mutating interface is purposely restricted to allow only
102         // changing those members, which are sensible to be changed.
103
104         void address(MACAddress const & addr); ///< Change address
105         void interface(std::string const & iface); ///< Change interface
106         void protocol(unsigned prot);   ///< Change protocol
107
108         ///\name Generic SocketAddress interface
109         ///@{
110
111         struct sockaddr * sockaddr_p();
112         struct sockaddr const * sockaddr_p() const;
113         unsigned sockaddr_len() const;
114
115         ///@}
116
117     private:
118         struct ::sockaddr_ll addr_;
119     };
120
121     /** \brief Signal invalid link local address syntax
122         \related LLSocketAddress
123      */
124     struct InvalidLLSocketAddressException : public std::exception
125     { char const * what() const throw() { return "invalid ll address"; } };
126
127     /// @}
128
129     /// \addtogroup policy_impl_group
130     /// @{
131
132     /** \brief Addressing policy supporting link-local addressing
133
134         \par Address Type:
135             LLSocketAddress
136
137         This addressing policy implements generic link local
138         addressing. The predominant type of link local addressing is
139         Ethernet addressing.
140
141         Since the link layer does not support the notion of
142         connections, link local addresses do not support the connect()
143         or peer() members.
144      */
145     struct LLAddressingPolicy
146         : public AddressingPolicyBase,
147           private GenericAddressingPolicy<LLSocketAddress>
148     {
149         typedef LLSocketAddress Address;
150
151         using GenericAddressingPolicy<LLSocketAddress>::local;
152         using GenericAddressingPolicy<LLSocketAddress>::bind;
153     };
154
155     /// @}
156 }
157
158 ///////////////////////////////hh.e////////////////////////////////////////
159 #include "LLAddressing.cci"
160 //#include "LLAddressing.ct"
161 //#include "LLAddressing.cti"
162 //#include "LLAddressing.mpp"
163 #endif
164
165 \f
166 // Local Variables:
167 // mode: c++
168 // fill-column: 100
169 // c-file-style: "senf"
170 // indent-tabs-mode: nil
171 // ispell-local-dictionary: "american"
172 // compile-command: "scons -u test"
173 // comment-column: 40
174 // End: