6c08d9502c1980915fdf011356b882c548242221
[senf.git] / Socket / Protocols / INet / ConnectedRawInetSocketHandle.hh
1 // Copyright (C) 2007 
2 // Fraunhofer Institute for Open Communication Systems (FOKUS) 
3 // Kompetenzzentrum NETwork research (NET)
4 //     David Wagner <dw6@berlios.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 #ifndef CONNECTEDRAWINETSOCKETHANDLE_HH_
22 #define CONNECTEDRAWINETSOCKETHANDLE_HH_
23
24 // Custom includes
25 #include "INetProtocol.hh"
26 #include "RawInetProtocol.hh"
27 #include "../../../Socket/Protocols/BSDSocketProtocol.hh"
28 #include "../../../Socket/FramingPolicy.hh"
29 #include "../../../Socket/CommunicationPolicy.hh"
30 #include "../../../Socket/ReadWritePolicy.hh"
31 #include "../../../Socket/BufferingPolicy.hh"
32 #include "../../../Socket/ProtocolClientSocketHandle.hh"
33
34
35 ///////////////////////////////hh.p////////////////////////////////////////
36
37 namespace senf {
38
39     /// \addtogroup concrete_protocol_group
40     /// @{
41
42     typedef MakeSocketPolicy<
43         INet4AddressingPolicy,
44         DatagramFramingPolicy,
45         ConnectedCommunicationPolicy,
46         ReadablePolicy,
47         WriteablePolicy,
48         SocketBufferingPolicy
49         >::policy ConnectedRawV4Socket_Policy;   ///< Socket Policy of the Connected RawV4 Protocol
50
51     /** \brief IPv4 RAW Socket Protocol, connected
52
53         \par Socket Handle typedefs:
54             \ref ConnectedRawV4ClientSocketHandle (ProtocolClientSocketHandle)
55
56         \par Policy Interface:
57             ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
58             ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
59             ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
60
61         \par Address Type:
62             INet4Address
63
64         ConnectedRawV4SocketProtocol provides an internet protocol raw socket based on IPv4 addressing.
65         This socket will put data written to it onto the IPv4 layer: if you call writeto don't inlude the header!
66         On the other hand `read` will return the packet data including the IP header. 
67         This behaviour is strange and differs from the behaviour of IPv6 RAW sockets and should be changed in the future. 
68
69         This class is utilized as the protocol class of the ProtocolClientSocketHandle
70         via the Socket Handle typedefs above.
71
72         \see ConnectedRawV6SocketProtocol
73         \see RawV4SocketProtocol
74         \see RawV6SocketProtocol
75      */
76     class ConnectedRawV4SocketProtocol
77         : public ConcreteSocketProtocol<ConnectedRawV4Socket_Policy>,
78           public IPv4Protocol,
79           public RawInetProtocol,
80           public BSDSocketProtocol,
81           public AddressableBSDSocketProtocol//,
82 //          public senf::pool_alloc_mixin<RawV4Socket_Policy>
83     {
84     public:
85         ///////////////////////////////////////////////////////////////////////////
86         // internal interface
87
88         ///\name Constructors
89         ///@{
90
91         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
92                                         /**< \note This member is implicitly called from the
93                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
94                                              constructor */
95         void init_client(int const & protocol) const;       ///< Create unconnected client socket for protocol
96         
97         void init_client(int const & protocol, INet4SocketAddress const & address) const;
98                                         ///< Create client socket and connect
99                                         /**< Creates a new client socket for the given protocol and connects to the given
100                                              address.
101                                              \param[in] protocol Layer 4 protocol to filter for / to send 
102                                              \param[in] address local address to connect to */
103
104         ///@}
105         ///\name Abstract Interface Implementation
106
107         std::auto_ptr<SocketProtocol> clone() const;
108
109         ///@}
110     };
111
112     typedef ProtocolClientSocketHandle<ConnectedRawV4SocketProtocol> ConnectedRawV4ClientSocketHandle;
113
114
115
116
117 //////////////////////////////////////////////////////////////////// Raw IPv6 Socket //////////////////////////////////////
118     typedef MakeSocketPolicy<
119         INet6AddressingPolicy,
120         DatagramFramingPolicy,
121         ConnectedCommunicationPolicy,
122         ReadablePolicy,
123         WriteablePolicy,
124         SocketBufferingPolicy
125         >::policy ConnectedRawV6Socket_Policy;   ///< Socket Policy of the RawV6 Protocol
126
127     /** \brief IPv6 RAW Socket Protocol, connected
128
129         \par Socket Handle typedefs:
130         \ref ConnectedRawV6ClientSocketHandle (ProtocolClientSocketHandle)
131
132         \par Policy Interface: 
133             ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
134             ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
135             ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
136
137         \par Address Type:
138             INet6Address
139
140         ConnectedRawV6SocketProtocol provides an internet protocol raw socket based on IPv6 addressing which is connected to certain peer.
141         This socket will put data written to it onto the IPv6 layer: if you call writeto don't inlude the header!
142         On the other hand `read` will return the packet data on top of the IPv6 layer, excluding the IP header. 
143         Note: This behaviour is differs from the behaviour of IPv4 RAW sockets. 
144
145         This class is utilized as the protocol class of the ProtocolClientSocketHandle
146         via the Socket Handle typedefs above.
147
148         \see ConnectedRawV4SocketProtocol
149         \see RawV4SocketProtocol
150         \see RawV6SocketProtocol
151      */
152     class ConnectedRawV6SocketProtocol
153         : public ConcreteSocketProtocol<ConnectedRawV6Socket_Policy>,
154           public IPv6Protocol,
155           public RawInetProtocol,
156           public BSDSocketProtocol,
157           public AddressableBSDSocketProtocol//,
158 //          public senf::pool_alloc_mixin<RawV6SocketProtocol>
159     {
160     public:
161         ///////////////////////////////////////////////////////////////////////////
162         // internal interface
163
164         ///\name Constructors
165         ///@{
166
167         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
168                                         /**< \note This member is implicitly called from the
169                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
170                                              constructor */
171
172         void init_client(int const & protocol) const;       ///< Create unconnected client socket for protocol
173
174         void init_client(int const & protocol, INet6SocketAddress const & address) const;
175                                         ///< Create client socket and connect
176                                         /**< Creates a new client socket for the given protocol and connects to the given
177                                              address.
178                                              \param[in] protocol Layer 4 protocol to filter for / to send 
179                                              \param[in] address local address to connect to */
180                                         /**< \note This member is implicitly called from the
181                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
182                                              constructor (??) */
183
184         ///@}
185         ///\name Abstract Interface Implementation
186
187         std::auto_ptr<SocketProtocol> clone() const;
188
189         ///@}
190     };
191
192     typedef ProtocolClientSocketHandle<ConnectedRawV6SocketProtocol> ConnectedRawV6ClientSocketHandle;
193
194     /// @}
195
196 }
197
198 #endif /*CONNECTEDRAWINETSOCKETHANDLE_HH_*/