Merged revisions 570-572,574-575,578-579,581-595,598-611 via svnmerge from
[senf.git] / Socket / Protocols / Raw / PacketSocketHandle.hh
1 // $Id:PacketSocketHandle.hh 218 2007-03-20 14:39:32Z tho $
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 PacketProtocol and PacketSocketHandle public header
25
26     \todo Implement global promisc() helper based on ioctl() interface.
27  */
28
29 #ifndef HH_PacketSocketHandle_
30 #define HH_PacketSocketHandle_ 1
31
32 // Custom includes
33 #include "../../../Socket/SocketPolicy.hh"
34 #include "../../../Socket/SocketProtocol.hh"
35 #include "../../../Socket/ProtocolClientSocketHandle.hh"
36 #include "../../../Socket/FramingPolicy.hh"
37 #include "../../../Socket/CommunicationPolicy.hh"
38 #include "../../../Socket/ReadWritePolicy.hh"
39 #include "../../../Socket/Protocols/BSDSocketProtocol.hh"
40 #include "LLAddressing.hh"
41
42 //#include "PacketSocketHandle.mpp"
43 //#include "PacketSocketHandle.ih"
44 ///////////////////////////////hh.p////////////////////////////////////////
45
46 namespace senf {
47
48     /// \addtogroup concrete_protocol_group
49     /// @{
50
51     typedef MakeSocketPolicy<
52         LLAddressingPolicy,
53         DatagramFramingPolicy,
54         UnconnectedCommunicationPolicy,
55         ReadablePolicy,
56         WriteablePolicy
57         >::policy Packet_Policy;        ///< Policy of PacketProtocol
58
59     /** \brief Raw Packet-Socket access (Linux)
60
61         \par Socket Handle typedefs:
62         \ref PacketSocketHandle (ProtocolClientSocketHandle)
63
64         \par Policy Interface:
65         ClientSocketHandle::read(), ClientSocketHandle::readfrom(), ClientSocketHandle::writeto(),
66         ClientSocketHandle::bind(), ClientSocketHandle::local(), ClientSocketHandle::rcvbuf(),
67         ClientSocketHandle::sndbuf()
68
69         \par Address Type:
70         LLSocketAddress
71
72         The PacketProtocol provides access to the linux packet socket API. This API gives access to
73         the low level network packets. The packet socket allows read() and write() operations. The
74         PacketProtocol has no concept of a server socket.
75
76         This class is utilized as the protocol class of the ProtocolClientSocketHandle via the
77         Socket Handle typedefs above.
78      */
79     class PacketProtocol
80         : public ConcreteSocketProtocol<Packet_Policy>,
81           public BSDSocketProtocol,
82           public senf::pool_alloc_mixin<PacketProtocol>
83     {
84     public:
85         enum SocketType { RawSocket, DatagramSocket };
86                                         ///< Socket types
87
88         ///\name Constructors
89         ///@{
90         void init_client(SocketType type = RawSocket, int protocol = -1) const;
91                                         ///< Create packet socket
92                                         /**< The new socket will receive all packets of the given
93                                              IEEE 802.3 \a protocol. The socket will receive all
94                                              packets, if \a protocol is -1.
95
96                                              If \a type is \c RawSocket, the packet will include the
97                                              link-level header (the Ethernet header). Sent packets
98                                              must already include a well formed ll header.
99
100                                              If \a type is \c DatagramSocket, the link level header
101                                              will not be part of the packet data. The ll header will
102                                              be removed from received packets and a correct ll
103                                              header will be created on sent packets.
104
105                                              \param[in] type socket type
106                                              \param[in] protocol IEEE 802.3 protocol number */
107                                         /**< \note This member is implicitly called from the
108                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
109                                              constructor */
110         ///@}
111
112         ///\name Protocol Interface
113         ///@{
114
115         void mcAdd(std::string const & interface, MACAddress const & address) const;
116                                         ///< Enable reception of a multicast group
117                                         /**< mcAdd will join a new multicast group.
118
119                                              \param[in] interface interface with which to join
120                                              \param[in] address multicast address to join
121
122                                              \see \ref LLSocketAddress */
123         void mcDrop(std::string const & interface, MACAddress const & address) const;
124                                         ///< Disable reception of a multicast group
125                                         /**< \see \ref mcAdd() */
126
127         ///@}
128
129         ///\name Abstract Interface Implementation
130         ///@{
131
132         std::auto_ptr<SocketProtocol> clone() const;
133         unsigned available() const;
134         bool eof() const;
135
136         ///@}
137     };
138
139     typedef ProtocolClientSocketHandle<PacketProtocol> PacketSocketHandle;
140                                         ///< SocketHandle of the PacketProtocol
141                                         /**< \related PacketPrototol */
142
143     /// @}
144 }
145
146 ///////////////////////////////hh.e////////////////////////////////////////
147 //#include "PacketSocketHandle.cci"
148 //#include "PacketSocketHandle.ct"
149 //#include "PacketSocketHandle.cti"
150 //#include "PacketSocketHandle.mpp"
151 #endif
152
153 \f
154 // Local Variables:
155 // mode: c++
156 // fill-column: 100
157 // c-file-style: "senf"
158 // indent-tabs-mode: nil
159 // ispell-local-dictionary: "american"
160 // compile-command: "scons -u test"
161 // comment-column: 40
162 // End: