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 // Stefan Bund <g0dil@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_PacketSocketHandle_
28 #define HH_SENF_Socket_Protocols_Raw_PacketSocketHandle_ 1
31 #include <senf/Socket/SocketPolicy.hh>
32 #include <senf/Socket/SocketProtocol.hh>
33 #include <senf/Socket/ProtocolClientSocketHandle.hh>
34 #include <senf/Socket/FramingPolicy.hh>
35 #include <senf/Socket/CommunicationPolicy.hh>
36 #include <senf/Socket/ReadWritePolicy.hh>
37 #include <senf/Socket/Protocols/BSDSocketProtocol.hh>
38 #include <senf/Socket/Protocols/DatagramSocketProtocol.hh>
39 #include "LLAddressing.hh"
41 //#include "PacketSocketHandle.mpp"
42 //#include "PacketSocketHandle.ih"
43 ///////////////////////////////hh.p////////////////////////////////////////
47 /// \addtogroup concrete_protocol_group
50 typedef MakeSocketPolicy<
52 DatagramFramingPolicy,
53 UnconnectedCommunicationPolicy,
56 >::policy Packet_Policy; ///< Policy of PacketSocketProtocol
58 /** \brief Raw Packet-Socket access (Linux)
60 \par Socket Handle typedefs:
61 \ref PacketSocketHandle (ProtocolClientSocketHandle)
63 \par Policy Interface:
64 ClientSocketHandle::read(), ClientSocketHandle::readfrom(), ClientSocketHandle::writeto(),
65 ClientSocketHandle::bind(), ClientSocketHandle::local()
70 The PacketSocketProtocol provides access to the linux packet socket API. This API gives access to
71 the low level network packets. The packet socket allows read() and write() operations. The
72 PacketSocketProtocol has no concept of a server socket.
74 This class is utilized as the protocol class of the ProtocolClientSocketHandle via the
75 Socket Handle typedefs above.
77 class PacketSocketProtocol
78 : public ConcreteSocketProtocol<Packet_Policy, PacketSocketProtocol>,
79 public DatagramSocketProtocol,
80 public BSDSocketProtocol
83 enum SocketType { RawSocket, DatagramSocket };
88 void init_client(SocketType type = RawSocket, int protocol = -1) const;
89 ///< Create packet socket
90 /**< The new socket will receive all packets of the given
91 IEEE 802.3 \a protocol. The socket will receive all
92 packets, if \a protocol is -1.
94 If \a type is \c RawSocket, the packet will include the
95 link-level header (the Ethernet header). Sent packets
96 must already include a well formed ll header.
98 If \a type is \c DatagramSocket, the link level header
99 will not be part of the packet data. The ll header will
100 be removed from received packets and a correct ll
101 header will be created on sent packets.
103 \param[in] type socket type
104 \param[in] protocol IEEE 802.3 protocol number */
105 /**< \note This member is implicitly called from the
106 ProtocolClientSocketHandle::ProtocolClientSocketHandle()
110 ///\name Protocol Interface
113 void mcAdd(std::string const & interface, MACAddress const & address) const;
114 ///< Enable reception of a multicast group
115 /**< mcAdd will join a new multicast group.
117 \param[in] interface interface with which to join
118 \param[in] address multicast address to join
120 \see \ref LLSocketAddress */
121 void mcDrop(std::string const & interface, MACAddress const & address) const;
122 ///< Disable reception of a multicast group
123 /**< \see \ref mcAdd() */
125 void promisc(std::string const & interface, bool mode) const;
126 ///< enable/disable promiscuous mode
130 ///\name Abstract Interface Implementation
133 unsigned available() const;
139 typedef ProtocolClientSocketHandle<PacketSocketProtocol> PacketSocketHandle;
140 ///< SocketHandle of the PacketSocketProtocol
141 /**< \related PacketPrototol */
146 ///////////////////////////////hh.e////////////////////////////////////////
147 //#include "PacketSocketHandle.cci"
148 //#include "PacketSocketHandle.ct"
149 //#include "PacketSocketHandle.cti"
150 //#include "PacketSocketHandle.mpp"
157 // c-file-style: "senf"
158 // indent-tabs-mode: nil
159 // ispell-local-dictionary: "american"
160 // compile-command: "scons -u test"
161 // comment-column: 40