c0f48efba1f1bad9dd404c6542a97334375d04ea
[senf.git] / senf / 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_SENF_Socket_Protocols_Raw_PacketSocketHandle_
28 #define HH_SENF_Socket_Protocols_Raw_PacketSocketHandle_ 1
29
30 // Custom includes
31 #include <senf/Socket/SocketPolicy.hh>
32 #include <senf/Socket/SocketProtocol.hh>
33 #include <senf/Socket/ProtocolClientSocketHandle.hh>
34 #include <senf/Socket/FramingPolicy.hh>
35 #include <senf/Socket/CommunicationPolicy.hh>
36 #include <senf/Socket/ReadWritePolicy.hh>
37 #include <senf/Socket/Protocols/BSDSocketProtocol.hh>
38 #include <senf/Socket/Protocols/DatagramSocketProtocol.hh>
39 #include "LLAddressing.hh"
40
41 //#include "PacketSocketHandle.mpp"
42 //#include "PacketSocketHandle.ih"
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
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()
66
67         \par Address Type:
68             LLSocketAddress
69
70         The PacketSocketProtocol 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         PacketSocketProtocol 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 PacketSocketProtocol
78         : public ConcreteSocketProtocol<Packet_Policy, PacketSocketProtocol>,
79           public DatagramSocketProtocol,
80           public BSDSocketProtocol
81     {
82     public:
83         enum SocketType { RawSocket, DatagramSocket };
84                                         ///< Socket types
85
86         ///\name Constructors
87         //\{
88         void init_client(SocketType type = RawSocket, int protocol = -1) const;
89                                         ///< Create packet socket
90                                         /**< The new socket will receive all packets of the given
91                                              IEEE 802.3 \a protocol. The socket will receive all
92                                              packets, if \a protocol is -1.
93
94                                              If \a type is \c RawSocket, the packet will include the
95                                              link-level header (the Ethernet header). Sent packets
96                                              must already include a well formed ll header.
97
98                                              If \a type is \c DatagramSocket, the link level header
99                                              will not be part of the packet data. The ll header will
100                                              be removed from received packets and a correct ll
101                                              header will be created on sent packets.
102
103                                              \param[in] type socket type
104                                              \param[in] protocol IEEE 802.3 protocol number */
105                                         /**< \note This member is implicitly called from the
106                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
107                                              constructor */
108         //\}
109
110         ///\name Protocol Interface
111         //\{
112
113         void mcAdd(std::string const & interface, MACAddress const & address) const;
114                                         ///< Enable reception of a multicast group
115                                         /**< mcAdd will join a new multicast group.
116
117                                              \param[in] interface interface with which to join
118                                              \param[in] address multicast address to join
119
120                                              \see \ref LLSocketAddress */
121         void mcDrop(std::string const & interface, MACAddress const & address) const;
122                                         ///< Disable reception of a multicast group
123                                         /**< \see \ref mcAdd() */
124
125         void promisc(std::string const & interface, bool mode) const;
126                                         ///< enable/disable promiscuous mode
127
128         //\}
129
130         ///\name Abstract Interface Implementation
131         //\{
132
133         unsigned available() const;
134         bool eof() const;
135
136         //\}
137     };
138
139     typedef ProtocolClientSocketHandle<PacketSocketProtocol> PacketSocketHandle;
140                                         ///< SocketHandle of the PacketSocketProtocol
141                                         /**< \related PacketPrototol */
142
143     //\}
144 }
145
146 //-/////////////////////////////////////////////////////////////////////////////////////////////////
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: