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