Add INPUT_FILTER support do Doxygen builder
[senf.git] / Socket / PacketSocketHandle.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 #ifndef HH_PacketSocketHandle_
24 #define HH_PacketSocketHandle_ 1
25
26 // Custom includes
27 #include "SocketPolicy.hh"
28 #include "SocketProtocol.hh"
29 #include "ProtocolClientSocketHandle.hh"
30 #include "LLAddressing.hh"
31 #include "FramingPolicy.hh"
32 #include "CommunicationPolicy.hh"
33 #include "ReadWritePolicy.hh"
34 #include "BufferingPolicy.hh"
35 #include "BSDSocketProtocol.hh"
36
37 //#include "PacketSocketHandle.mpp"
38 #include "PacketSocketHandle.ih"
39 ///////////////////////////////hh.p////////////////////////////////////////
40
41 namespace senf {
42
43     /// \addtogroup concrete_protocol_group
44     /// @{
45     
46     typedef MakeSocketPolicy<
47         LLAddressingPolicy,
48         DatagramFramingPolicy,
49         UnconnectedCommunicationPolicy,
50         ReadablePolicy,
51         WriteablePolicy,
52         SocketBufferingPolicy
53         >::policy Packet_Policy;        ///< Policy of PacketProtocol
54
55     /** \brief Raw Packet-Socket access (Linux)
56         
57         \par Socket Handle typedefs:
58         \ref PacketSocketHandle
59
60         \par Protocol Interface:
61         ClientSocketHandle::read(), ClientSocketHandle::readfrom(), ClientSocketHandle::writeto(),
62         ClientSocketHandle::bind(), ClientSocketHandle::local(), ClientSocketHandle::rcvbuf(),
63         ClientSocketHandle::sndbuf()
64
65         \par Address Type:
66         LLSocketAddress
67
68         The PacketProtocol provides access to the linux packet socket API. This API gives access to
69         the low level network packets. The packet socket allows read() and write() operations. The
70         PacketProtocol has no concept of a server socket.
71
72         \see \ref ProtocolClientSocketHandle \n
73              \ref protocol_group
74      */
75     class PacketProtocol 
76         : public ConcreteSocketProtocol<Packet_Policy>,
77           public BSDSocketProtocol
78     {
79     public:
80         enum SocketType { RawSocket, DatagramSocket };
81                                         ///< Socket types
82         enum PromiscMode { Promiscuous, AllMulticast, None };
83                                         ///< Interface modes
84
85         ///\name Constructors
86         ///@{
87         void init_client(SocketType type = RawSocket, int protocol = -1) const;
88                                         ///< Create packet socket
89                                         /**< The new socket will receive all packets of the given
90                                              IEEE 802.3 \a protocol. The socket will receive all
91                                              packets, if \a protocol is -1.
92
93                                              If \a type is \c RawSocket, the packet will include the
94                                              link-level header (the Ethernet header). Sent packets
95                                              must already include a well formed ll header.
96                                              
97                                              If \a type is \c DatagramSocket, the link level header
98                                              will not be part of the packet data. The ll header will
99                                              be removed from received packets and a correct ll
100                                              header will be created on sent packets.
101
102                                              \param[in] type socket type
103                                              \param[in] protocol IEEE 802.3 protocol number */
104         ///@}
105
106         ///\name Protocol Interface
107         ///@{
108         void promisc(std::string interface, PromiscMode mode) const;
109                                         ///< Change interface mode
110                                         /**< This member will change the reception on the given
111                                              interface. The modes available are
112
113                                              <dl>
114                                              <dt>\e None</dt><dd>No special mode set. Only receive
115                                              packets addressed to the interface or of joined
116                                              multicast groups</dd>
117                                              <dt>\e AllMulticast</dt><dd>Additionally receive all
118                                              multicast traffic</dd>
119                                              <dt>\e Promiscuous</dt><dd>Receive all packets on the
120                                              wire</dd>
121                                              </dl>
122
123                                              \param[in] interface interface to modify
124                                              \param[in] mode new interface mode */
125
126         // See LLSocketAddress for a discussion/rationale for ForwardRange here
127         template <class ForwardRange>
128         void mcAdd(std::string interface, ForwardRange const & address) const;
129                                         ///< Enable reception of a multicast group
130                                         /**< mcAdd will join a new multicast group. The address
131                                              parameter is specified as an arbitrary forward range
132                                              (see <a
133                                              href="http://www.boost.org/libs/range/index.html">Boost.Range</a>)
134                                              of up to 8 bytes. This  allows to initialize the
135                                              address from an arbitrary sources without excessive
136                                              copying. 
137
138                                              \param[in] interface interface with which to join
139                                              \param[in] address multicast address to join 
140
141                                              \see \ref LLSocketAddress */
142         template <class ForwardRange>
143         void mcDrop(std::string interface, ForwardRange const & address) const;
144                                         ///< Disable reception of a multicast group
145                                         /**< \see \ref mcAdd() */
146         ///@}
147
148         ///\name Abstract Interface Implementation
149         ///@{
150
151         std::auto_ptr<SocketProtocol> clone() const;
152         unsigned available() const;
153         bool eof() const;
154
155         ///@}
156
157     private:
158         template<class ForwardRange>
159         void do_mc(std::string interface, ForwardRange const & address, bool add) const;
160         void do_mc_i(std::string interface, detail::LLAddressCopier const & copier, bool add) const;
161     };
162
163     typedef ProtocolClientSocketHandle<PacketProtocol> PacketSocketHandle;
164                                         ///< SocketHandle of the PacketProtocol
165                                         /**< \related PacketPrototol */
166     
167     /// @}
168 }
169
170 ///////////////////////////////hh.e////////////////////////////////////////
171 //#include "PacketSocketHandle.cci"
172 #include "PacketSocketHandle.ct"
173 #include "PacketSocketHandle.cti"
174 //#include "PacketSocketHandle.mpp"
175 #endif
176
177 \f
178 // Local Variables:
179 // mode: c++
180 // c-file-style: "senf"
181 // fill-column: 100
182 // End: