1 // $Id:PacketSocketHandle.hh 218 2007-03-20 14:39:32Z tho $
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Thorsten Horstmann <tho@berlios.de>
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.
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.
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.
24 \brief PacketSocketProtocol and PacketSocketHandle public header
27 #ifndef HH_SENF_Socket_Protocols_Raw_TunTapSocketHandle_
28 #define HH_SENF_Socket_Protocols_Raw_TunTapSocketHandle_ 1
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"
40 //#include "TunTapSocketHandle.mpp"
41 //#include "TunTapSocketHandle.ih"
42 ///////////////////////////////hh.p////////////////////////////////////////
46 /// \addtogroup concrete_protocol_group
49 typedef MakeSocketPolicy<
51 DatagramFramingPolicy,
52 ConnectedCommunicationPolicy,
55 >::policy Tap_Policy; ///< Policy for TapSocketProtocol
57 /** \brief SocketProcol for the tap pseudo-device.
59 \par Socket Handle typedefs:
62 \par Policy Interface:
63 ClientSocketHandle::read() ...
65 The TapSocketProtocol provides access to the Linux tap device.
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.
73 This class is utilized as the protocol class of the ProtocolClientSocketHandle via the
74 Socket Handle typedef above.
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>
78 class TapSocketProtocol
79 : public ConcreteSocketProtocol<Tap_Policy,TapSocketProtocol>,
80 public BSDSocketProtocol
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
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()
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.
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()
115 ///\name Abstract Interface Implementation
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
124 mutable unsigned int ifaceIndex_;
128 typedef ProtocolClientSocketHandle<TapSocketProtocol> TapSocketHandle;
129 ///< SocketHandle of TapSocketProtocol
130 /**< \related TapSocketProtocol */
135 ///////////////////////////////hh.e////////////////////////////////////////
136 //#include "TunTapSocketHandle.cci"
137 //#include "TunTapSocketHandle.ct"
138 //#include "TunTapSocketHandle.cti"
139 //#include "TunTapSocketHandle.mpp"
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