removed some useless spaces; not very important, I know :)
[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
27 #ifndef HH_PacketSocketHandle_
28 #define HH_PacketSocketHandle_ 1
29
30 // Custom includes
31 #include "../../../Socket/SocketPolicy.hh"
32 #include "../../../Socket/SocketProtocol.hh"
33 #include "../../../Socket/ProtocolClientSocketHandle.hh"
34 #include "../../../Socket/FramingPolicy.hh"
35 #include "../../../Socket/CommunicationPolicy.hh"
36 #include "../../../Socket/ReadWritePolicy.hh"
37 #include "../../../Socket/Protocols/BSDSocketProtocol.hh"
38 #include "LLAddressing.hh"
39
40 //#include "PacketSocketHandle.mpp"
41 //#include "PacketSocketHandle.ih"
42 ///////////////////////////////hh.p////////////////////////////////////////
43
44 namespace senf {
45
46     /// \addtogroup concrete_protocol_group
47     /// @{
48
49     typedef MakeSocketPolicy<
50         LLAddressingPolicy,
51         DatagramFramingPolicy,
52         UnconnectedCommunicationPolicy,
53         ReadablePolicy,
54         WriteablePolicy
55         >::policy Packet_Policy;        ///< Policy of PacketProtocol
56
57     /** \brief Raw Packet-Socket access (Linux)
58
59         \par Socket Handle typedefs:
60         \ref PacketSocketHandle (ProtocolClientSocketHandle)
61
62         \par Policy Interface:
63         ClientSocketHandle::read(), ClientSocketHandle::readfrom(), ClientSocketHandle::writeto(),
64         ClientSocketHandle::bind(), ClientSocketHandle::local(), ClientSocketHandle::rcvbuf(),
65         ClientSocketHandle::sndbuf()
66
67         \par Address Type:
68         LLSocketAddress
69
70         The PacketProtocol provides access to the linux packet socket API. This API gives access to
71         the low level network packets. The packet socket allows read() and write() operations. The
72         PacketProtocol has no concept of a server socket.
73
74         This class is utilized as the protocol class of the ProtocolClientSocketHandle via the
75         Socket Handle typedefs above.
76      */
77     class PacketProtocol
78         : public ConcreteSocketProtocol<Packet_Policy, PacketProtocol>,
79           public BSDSocketProtocol
80     {
81     public:
82         enum SocketType { RawSocket, DatagramSocket };
83                                         ///< Socket types
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                                         /**< \note This member is implicitly called from the
105                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
106                                              constructor */
107         ///@}
108
109         ///\name Protocol Interface
110         ///@{
111
112         void mcAdd(std::string const & interface, MACAddress const & address) const;
113                                         ///< Enable reception of a multicast group
114                                         /**< mcAdd will join a new multicast group.
115
116                                              \param[in] interface interface with which to join
117                                              \param[in] address multicast address to join
118
119                                              \see \ref LLSocketAddress */
120         void mcDrop(std::string const & interface, MACAddress const & address) const;
121                                         ///< Disable reception of a multicast group
122                                         /**< \see \ref mcAdd() */
123
124         ///@}
125
126         ///\name Abstract Interface Implementation
127         ///@{
128
129         unsigned available() const;
130         bool eof() const;
131
132         ///@}
133     };
134
135     typedef ProtocolClientSocketHandle<PacketProtocol> PacketSocketHandle;
136                                         ///< SocketHandle of the PacketProtocol
137                                         /**< \related PacketPrototol */
138
139     /// @}
140 }
141
142 ///////////////////////////////hh.e////////////////////////////////////////
143 //#include "PacketSocketHandle.cci"
144 //#include "PacketSocketHandle.ct"
145 //#include "PacketSocketHandle.cti"
146 //#include "PacketSocketHandle.mpp"
147 #endif
148
149 \f
150 // Local Variables:
151 // mode: c++
152 // fill-column: 100
153 // c-file-style: "senf"
154 // indent-tabs-mode: nil
155 // ispell-local-dictionary: "american"
156 // compile-command: "scons -u test"
157 // comment-column: 40
158 // End: