switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Socket / Protocols / INet / RawINetSocketHandle.hh
1 // $Id: RawINetSocketHandle.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
29 #ifndef HH_SENF_Socket_Protocols_INet_RawINetSocketHandle_
30 #define HH_SENF_Socket_Protocols_INet_RawINetSocketHandle_
31
32
33 // Custom includes
34 #include "INetAddressing.hh"
35 #include "RawINetSocketProtocol.hh"
36 #include "MulticastSocketProtocol.hh"
37 #include <senf/Socket/Protocols/BSDSocketProtocol.hh>
38 #include <senf/Socket/Protocols/DatagramSocketProtocol.hh>
39 #include <senf/Socket/FramingPolicy.hh>
40 #include <senf/Socket/CommunicationPolicy.hh>
41 #include <senf/Socket/ReadWritePolicy.hh>
42 #include <senf/Socket/ProtocolClientSocketHandle.hh>
43
44
45 //-/////////////////////////////////////////////////////////////////////////////////////////////////
46
47 namespace senf {
48
49     /// \addtogroup concrete_protocol_group
50     //\{
51
52     typedef MakeSocketPolicy<
53         INet4AddressingPolicy,
54         DatagramFramingPolicy,
55         UnconnectedCommunicationPolicy,
56         ReadablePolicy,
57         WriteablePolicy
58         >::policy RawV4Socket_Policy;   ///< Socket Policy of the RawV4 Protocol
59
60     /** \brief IPv4 RAW Socket Protocol
61
62         \par Socket Handle typedefs:
63             \ref RawV4ClientSocketHandle (ProtocolClientSocketHandle)
64
65         \par Policy Interface:
66             ClientSocketHandle::read(), ClientSocketHandle::readfrom(),
67             ClientSocketHandle::writeto(), ClientSocketHandle::bind(), ClientSocketHandle::local()
68
69         \par Address Type:
70             INet4SocketAddress
71
72         RawV4SocketProtocol provides an internet protocol raw socket based on IPv4 addressing.
73         This socket will put data written to it onto the IPv4 layer: if you call writeto don't include the header!
74         On the other hand `read` will return the packet data including the IP header.
75         This behaviour is strange and differs from the behaviour of IPv6 RAW sockets and should be 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
81             If socket handle with RawV4SocketProtocol is connected via INet4SocketAddress, the port number
82             is interpreted as protocol number for IPv4 layer. Please refer manpage: "man 7 raw".
83
84         \see RawV6SocketProtocol
85      */
86     class RawV4SocketProtocol
87         : public ConcreteSocketProtocol<RawV4Socket_Policy, RawV4SocketProtocol>,
88           public RawINetSocketProtocol,
89           public BSDSocketProtocol,
90           public AddressableBSDSocketProtocol,
91           public DatagramSocketProtocol,
92           public INet4MulticastSocketProtocol
93     {
94     public:
95         //-////////////////////////////////////////////////////////////////////////
96         // internal interface
97
98         ///\name Constructors
99         //\{
100
101         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
102                                         /**< \note This member is implicitly called from the
103                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
104                                              constructor */
105         void init_client(int const & protocol) const;       ///< Create unconnected client socket for protocol
106
107         void init_client(int const & protocol, INet4SocketAddress const & address) const;
108                                         ///< Create client socket and bind
109                                         /**< Creates a new client socket for the given protocol and binds to the given
110                                              address.
111                                              \param[in] protocol Layer 4 protocol to filter for / to send
112                                              \param[in] address local address to bind to */
113
114         //\}
115     };
116
117     typedef ProtocolClientSocketHandle<RawV4SocketProtocol> RawV4ClientSocketHandle;
118
119
120
121
122 //-/////////////////////////////////////////////////////////////////////////////////////////////////
123     typedef MakeSocketPolicy<
124         INet6AddressingPolicy,
125         DatagramFramingPolicy,
126         UnconnectedCommunicationPolicy,
127         ReadablePolicy,
128         WriteablePolicy
129         >::policy RawV6Socket_Policy;   ///< Socket Policy of the RawV6 Protocol
130
131     /** \brief IPv6 RAW Socket Protocol
132
133         \par Socket Handle typedefs:
134         \ref RawV6ClientSocketHandle (ProtocolClientSocketHandle)
135
136         \par Policy Interface:
137             ClientSocketHandle::read(), ClientSocketHandle::readfrom(),
138             ClientSocketHandle::writeto(), ClientSocketHandle::bind(), ClientSocketHandle::local()
139
140         \par Address Type:
141             INet6Address
142
143         RawV6SocketProtocol provides an internet protocol raw socket based on IPv6 addressing.
144         This socket will put data written to it onto the IPv6 layer: if you call writeto don't include the header!
145         On the other hand `read` will return the packet data on top of the IPv6 layer, excluding the IP header.
146         Note: This behaviour is differs from the behaviour of IPv4 RAW sockets.
147
148         This class is utilized as the protocol class of the ProtocolClientSocketHandle
149         via the Socket Handle typedefs above.
150
151         \attention
152             If socket handle with ConnectedRawV6SocketProtocol is connected via INet6SocketAddress, the port number
153             is interpreted as protocol number for IPv6 layer. Please refer manpage: "man 7 ipv6".
154
155         \see RawV4SocketProtocol
156      */
157     class RawV6SocketProtocol
158         : public ConcreteSocketProtocol<RawV6Socket_Policy,RawV6SocketProtocol>,
159           public RawINetSocketProtocol,
160           public BSDSocketProtocol,
161           public AddressableBSDSocketProtocol,
162           public DatagramSocketProtocol,
163           public INet6MulticastSocketProtocol
164     {
165     public:
166         //-////////////////////////////////////////////////////////////////////////
167         // internal interface
168
169         ///\name Constructors
170         //\{
171
172         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
173                                         /**< \note This member is implicitly called from the
174                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
175                                              constructor */
176
177         void init_client(int const & protocol) const;       ///< Create unconnected client socket for protocol
178
179         void init_client(int const & protocol, INet6SocketAddress const & address) const;
180                                         ///< Create client socket and bind
181                                         /**< Creates a new client socket for the given protocol and binds to the given
182                                              address.
183                                              \param[in] protocol Layer 4 protocol to filter for / to send
184                                              \param[in] address local address to bind to */
185                                         /**< \note This member is implicitly called from the
186                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
187                                              constructor */
188
189         //\}
190     };
191
192     typedef ProtocolClientSocketHandle<RawV6SocketProtocol> RawV6ClientSocketHandle;
193
194     //\}
195
196 }
197
198 #endif /*HH_SENF_Socket_Protocols_INet_RawINetSocketHandle_*/