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 // Stefan Bund <g0dil@berlios.de>
29 \brief PacketSocketProtocol and PacketSocketHandle public header
32 #ifndef HH_SENF_Socket_Protocols_Raw_PacketSocketHandle_
33 #define HH_SENF_Socket_Protocols_Raw_PacketSocketHandle_ 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>
43 #include <senf/Socket/Protocols/DatagramSocketProtocol.hh>
44 #include "LLAddressing.hh"
46 //#include "PacketSocketHandle.mpp"
47 //#include "PacketSocketHandle.ih"
48 //-/////////////////////////////////////////////////////////////////////////////////////////////////
52 /// \addtogroup concrete_protocol_group
55 typedef MakeSocketPolicy<
57 DatagramFramingPolicy,
58 UnconnectedCommunicationPolicy,
61 >::policy Packet_Policy; ///< Policy of PacketSocketProtocol
63 /** \brief Raw Packet-Socket access (Linux)
65 \par Socket Handle typedefs:
66 \ref PacketSocketHandle (ProtocolClientSocketHandle)
68 \par Policy Interface:
69 ClientSocketHandle::read(), ClientSocketHandle::readfrom(), ClientSocketHandle::writeto(),
70 ClientSocketHandle::bind(), ClientSocketHandle::local()
75 The PacketSocketProtocol provides access to the linux packet socket API. This API gives access to
76 the low level network packets. The packet socket allows read() and write() operations. The
77 PacketSocketProtocol has no concept of a server socket.
79 This class is utilized as the protocol class of the ProtocolClientSocketHandle via the
80 Socket Handle typedefs above.
82 class PacketSocketProtocol
83 : public ConcreteSocketProtocol<Packet_Policy, PacketSocketProtocol>,
84 public DatagramSocketProtocol,
85 public BSDSocketProtocol
88 enum SocketType { RawSocket, DatagramSocket };
93 void init_client(SocketType type = RawSocket, int protocol = -1) const;
94 ///< Create packet socket
95 /**< The new socket will receive all packets of the given
96 IEEE 802.3 \a protocol. The socket will receive all
97 packets, if \a protocol is -1.
99 If \a type is \c RawSocket, the packet will include the
100 link-level header (the Ethernet header). Sent packets
101 must already include a well formed ll header.
103 If \a type is \c DatagramSocket, the link level header
104 will not be part of the packet data. The ll header will
105 be removed from received packets and a correct ll
106 header will be created on sent packets.
108 \param[in] type socket type
109 \param[in] protocol IEEE 802.3 protocol number */
110 /**< \note This member is implicitly called from the
111 ProtocolClientSocketHandle::ProtocolClientSocketHandle()
115 ///\name Protocol Interface
118 void mcAdd(std::string const & interface, MACAddress const & address) const;
119 ///< Enable reception of a multicast group
120 /**< mcAdd will join a new multicast group.
122 \param[in] interface interface with which to join
123 \param[in] address multicast address to join
125 \see \ref LLSocketAddress */
126 void mcDrop(std::string const & interface, MACAddress const & address) const;
127 ///< Disable reception of a multicast group
128 /**< \see \ref mcAdd() */
130 void promisc(std::string const & interface, bool mode) const;
131 ///< enable/disable promiscuous mode
135 ///\name Abstract Interface Implementation
138 unsigned available() const;
144 typedef ProtocolClientSocketHandle<PacketSocketProtocol> PacketSocketHandle;
145 ///< SocketHandle of the PacketSocketProtocol
146 /**< \related PacketPrototol */
151 //-/////////////////////////////////////////////////////////////////////////////////////////////////
152 //#include "PacketSocketHandle.cci"
153 //#include "PacketSocketHandle.ct"
154 //#include "PacketSocketHandle.cti"
155 //#include "PacketSocketHandle.mpp"
162 // c-file-style: "senf"
163 // indent-tabs-mode: nil
164 // ispell-local-dictionary: "american"
165 // compile-command: "scons -u test"
166 // comment-column: 40