switch to new MPL based Fraunhofer FOKUS Public License
[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 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief PacketSocketProtocol and PacketSocketHandle public header
30  */
31
32 #ifndef HH_SENF_Socket_Protocols_Raw_PacketSocketHandle_
33 #define HH_SENF_Socket_Protocols_Raw_PacketSocketHandle_ 1
34
35 // Custom includes
36 #include <senf/Socket/SocketPolicy.hh>
37 #include <senf/Socket/SocketProtocol.hh>
38 #include <senf/Socket/ProtocolClientSocketHandle.hh>
39 #include <senf/Socket/FramingPolicy.hh>
40 #include <senf/Socket/CommunicationPolicy.hh>
41 #include <senf/Socket/ReadWritePolicy.hh>
42 #include <senf/Socket/Protocols/BSDSocketProtocol.hh>
43 #include <senf/Socket/Protocols/DatagramSocketProtocol.hh>
44 #include "LLAddressing.hh"
45
46 //#include "PacketSocketHandle.mpp"
47 //#include "PacketSocketHandle.ih"
48 //-/////////////////////////////////////////////////////////////////////////////////////////////////
49
50 namespace senf {
51
52     /// \addtogroup concrete_protocol_group
53     //\{
54
55     typedef MakeSocketPolicy<
56         LLAddressingPolicy,
57         DatagramFramingPolicy,
58         UnconnectedCommunicationPolicy,
59         ReadablePolicy,
60         WriteablePolicy
61         >::policy Packet_Policy;        ///< Policy of PacketSocketProtocol
62
63     /** \brief Raw Packet-Socket access (Linux)
64
65         \par Socket Handle typedefs:
66         \ref PacketSocketHandle (ProtocolClientSocketHandle)
67
68         \par Policy Interface:
69         ClientSocketHandle::read(), ClientSocketHandle::readfrom(), ClientSocketHandle::writeto(),
70         ClientSocketHandle::bind(), ClientSocketHandle::local()
71
72         \par Address Type:
73             LLSocketAddress
74
75         The PacketSocketProtocol provides access to the linux packet socket API. This API gives access to
76         the low level network packets. The packet socket allows read() and write() operations. The
77         PacketSocketProtocol has no concept of a server socket.
78
79         This class is utilized as the protocol class of the ProtocolClientSocketHandle via the
80         Socket Handle typedefs above.
81      */
82     class PacketSocketProtocol
83         : public ConcreteSocketProtocol<Packet_Policy, PacketSocketProtocol>,
84           public DatagramSocketProtocol,
85           public BSDSocketProtocol
86     {
87     public:
88         enum SocketType { RawSocket, DatagramSocket };
89                                         ///< Socket types
90
91         ///\name Constructors
92         //\{
93         void init_client(SocketType type = RawSocket, int protocol = -1) const;
94                                         ///< Create packet socket
95                                         /**< The new socket will receive all packets of the given
96                                              IEEE 802.3 \a protocol. The socket will receive all
97                                              packets, if \a protocol is -1.
98
99                                              If \a type is \c RawSocket, the packet will include the
100                                              link-level header (the Ethernet header). Sent packets
101                                              must already include a well formed ll header.
102
103                                              If \a type is \c DatagramSocket, the link level header
104                                              will not be part of the packet data. The ll header will
105                                              be removed from received packets and a correct ll
106                                              header will be created on sent packets.
107
108                                              \param[in] type socket type
109                                              \param[in] protocol IEEE 802.3 protocol number */
110                                         /**< \note This member is implicitly called from the
111                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
112                                              constructor */
113         //\}
114
115         ///\name Protocol Interface
116         //\{
117
118         void mcAdd(std::string const & interface, MACAddress const & address) const;
119                                         ///< Enable reception of a multicast group
120                                         /**< mcAdd will join a new multicast group.
121
122                                              \param[in] interface interface with which to join
123                                              \param[in] address multicast address to join
124
125                                              \see \ref LLSocketAddress */
126         void mcDrop(std::string const & interface, MACAddress const & address) const;
127                                         ///< Disable reception of a multicast group
128                                         /**< \see \ref mcAdd() */
129
130         void promisc(std::string const & interface, bool mode) const;
131                                         ///< enable/disable promiscuous mode
132
133         //\}
134
135         ///\name Abstract Interface Implementation
136         //\{
137
138         unsigned available() const;
139         bool eof() const;
140
141         //\}
142     };
143
144     typedef ProtocolClientSocketHandle<PacketSocketProtocol> PacketSocketHandle;
145                                         ///< SocketHandle of the PacketSocketProtocol
146                                         /**< \related PacketPrototol */
147
148     //\}
149 }
150
151 //-/////////////////////////////////////////////////////////////////////////////////////////////////
152 //#include "PacketSocketHandle.cci"
153 //#include "PacketSocketHandle.ct"
154 //#include "PacketSocketHandle.cti"
155 //#include "PacketSocketHandle.mpp"
156 #endif
157
158 \f
159 // Local Variables:
160 // mode: c++
161 // fill-column: 100
162 // c-file-style: "senf"
163 // indent-tabs-mode: nil
164 // ispell-local-dictionary: "american"
165 // compile-command: "scons -u test"
166 // comment-column: 40
167 // End: