Blocked revisions 580 via svnmerge
[senf.git] / Socket / Protocols / INet / ConnectedRawInetSocketHandle.hh
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS) 
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY 
6 //     David Wagner <dw6@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 #ifndef CONNECTEDRAWINETSOCKETHANDLE_HH_
24 #define CONNECTEDRAWINETSOCKETHANDLE_HH_
25
26 // Custom includes
27 #include "INetProtocol.hh"
28 #include "RawInetProtocol.hh"
29 #include "../../../Socket/Protocols/BSDSocketProtocol.hh"
30 #include "../../../Socket/FramingPolicy.hh"
31 #include "../../../Socket/CommunicationPolicy.hh"
32 #include "../../../Socket/ReadWritePolicy.hh"
33 #include "../../../Socket/BufferingPolicy.hh"
34 #include "../../../Socket/ProtocolClientSocketHandle.hh"
35
36
37 ///////////////////////////////hh.p////////////////////////////////////////
38
39 namespace senf {
40
41     /// \addtogroup concrete_protocol_group
42     /// @{
43
44     typedef MakeSocketPolicy<
45         INet4AddressingPolicy,
46         DatagramFramingPolicy,
47         ConnectedCommunicationPolicy,
48         ReadablePolicy,
49         WriteablePolicy,
50         SocketBufferingPolicy
51         >::policy ConnectedRawV4Socket_Policy;   ///< Socket Policy of the Connected RawV4 Protocol
52
53     /** \brief IPv4 RAW Socket Protocol, connected
54
55         \par Socket Handle typedefs:
56             \ref ConnectedRawV4ClientSocketHandle (ProtocolClientSocketHandle)
57
58         \par Policy Interface:
59             ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
60             ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
61             ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
62
63         \par Address Type:
64             INet4Address
65
66         ConnectedRawV4SocketProtocol provides an internet protocol raw socket based on IPv4 addressing.
67         This socket will put data written to it onto the IPv4 layer: if you call writeto don't inlude the header!
68         On the other hand `read` will return the packet data including the IP header. 
69         This behaviour is strange and differs from the behaviour of IPv6 RAW sockets and should be changed in the future. 
70
71         This class is utilized as the protocol class of the ProtocolClientSocketHandle
72         via the Socket Handle typedefs above.
73
74         \see ConnectedRawV6SocketProtocol
75         \see RawV4SocketProtocol
76         \see RawV6SocketProtocol
77      */
78     class ConnectedRawV4SocketProtocol
79         : public ConcreteSocketProtocol<ConnectedRawV4Socket_Policy>,
80           public IPv4Protocol,
81           public RawInetProtocol,
82           public BSDSocketProtocol,
83           public AddressableBSDSocketProtocol//,
84 //          public senf::pool_alloc_mixin<RawV4Socket_Policy>
85     {
86     public:
87         ///////////////////////////////////////////////////////////////////////////
88         // internal interface
89
90         ///\name Constructors
91         ///@{
92
93         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
94                                         /**< \note This member is implicitly called from the
95                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
96                                              constructor */
97         void init_client(int const & protocol) const;       ///< Create unconnected client socket for protocol
98         
99         void init_client(int const & protocol, INet4SocketAddress const & address) const;
100                                         ///< Create client socket and connect
101                                         /**< Creates a new client socket for the given protocol and connects to the given
102                                              address.
103                                              \param[in] protocol Layer 4 protocol to filter for / to send 
104                                              \param[in] address local address to connect to */
105
106         ///@}
107         ///\name Abstract Interface Implementation
108
109         std::auto_ptr<SocketProtocol> clone() const;
110
111         ///@}
112     };
113
114     typedef ProtocolClientSocketHandle<ConnectedRawV4SocketProtocol> ConnectedRawV4ClientSocketHandle;
115
116
117
118
119 //////////////////////////////////////////////////////////////////// Raw IPv6 Socket //////////////////////////////////////
120     typedef MakeSocketPolicy<
121         INet6AddressingPolicy,
122         DatagramFramingPolicy,
123         ConnectedCommunicationPolicy,
124         ReadablePolicy,
125         WriteablePolicy,
126         SocketBufferingPolicy
127         >::policy ConnectedRawV6Socket_Policy;   ///< Socket Policy of the RawV6 Protocol
128
129     /** \brief IPv6 RAW Socket Protocol, connected
130
131         \par Socket Handle typedefs:
132         \ref ConnectedRawV6ClientSocketHandle (ProtocolClientSocketHandle)
133
134         \par Policy Interface: 
135             ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
136             ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
137             ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
138
139         \par Address Type:
140             INet6Address
141
142         ConnectedRawV6SocketProtocol provides an internet protocol raw socket based on IPv6 addressing which is connected to certain peer.
143         This socket will put data written to it onto the IPv6 layer: if you call writeto don't inlude the header!
144         On the other hand `read` will return the packet data on top of the IPv6 layer, excluding the IP header. 
145         Note: This behaviour is differs from the behaviour of IPv4 RAW sockets. 
146
147         This class is utilized as the protocol class of the ProtocolClientSocketHandle
148         via the Socket Handle typedefs above.
149
150         \see ConnectedRawV4SocketProtocol
151         \see RawV4SocketProtocol
152         \see RawV6SocketProtocol
153      */
154     class ConnectedRawV6SocketProtocol
155         : public ConcreteSocketProtocol<ConnectedRawV6Socket_Policy>,
156           public IPv6Protocol,
157           public RawInetProtocol,
158           public BSDSocketProtocol,
159           public AddressableBSDSocketProtocol//,
160 //          public senf::pool_alloc_mixin<RawV6SocketProtocol>
161     {
162     public:
163         ///////////////////////////////////////////////////////////////////////////
164         // internal interface
165
166         ///\name Constructors
167         ///@{
168
169         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
170                                         /**< \note This member is implicitly called from the
171                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
172                                              constructor */
173
174         void init_client(int const & protocol) const;       ///< Create unconnected client socket for protocol
175
176         void init_client(int const & protocol, INet6SocketAddress const & address) const;
177                                         ///< Create client socket and connect
178                                         /**< Creates a new client socket for the given protocol and connects to the given
179                                              address.
180                                              \param[in] protocol Layer 4 protocol to filter for / to send 
181                                              \param[in] address local address to connect to */
182                                         /**< \note This member is implicitly called from the
183                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
184                                              constructor (??) */
185
186         ///@}
187         ///\name Abstract Interface Implementation
188
189         std::auto_ptr<SocketProtocol> clone() const;
190
191         ///@}
192     };
193
194     typedef ProtocolClientSocketHandle<ConnectedRawV6SocketProtocol> ConnectedRawV6ClientSocketHandle;
195
196     /// @}
197
198 }
199
200 #endif /*CONNECTEDRAWINETSOCKETHANDLE_HH_*/