0f2927990c6e062ace4c6a435f47678f3fd0bb17
[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 "INetSocketProtocol.hh"
28 #include "RawINetSocketProtocol.hh"
29 #include "../../../Socket/Protocols/BSDSocketProtocol.hh"
30 #include "../../../Socket/Protocols/DatagramSocketProtocol.hh"
31 #include "../../../Socket/FramingPolicy.hh"
32 #include "../../../Socket/CommunicationPolicy.hh"
33 #include "../../../Socket/ReadWritePolicy.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         >::policy ConnectedRawV4Socket_Policy;   ///< Socket Policy of the Connected RawV4 Protocol
51
52     /** \brief IPv4 RAW Socket Protocol, connected
53
54         \par Socket Handle typedefs:
55             \ref ConnectedRawV4ClientSocketHandle (ProtocolClientSocketHandle)
56
57         \par Policy Interface:
58             ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
59             ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
60             ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
61
62         \par Address Type:
63             INet4Address
64
65         ConnectedRawV4SocketProtocol provides an internet protocol raw socket based on IPv4 addressing.
66         This socket will put data written to it onto the IPv4 layer: if you call writeto don't inlude the header!
67         On the other hand `read` will return the packet data including the IP header. 
68         This behaviour is strange and differs from the behaviour of IPv6 RAW sockets and should be changed in the future. 
69
70         This class is utilized as the protocol class of the ProtocolClientSocketHandle
71         via the Socket Handle typedefs above.
72
73         \see ConnectedRawV6SocketProtocol
74         \see RawV4SocketProtocol
75         \see RawV6SocketProtocol
76      */
77     class ConnectedRawV4SocketProtocol
78         : public ConcreteSocketProtocol<ConnectedRawV4Socket_Policy, ConnectedRawV4SocketProtocol>,
79           public RawINetSocketProtocol,
80           public BSDSocketProtocol,
81           public DatagramSocketProtocol,
82           public AddressableBSDSocketProtocol
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     };
106
107     typedef ProtocolClientSocketHandle<ConnectedRawV4SocketProtocol> ConnectedRawV4ClientSocketHandle;
108
109
110
111
112 //////////////////////////////////////////////////////////////////// Raw IPv6 Socket //////////////////////////////////////
113     typedef MakeSocketPolicy<
114         INet6AddressingPolicy,
115         DatagramFramingPolicy,
116         ConnectedCommunicationPolicy,
117         ReadablePolicy,
118         WriteablePolicy
119         >::policy ConnectedRawV6Socket_Policy;   ///< Socket Policy of the RawV6 Protocol
120
121     /** \brief IPv6 RAW Socket Protocol, connected
122
123         \par Socket Handle typedefs:
124         \ref ConnectedRawV6ClientSocketHandle (ProtocolClientSocketHandle)
125
126         \par Policy Interface: 
127             ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
128             ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(),
129             ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
130
131         \par Address Type:
132             INet6Address
133
134         ConnectedRawV6SocketProtocol provides an internet protocol raw socket based on IPv6 addressing which is connected to certain peer.
135         This socket will put data written to it onto the IPv6 layer: if you call writeto don't inlude the header!
136         On the other hand `read` will return the packet data on top of the IPv6 layer, excluding the IP header. 
137         Note: This behaviour is differs from the behaviour of IPv4 RAW sockets. 
138
139         This class is utilized as the protocol class of the ProtocolClientSocketHandle
140         via the Socket Handle typedefs above.
141
142         \see ConnectedRawV4SocketProtocol
143         \see RawV4SocketProtocol
144         \see RawV6SocketProtocol
145      */
146     class ConnectedRawV6SocketProtocol
147         : public ConcreteSocketProtocol<ConnectedRawV6Socket_Policy, ConnectedRawV6SocketProtocol>,
148           public RawINetSocketProtocol,
149           public BSDSocketProtocol,
150           public DatagramSocketProtocol,
151           public AddressableBSDSocketProtocol
152     {
153     public:
154         ///////////////////////////////////////////////////////////////////////////
155         // internal interface
156
157         ///\name Constructors
158         ///@{
159
160         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
161                                         /**< \note This member is implicitly called from the
162                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
163                                              constructor */
164
165         void init_client(int const & protocol) const;       ///< Create unconnected client socket for protocol
166
167         void init_client(int const & protocol, INet6SocketAddress const & address) const;
168                                         ///< Create client socket and connect
169                                         /**< Creates a new client socket for the given protocol and connects to the given
170                                              address.
171                                              \param[in] protocol Layer 4 protocol to filter for / to send 
172                                              \param[in] address local address to connect to */
173                                         /**< \note This member is implicitly called from the
174                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
175                                              constructor (??) */
176
177         ///@}
178     };
179
180     typedef ProtocolClientSocketHandle<ConnectedRawV6SocketProtocol> ConnectedRawV6ClientSocketHandle;
181
182     /// @}
183
184 }
185
186 #endif /*CONNECTEDRAWINETSOCKETHANDLE_HH_*/