added some documentation
[senf.git] / Socket / Protocols / Raw / TunTapSocketHandle.hh
1 // $Id:PacketSocketHandle.hh 218 2007-03-20 14:39:32Z tho $
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@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 /** \file
24     \brief PacketSocketProtocol and PacketSocketHandle public header
25  */
26
27 #ifndef HH_SENF_Socket_Protocols_Raw_TunTapSocketHandle_
28 #define HH_SENF_Socket_Protocols_Raw_TunTapSocketHandle_ 1
29
30 // Custom includes
31 #include "../../../Socket/SocketPolicy.hh"
32 #include "../../../Socket/SocketProtocol.hh"
33 #include "../../../Socket/ProtocolClientSocketHandle.hh"
34 #include "../../../Socket/FramingPolicy.hh"
35 #include "../../../Socket/CommunicationPolicy.hh"
36 #include "../../../Socket/ReadWritePolicy.hh"
37 #include "../../../Socket/Protocols/BSDSocketProtocol.hh"
38 #include "LLAddressing.hh"
39
40 //#include "TunTapSocketHandle.mpp"
41 //#include "TunTapSocketHandle.ih"
42 ///////////////////////////////hh.p////////////////////////////////////////
43
44 namespace senf {
45
46     /// \addtogroup concrete_protocol_group
47     /// @{
48
49     typedef MakeSocketPolicy<
50         NoAddressingPolicy,
51         DatagramFramingPolicy,
52         ConnectedCommunicationPolicy,
53         ReadablePolicy,
54         WriteablePolicy
55         >::policy Tap_Policy;        ///< Policy for TapSocketProtocol
56
57     /** \brief SocketProcol for the tap pseudo-device.
58
59         \par Socket Handle typedefs:
60             \ref TapSocketHandle
61
62         \par Policy Interface:
63             ClientSocketHandle::read() ...
64
65         The TapSocketProtocol provides access to the Linux tap device.
66
67         The tap device is a virtual ethernet network device. The tap driver was designed as low
68         level kernel support for ethernet tunneling. Userland application can write Ethernet
69         frames to the socket and kernel will receive this frames from the tap interface.
70         In the same time every frame that kernel writes to the tap interface can be read by
71         userland application from the socket.
72
73         This class is utilized as the protocol class of the ProtocolClientSocketHandle via the
74         Socket Handle typedef above.
75
76         \see <a href="http://www.kernel.org/pub/linux/kernel/people/marcelo/linux-2.4/Documentation/networking/tuntap.txt">Kernel documentation for the TUN/TAP device driver.</a>
77      */
78     class TapSocketProtocol
79         : public ConcreteSocketProtocol<Tap_Policy,TapSocketProtocol>,
80           public BSDSocketProtocol
81     {
82     public:
83         ///\name Constructors
84         ///@{
85         void init_client() const;       ///< Open tap socket and create new tap interface
86                                         /**< Opens the tun/tap socket and create a new tap interface
87                                              Use \ref ifaceName() to get the actual name of the newly
88                                              created interface.
89              
90                                              The new interface is down and has to be set up separately. 
91                                              After closing the socket, the tap interface and all
92                                              corresponding routes will be deleted automatically. */
93                                         /**< \note This member is implicitly called from the
94                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
95                                              constructor */
96         void init_client(std::string const & interface_name, bool NO_PI=true) const;
97                                         ///< Open tap socket and create new tap interface
98                                         /**< Opens the tun/tap socket and create a new tap interface
99                                              with the given name. Note that the created interface can
100                                              have a different name as specified. Use \ref ifaceName()
101                                              to get the actual name.
102                                              
103                                              The new interface is down and has to be set up separately. 
104                                              After closing the socket, the tap interface and all
105                                              corresponding routes will be deleted automatically. 
106                                              \param[in] interface_name name of the new tap interface.
107                                              \param[in] NO_PI if set to \c false each packet has a 
108                                                  additional 4 bytes header (flags, proto) */
109                                         /**< \note This member is implicitly called from the
110                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
111                                              constructor */
112
113         ///@}
114
115         ///\name Abstract Interface Implementation
116         ///@{
117
118         unsigned available() const;
119         bool eof() const;               ///< returns always false.
120         unsigned int ifaceIndex() const;///< returns the index of the correspondent tap interface
121         std::string ifaceName() const;  ///< returns the actual name of the correspondent tap interface  
122
123     private:
124         mutable unsigned int ifaceIndex_;
125         ///@}
126     };
127
128     typedef ProtocolClientSocketHandle<TapSocketProtocol> TapSocketHandle;
129                                         ///< SocketHandle of TapSocketProtocol
130                                         /**< \related TapSocketProtocol */
131
132     /// @}
133 }
134
135 ///////////////////////////////hh.e////////////////////////////////////////
136 //#include "TunTapSocketHandle.cci"
137 //#include "TunTapSocketHandle.ct"
138 //#include "TunTapSocketHandle.cti"
139 //#include "TunTapSocketHandle.mpp"
140 #endif
141
142
143 // Local Variables:
144 // mode: c++
145 // fill-column: 100
146 // c-file-style: "senf"
147 // indent-tabs-mode: nil
148 // ispell-local-dictionary: "american"
149 // compile-command: "scons -u test"
150 // comment-column: 40
151 // End: