1 // $Id:PacketSocketHandle.hh 218 2007-03-20 14:39:32Z tho $
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Thorsten Horstmann <tho@berlios.de>
29 \brief PacketSocketProtocol and PacketSocketHandle public header
32 #ifndef HH_SENF_Socket_Protocols_Raw_TunTapSocketHandle_
33 #define HH_SENF_Socket_Protocols_Raw_TunTapSocketHandle_ 1
36 #include <senf/Socket/SocketPolicy.hh>
37 #include <senf/Socket/SocketProtocol.hh>
38 #include <senf/Socket/ProtocolClientSocketHandle.hh>
39 #include <senf/Socket/FramingPolicy.hh>
40 #include <senf/Socket/CommunicationPolicy.hh>
41 #include <senf/Socket/ReadWritePolicy.hh>
42 #include <senf/Socket/Protocols/BSDSocketProtocol.hh>
44 //#include "TunTapSocketHandle.mpp"
45 //#include "TunTapSocketHandle.ih"
46 //-/////////////////////////////////////////////////////////////////////////////////////////////////
50 /// \addtogroup concrete_protocol_group
53 typedef MakeSocketPolicy<
55 DatagramFramingPolicy,
56 ConnectedCommunicationPolicy,
59 >::policy Tap_Policy; ///< Policy for TapSocketProtocol
61 /** \brief SocketProcol for the tap pseudo-device.
63 \par Socket Handle typedefs:
66 \par Policy Interface:
67 ClientSocketHandle::read() ...
69 The TapSocketProtocol provides access to the Linux tap device.
71 The tap device is a virtual ethernet network device. The tap driver was designed as low
72 level kernel support for ethernet tunneling. Userland application can write Ethernet
73 frames to the socket and kernel will receive this frames from the tap interface.
74 In the same time every frame that kernel writes to the tap interface can be read by
75 userland application from the socket.
77 This class is utilized as the protocol class of the ProtocolClientSocketHandle via the
78 Socket Handle typedef above.
80 \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>
82 class TapSocketProtocol
83 : public ConcreteSocketProtocol<Tap_Policy,TapSocketProtocol>,
84 public BSDSocketProtocol
89 void init_client() const; ///< Open tap socket and create new tap interface
90 /**< Opens the tun/tap socket and create a new tap interface
91 Use \ref ifaceName() to get the actual name of the newly
94 The new interface is down and has to be set up separately.
95 After closing the socket, the tap interface and all
96 corresponding routes will be deleted automatically. */
97 /**< \note This member is implicitly called from the
98 ProtocolClientSocketHandle::ProtocolClientSocketHandle()
100 void init_client(std::string const & interface_name, bool NO_PI=true) const;
101 ///< Open tap socket and create new tap interface
102 /**< Opens the tun/tap socket and create a new tap interface
103 with the given name. Note that the created interface can
104 have a different name as specified. Use \ref ifaceName()
105 to get the actual name.
107 The new interface is down and has to be set up separately.
108 After closing the socket, the tap interface and all
109 corresponding routes will be deleted automatically.
110 \param[in] interface_name name of the new tap interface.
111 \param[in] NO_PI if set to \c false each packet has a
112 additional 4 bytes header (flags, proto) */
113 /**< \note This member is implicitly called from the
114 ProtocolClientSocketHandle::ProtocolClientSocketHandle()
119 ///\name Abstract Interface Implementation
122 unsigned available() const;
123 bool eof() const; ///< returns always false.
124 unsigned int ifaceIndex() const;///< returns the index of the correspondent tap interface
125 std::string ifaceName() const; ///< returns the actual name of the correspondent tap interface
128 mutable unsigned int ifaceIndex_;
132 typedef ProtocolClientSocketHandle<TapSocketProtocol> TapSocketHandle;
133 ///< SocketHandle of TapSocketProtocol
134 /**< \related TapSocketProtocol */
139 //-/////////////////////////////////////////////////////////////////////////////////////////////////
140 //#include "TunTapSocketHandle.cci"
141 //#include "TunTapSocketHandle.ct"
142 //#include "TunTapSocketHandle.cti"
143 //#include "TunTapSocketHandle.mpp"
150 // c-file-style: "senf"
151 // indent-tabs-mode: nil
152 // ispell-local-dictionary: "american"
153 // compile-command: "scons -u test"
154 // comment-column: 40