1 // $Id:PacketSocketHandle.hh 218 2007-03-20 14:39:32Z tho $
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.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 PacketProtocol and PacketSocketHandle public header
26 \todo Implement global promisc() helper based on ioctl() interface.
29 #ifndef HH_PacketSocketHandle_
30 #define HH_PacketSocketHandle_ 1
33 #include "SocketPolicy.hh"
34 #include "SocketProtocol.hh"
35 #include "ProtocolClientSocketHandle.hh"
36 #include "LLAddressing.hh"
37 #include "FramingPolicy.hh"
38 #include "CommunicationPolicy.hh"
39 #include "ReadWritePolicy.hh"
40 #include "BufferingPolicy.hh"
41 #include "BSDSocketProtocol.hh"
43 //#include "PacketSocketHandle.mpp"
44 #include "PacketSocketHandle.ih"
45 ///////////////////////////////hh.p////////////////////////////////////////
49 /// \addtogroup concrete_protocol_group
52 typedef MakeSocketPolicy<
54 DatagramFramingPolicy,
55 UnconnectedCommunicationPolicy,
59 >::policy Packet_Policy; ///< Policy of PacketProtocol
61 /** \brief Raw Packet-Socket access (Linux)
63 \par Socket Handle typedefs:
64 \ref PacketSocketHandle (ProtocolClientSocketHandle)
66 \par Policy Interface:
67 ClientSocketHandle::read(), ClientSocketHandle::readfrom(), ClientSocketHandle::writeto(),
68 ClientSocketHandle::bind(), ClientSocketHandle::local(), ClientSocketHandle::rcvbuf(),
69 ClientSocketHandle::sndbuf()
74 The PacketProtocol provides access to the linux packet socket API. This API gives access to
75 the low level network packets. The packet socket allows read() and write() operations. The
76 PacketProtocol has no concept of a server socket.
78 This class is utilized as the protocol class of the ProtocolClientSocketHandle via the
79 Socket Handle typedefs above.
82 : public ConcreteSocketProtocol<Packet_Policy>,
83 public BSDSocketProtocol
86 enum SocketType { RawSocket, DatagramSocket };
91 void init_client(SocketType type = RawSocket, int protocol = -1) const;
92 ///< Create packet socket
93 /**< The new socket will receive all packets of the given
94 IEEE 802.3 \a protocol. The socket will receive all
95 packets, if \a protocol is -1.
97 If \a type is \c RawSocket, the packet will include the
98 link-level header (the Ethernet header). Sent packets
99 must already include a well formed ll header.
101 If \a type is \c DatagramSocket, the link level header
102 will not be part of the packet data. The ll header will
103 be removed from received packets and a correct ll
104 header will be created on sent packets.
106 \param[in] type socket type
107 \param[in] protocol IEEE 802.3 protocol number */
108 /**< \note This member is implicitly called from the
109 ProtocolClientSocketHandle::ProtocolClientSocketHandle()
113 ///\name Protocol Interface
116 // See LLSocketAddress for a discussion/rationale for ForwardRange here
117 template <class ForwardRange>
118 void mcAdd(std::string interface, ForwardRange const & address) const;
119 ///< Enable reception of a multicast group
120 /**< mcAdd will join a new multicast group. The address
121 parameter is specified as an arbitrary forward range
123 href="http://www.boost.org/libs/range/index.html">Boost.Range</a>)
124 of up to 8 bytes. This allows to initialize the
125 address from an arbitrary sources without excessive
128 \param[in] interface interface with which to join
129 \param[in] address multicast address to join
131 \see \ref LLSocketAddress */
132 template <class ForwardRange>
133 void mcDrop(std::string interface, ForwardRange const & address) const;
134 ///< Disable reception of a multicast group
135 /**< \see \ref mcAdd() */
138 ///\name Abstract Interface Implementation
141 std::auto_ptr<SocketProtocol> clone() const;
142 unsigned available() const;
148 template<class ForwardRange>
149 void do_mc(std::string interface, ForwardRange const & address, bool add) const;
150 void do_mc_i(std::string interface, detail::LLAddressCopier const & copier, bool add) const;
153 typedef ProtocolClientSocketHandle<PacketProtocol> PacketSocketHandle;
154 ///< SocketHandle of the PacketProtocol
155 /**< \related PacketPrototol */
160 ///////////////////////////////hh.e////////////////////////////////////////
161 //#include "PacketSocketHandle.cci"
162 #include "PacketSocketHandle.ct"
163 #include "PacketSocketHandle.cti"
164 //#include "PacketSocketHandle.mpp"
171 // c-file-style: "senf"
172 // indent-tabs-mode: nil
173 // ispell-local-dictionary: "american"