switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / 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 //
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 //   David Wagner <dw6@berlios.de>
27
28 #ifndef CONNECTEDHH_SENF_Socket_Protocols_INet_RawINetSocketHandle_
29 #define CONNECTEDHH_SENF_Socket_Protocols_INet_RawINetSocketHandle_
30
31 // Custom includes
32 #include "INetAddressing.hh"
33 #include "RawINetSocketProtocol.hh"
34 #include <senf/Socket/Protocols/BSDSocketProtocol.hh>
35 #include <senf/Socket/Protocols/DatagramSocketProtocol.hh>
36 #include <senf/Socket/FramingPolicy.hh>
37 #include <senf/Socket/CommunicationPolicy.hh>
38 #include <senf/Socket/ReadWritePolicy.hh>
39 #include <senf/Socket/ProtocolClientSocketHandle.hh>
40
41
42 //-/////////////////////////////////////////////////////////////////////////////////////////////////
43
44 namespace senf {
45
46     /// \addtogroup concrete_protocol_group
47     //\{
48
49     typedef MakeSocketPolicy<
50         INet4AddressingPolicy,
51         DatagramFramingPolicy,
52         ConnectedCommunicationPolicy,
53         ReadablePolicy,
54         WriteablePolicy
55         >::policy ConnectedRawV4Socket_Policy;   ///< Socket Policy of the Connected RawV4 Protocol
56
57     /** \brief IPv4 RAW Socket Protocol, connected
58
59         \par Socket Handle typedefs:
60             \ref ConnectedRawV4ClientSocketHandle (ProtocolClientSocketHandle)
61
62         \par Policy Interface:
63             ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
64             ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer()
65
66         \par Address Type:
67             INet4SocketAddress
68
69         ConnectedRawV4SocketProtocol provides an Internet protocol raw socket based on IPv4
70         addressing. This socket will put data written to it onto the IPv4 layer: if you call
71         writeto don't include the header!
72
73         On the other hand `read` will return the packet data including the IP header.
74         This behaviour is strange and differs from the behaviour of IPv6 RAW sockets and should be
75         changed in the future.
76
77         This class is utilized as the protocol class of the ProtocolClientSocketHandle
78         via the Socket Handle typedefs above.
79
80         \attention If socket handle with ConnectedRawV4SocketProtocol is connected via
81             INet4SocketAddress, the port number is interpreted as protocol number for IPv4
82             layer. Please refer manpage: "man 7 raw".
83
84         \see ConnectedRawV6SocketProtocol
85         \see RawV4SocketProtocol
86         \see RawV6SocketProtocol
87      */
88     class ConnectedRawV4SocketProtocol
89         : public ConcreteSocketProtocol<ConnectedRawV4Socket_Policy, ConnectedRawV4SocketProtocol>,
90           public RawINetSocketProtocol,
91           public BSDSocketProtocol,
92           public DatagramSocketProtocol,
93           public AddressableBSDSocketProtocol
94     {
95     public:
96         //-////////////////////////////////////////////////////////////////////////
97         // internal interface
98
99         ///\name Constructors
100         //\{
101
102         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
103                                         /**< \note This member is implicitly called from the
104                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
105                                              constructor */
106         void init_client(int const & protocol) const;
107                                         ///< Create unconnected client socket for protocol
108
109         void init_client(int const & protocol, INet4SocketAddress const & address) const;
110                                         ///< Create client socket and connect
111                                         /**< Creates a new client socket for the given protocol and
112                                              connects to the given address.
113                                              \param[in] protocol Layer 4 protocol to filter for / to
114                                                  send
115                                              \param[in] address local address to connect to */
116
117         //\}
118     };
119
120     typedef ProtocolClientSocketHandle<ConnectedRawV4SocketProtocol>
121         ConnectedRawV4ClientSocketHandle;
122
123
124
125
126 //-/////////////////////////////////////////////////////////////////////////////////////////////////
127     typedef MakeSocketPolicy<
128         INet6AddressingPolicy,
129         DatagramFramingPolicy,
130         ConnectedCommunicationPolicy,
131         ReadablePolicy,
132         WriteablePolicy
133         >::policy ConnectedRawV6Socket_Policy;   ///< Socket Policy of the RawV6 Protocol
134
135     /** \brief IPv6 RAW Socket Protocol, connected
136
137         \par Socket Handle typedefs:
138         \ref ConnectedRawV6ClientSocketHandle (ProtocolClientSocketHandle)
139
140         \par Policy Interface:
141             ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(),
142             ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer()
143
144         \par Address Type:
145             INet6Address
146
147         ConnectedRawV6SocketProtocol provides an internet protocol raw socket based on IPv6
148         addressing which is connected to certain peer.  This socket will put data written to it onto
149         the IPv6 layer: if you call writeto don't include the header!  On the other hand `read` will
150         return the packet data on top of the IPv6 layer, excluding the IP header.  Note: This
151         behaviour is differs from the behaviour of IPv4 RAW sockets.
152
153         This class is utilized as the protocol class of the ProtocolClientSocketHandle
154         via the Socket Handle typedefs above.
155
156         \attention If socket handle with ConnectedRawV6SocketProtocol is connected via
157             INet6SocketAddress, the port number is interpreted as protocol number for IPv6
158             layer. Please refer manpage: "man 7 ipv6".
159
160         \see ConnectedRawV4SocketProtocol
161         \see RawV4SocketProtocol
162         \see RawV6SocketProtocol
163      */
164     class ConnectedRawV6SocketProtocol
165         : public ConcreteSocketProtocol<ConnectedRawV6Socket_Policy, ConnectedRawV6SocketProtocol>,
166           public RawINetSocketProtocol,
167           public BSDSocketProtocol,
168           public DatagramSocketProtocol,
169           public AddressableBSDSocketProtocol
170     {
171     public:
172         //-////////////////////////////////////////////////////////////////////////
173         // internal interface
174
175         ///\name Constructors
176         //\{
177
178         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
179                                         /**< \note This member is implicitly called from the
180                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
181                                              constructor */
182
183         void init_client(int const & protocol) const;
184                                         ///< Create unconnected client socket for protocol
185
186         void init_client(int const & protocol, INet6SocketAddress const & address) const;
187                                         ///< Create client socket and connect
188                                         /**< Creates a new client socket for the given protocol and
189                                              connects to the given address.
190                                              \param[in] protocol Layer 4 protocol to filter for / to
191                                                  send
192                                              \param[in] address local address to connect to
193                                              \note This member is implicitly called from the //
194                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
195                                              constructor (??) */
196
197         //\}
198     };
199
200     typedef ProtocolClientSocketHandle<ConnectedRawV6SocketProtocol>
201         ConnectedRawV6ClientSocketHandle;
202
203     //\}
204
205 }
206
207 #endif /*CONNECTEDHH_SENF_Socket_Protocols_INet_RawINetSocketHandle_*/
208
209 \f
210 // Local Variables:
211 // mode: c++
212 // fill-column: 100
213 // c-file-style: "senf"
214 // indent-tabs-mode: nil
215 // ispell-local-dictionary: "american"
216 // compile-command: "scons -u test"
217 // comment-column: 40
218 // End: