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