NEW FILE HEADER / COPYRIGHT FORMAT
[senf.git] / Socket / Protocols / INet / RawInetSocketHandle.hh
1 // Copyright (C) 2007 
2 // Fraunhofer Institute for Open Communication Systems (FOKUS) 
3 // Kompetenzzentrum NETwork research (NET)
4 //     David Wagner <dw6@berlios.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 #ifndef RAWINETSOCKETHANDLE_HH_
22 #define RAWINETSOCKETHANDLE_HH_
23
24
25 // Custom includes
26 #include "INetProtocol.hh"
27 #include "RawInetProtocol.hh"
28 #include "../../../Socket/Protocols/BSDSocketProtocol.hh"
29 #include "../../../Socket/FramingPolicy.hh"
30 #include "../../../Socket/CommunicationPolicy.hh"
31 #include "../../../Socket/ReadWritePolicy.hh"
32 #include "../../../Socket/BufferingPolicy.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         UnconnectedCommunicationPolicy,
47         ReadablePolicy,
48         WriteablePolicy,
49         SocketBufferingPolicy
50         >::policy RawV4Socket_Policy;   ///< Socket Policy of the RawV4 Protocol
51
52     /** \brief IPv4 RAW Socket Protocol
53
54         \par Socket Handle typedefs:
55             \ref RawV4ClientSocketHandle (ProtocolClientSocketHandle)
56
57         \par Policy Interface:
58             ClientSocketHandle::read(), ClientSocketHandle::readfrom(),
59             ClientSocketHandle::writeto(), ClientSocketHandle::bind(), ClientSocketHandle::local(),
60             ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
61
62         \par Address Type:
63             INet4Address
64
65         RawV4SocketProtocol 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 RawV6SocketProtocol
74      */
75     class RawV4SocketProtocol
76         : public ConcreteSocketProtocol<RawV4Socket_Policy>,
77           public IPv4Protocol,
78           public RawInetProtocol,
79           public BSDSocketProtocol,
80           public AddressableBSDSocketProtocol//,
81 //          public senf::pool_alloc_mixin<RawV4Socket_Policy>
82     {
83     public:
84         ///////////////////////////////////////////////////////////////////////////
85         // internal interface
86
87         ///\name Constructors
88         ///@{
89
90         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
91                                         /**< \note This member is implicitly called from the
92                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
93                                              constructor */
94         void init_client(int const & protocol) const;       ///< Create unconnected client socket for protocol
95         
96         void init_client(int const & protocol, INet4SocketAddress const & address) const;
97                                         ///< Create client socket and bind
98                                         /**< Creates a new client socket for the given protocol and binds to the given
99                                              address.
100                                              \param[in] protocol Layer 4 protocol to filter for / to send 
101                                              \param[in] address local address to bind to */
102
103         ///@}
104         ///\name Abstract Interface Implementation
105
106         std::auto_ptr<SocketProtocol> clone() const;
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         SocketBufferingPolicy
124         >::policy RawV6Socket_Policy;   ///< Socket Policy of the RawV6 Protocol
125
126     /** \brief IPv6 RAW Socket Protocol
127
128         \par Socket Handle typedefs:
129         \ref RawV6ClientSocketHandle (ProtocolClientSocketHandle)
130
131         \par Policy Interface: 
132             ClientSocketHandle::read(), ClientSocketHandle::readfrom(),
133             ClientSocketHandle::writeto(), ClientSocketHandle::bind(), ClientSocketHandle::local(),
134             ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
135
136         \par Address Type:
137             INet6Address
138
139         RawV6SocketProtocol provides an internet protocol raw socket based on IPv6 addressing.
140         This socket will put data written to it onto the IPv6 layer: if you call writeto don't inlude the header!
141         On the other hand `read` will return the packet data on top of the IPv6 layer, excluding the IP header. 
142         Note: This behaviour is differs from the behaviour of IPv4 RAW sockets. 
143
144         This class is utilized as the protocol class of the ProtocolClientSocketHandle
145         via the Socket Handle typedefs above.
146
147         \see RawV4SocketProtocol
148      */
149     class RawV6SocketProtocol
150         : public ConcreteSocketProtocol<RawV6Socket_Policy>,
151           public IPv6Protocol,
152           public RawInetProtocol,
153           public BSDSocketProtocol,
154           public AddressableBSDSocketProtocol//,
155 //          public senf::pool_alloc_mixin<RawV6SocketProtocol>
156     {
157     public:
158         ///////////////////////////////////////////////////////////////////////////
159         // internal interface
160
161         ///\name Constructors
162         ///@{
163
164         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
165                                         /**< \note This member is implicitly called from the
166                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
167                                              constructor */
168
169         void init_client(int const & protocol) const;       ///< Create unconnected client socket for protocol
170
171         void init_client(int const & protocol, INet6SocketAddress const & address) const;
172                                         ///< Create client socket and bind
173                                         /**< Creates a new client socket for the given protocol and binds to the given
174                                              address.
175                                              \param[in] protocol Layer 4 protocol to filter for / to send 
176                                              \param[in] address local address to bind to */
177                                         /**< \note This member is implicitly called from the
178                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
179                                              constructor */
180
181         ///@}
182         ///\name Abstract Interface Implementation
183
184         std::auto_ptr<SocketProtocol> clone() const;
185
186         ///@}
187     };
188
189     typedef ProtocolClientSocketHandle<RawV6SocketProtocol> RawV6ClientSocketHandle;
190
191     /// @}
192
193 }
194
195 #endif /*RAWINETSOCKETHANDLE_HH_*/