removed some useless spaces; not very important, I know :)
[senf.git] / Socket / Protocols / INet / ConnectedRawINetSocketHandle.hh
1 // $Id: ConnectedRawINetSocketHandle.hh 597 2008-01-15 09:16:20Z g0dil $
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/ProtocolClientSocketHandle.hh"
34
35
36 ///////////////////////////////hh.p////////////////////////////////////////
37
38 namespace senf {
39
40     /// \addtogroup concrete_protocol_group
41     /// @{
42
43     typedef MakeSocketPolicy<
44         INet4AddressingPolicy,
45         DatagramFramingPolicy,
46         ConnectedCommunicationPolicy,
47         ReadablePolicy,
48         WriteablePolicy
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, ConnectedRawV4SocketProtocol>,
78           public RawINetProtocol,
79           public BSDSocketProtocol,
80           public AddressableBSDSocketProtocol
81     {
82     public:
83         ///////////////////////////////////////////////////////////////////////////
84         // internal interface
85
86         ///\name Constructors
87         ///@{
88
89         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
90                                         /**< \note This member is implicitly called from the
91                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
92                                              constructor */
93         void init_client(int const & protocol) const;       ///< Create unconnected client socket for protocol
94         
95         void init_client(int const & protocol, INet4SocketAddress const & address) const;
96                                         ///< Create client socket and connect
97                                         /**< Creates a new client socket for the given protocol and connects to the given
98                                              address.
99                                              \param[in] protocol Layer 4 protocol to filter for / to send 
100                                              \param[in] address local address to connect to */
101
102         ///@}
103     };
104
105     typedef ProtocolClientSocketHandle<ConnectedRawV4SocketProtocol> ConnectedRawV4ClientSocketHandle;
106
107
108
109
110 //////////////////////////////////////////////////////////////////// Raw IPv6 Socket //////////////////////////////////////
111     typedef MakeSocketPolicy<
112         INet6AddressingPolicy,
113         DatagramFramingPolicy,
114         ConnectedCommunicationPolicy,
115         ReadablePolicy,
116         WriteablePolicy
117         >::policy ConnectedRawV6Socket_Policy;   ///< Socket Policy of the RawV6 Protocol
118
119     /** \brief IPv6 RAW Socket Protocol, connected
120
121         \par Socket Handle typedefs:
122         \ref ConnectedRawV6ClientSocketHandle (ProtocolClientSocketHandle)
123
124         \par Policy Interface: 
125             ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
126             ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
127             ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
128
129         \par Address Type:
130             INet6Address
131
132         ConnectedRawV6SocketProtocol provides an internet protocol raw socket based on IPv6 addressing which is connected to certain peer.
133         This socket will put data written to it onto the IPv6 layer: if you call writeto don't inlude the header!
134         On the other hand `read` will return the packet data on top of the IPv6 layer, excluding the IP header. 
135         Note: This behaviour is differs from the behaviour of IPv4 RAW sockets. 
136
137         This class is utilized as the protocol class of the ProtocolClientSocketHandle
138         via the Socket Handle typedefs above.
139
140         \see ConnectedRawV4SocketProtocol
141         \see RawV4SocketProtocol
142         \see RawV6SocketProtocol
143      */
144     class ConnectedRawV6SocketProtocol
145         : public ConcreteSocketProtocol<ConnectedRawV6Socket_Policy, ConnectedRawV6SocketProtocol>,
146           public RawINetProtocol,
147           public BSDSocketProtocol,
148           public AddressableBSDSocketProtocol
149     {
150     public:
151         ///////////////////////////////////////////////////////////////////////////
152         // internal interface
153
154         ///\name Constructors
155         ///@{
156
157         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
158                                         /**< \note This member is implicitly called from the
159                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
160                                              constructor */
161
162         void init_client(int const & protocol) const;       ///< Create unconnected client socket for protocol
163
164         void init_client(int const & protocol, INet6SocketAddress const & address) const;
165                                         ///< Create client socket and connect
166                                         /**< Creates a new client socket for the given protocol and connects to the given
167                                              address.
168                                              \param[in] protocol Layer 4 protocol to filter for / to send 
169                                              \param[in] address local address to connect to */
170                                         /**< \note This member is implicitly called from the
171                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
172                                              constructor (??) */
173
174         ///@}
175     };
176
177     typedef ProtocolClientSocketHandle<ConnectedRawV6SocketProtocol> ConnectedRawV6ClientSocketHandle;
178
179     /// @}
180
181 }
182
183 #endif /*CONNECTEDRAWINETSOCKETHANDLE_HH_*/