adding PF_INET[6], SOCK_RAW sockets called RawV[4|6]ClientSocketHandle while naming...
[senf.git] / Socket / Protocols / INet / RawInetSocketHandle.hh
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum NETwork research (NET)
4 //     David Wagner <david.wagner@fokus.fraunhofer.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 //#include "UDPSocketHandle.mpp"
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
67         This class is utilized as the protocol class of the ProtocolClientSocketHandle
68         via the Socket Handle typedefs above.
69
70         \see RawV6SocketProtocol
71      */
72     class RawV4SocketProtocol
73         : public ConcreteSocketProtocol<RawV4Socket_Policy>,
74           public IPv4Protocol,
75           public RawInetProtocol,
76           public BSDSocketProtocol,
77           public AddressableBSDSocketProtocol//,
78 //          public senf::pool_alloc_mixin<RawV4Socket_Policy>
79     {
80     public:
81         ///////////////////////////////////////////////////////////////////////////
82         // internal interface
83
84         ///\name Constructors
85         ///@{
86
87         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
88                                         /**< \note This member is implicitly called from the
89                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
90                                              constructor */
91         void init_client(int const & protocol) const;       ///< Create unconnected client socket for protocol
92         
93         void init_client(int const & protocol, INet4SocketAddress const & address) const;
94                                         ///< Create client socket and bind
95                                         /**< Creates a new client socket for the given protocol and binds to the given
96                                              address.
97                                              \param[in] protocol Layer 4 protocol to filter for / to send 
98                                              \param[in] address local address to bind to */
99
100         ///@}
101         ///\name Abstract Interface Implementation
102
103         std::auto_ptr<SocketProtocol> clone() const;
104
105         ///@}
106     };
107
108     typedef ProtocolClientSocketHandle<RawV4SocketProtocol> RawV4ClientSocketHandle;
109
110
111
112
113 //////////////////////////////////////////////////////////////////// Raw IPv6 Socket //////////////////////////////////////
114     typedef MakeSocketPolicy<
115         INet6AddressingPolicy,
116         DatagramFramingPolicy,
117         UnconnectedCommunicationPolicy,
118         ReadablePolicy,
119         WriteablePolicy,
120         SocketBufferingPolicy
121         >::policy RawV6Socket_Policy;   ///< Socket Policy of the RawV6 Protocol
122
123     /** \brief IPv6 RAW Socket Protocol
124
125         \par Socket Handle typedefs:
126         \ref RawV6ClientSocketHandle (ProtocolClientSocketHandle)
127
128         \par Policy Interface: 
129             ClientSocketHandle::read(), ClientSocketHandle::readfrom(),
130             ClientSocketHandle::writeto(), ClientSocketHandle::bind(), ClientSocketHandle::local(),
131             ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf()
132
133         \par Address Type:
134             INet6Address
135
136         RawV6SocketProtocol provides an internet protocol stream socket based on IPv6 addressing.
137
138         This class is utilized as the protocol class of the ProtocolClientSocketHandle
139         via the Socket Handle typedefs above.
140
141         \see RawV4SocketProtocol
142      */
143     class RawV6SocketProtocol
144         : public ConcreteSocketProtocol<RawV6Socket_Policy>,
145           public IPv6Protocol,
146           public RawInetProtocol,
147           public BSDSocketProtocol,
148           public AddressableBSDSocketProtocol//,
149 //          public senf::pool_alloc_mixin<RawV6SocketProtocol>
150     {
151     public:
152         ///////////////////////////////////////////////////////////////////////////
153         // internal interface
154
155         ///\name Constructors
156         ///@{
157
158         void init_client() const;       ///< Create unconnected client socket for IPPROTO_RAW
159                                         /**< \note This member is implicitly called from the
160                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
161                                              constructor */
162
163         void init_client(int const & protocol) const;       ///< Create unconnected client socket for protocol
164
165         void init_client(int const & protocol, INet6SocketAddress const & address) const;
166                                         ///< Create client socket and bind
167                                         /**< Creates a new client socket for the given protocol and binds to the given
168                                              address.
169                                              \param[in] protocol Layer 4 protocol to filter for / to send 
170                                              \param[in] address local address to bind to */
171                                         /**< \note This member is implicitly called from the
172                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
173                                              constructor */
174
175         ///@}
176         ///\name Abstract Interface Implementation
177
178         std::auto_ptr<SocketProtocol> clone() const;
179
180         ///@}
181     };
182
183     typedef ProtocolClientSocketHandle<RawV6SocketProtocol> RawV6ClientSocketHandle;
184
185     /// @}
186
187 }
188
189 #endif /*RAWINETSOCKETHANDLE_HH_*/