// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-/** \mainpage HowTo: Defining and using a new 'libPacket' Packet Type
+/** \mainpage Defining and using a new 'libPacket' Packet Type
This howto will introduce the facilities needed to define a new packet type. As example, the
\c GREPacket type is defined.
\section howto_newpacket_type Defining the packet type
- After we have implemented the \c GREPacketParser we need now to build the packet type. This is
+ After we have implemented the \c GREPacketParser we now need to build the packet type. This is
done by providing a special policy class called the 'packet type'. This class encapsulates all
the information the packet library needs to know about a packet:
\code
static void finalize(packet p)
{
+ p->protocolType() << key(p.next(senf::nothrow));
if (p->checksumPresent())
p->checksum() << p->calculateChecksum();
- p->protocolType() << key(p.next(senf::nothrow));
}
\endcode
- \a finalize() first updates the \a checksum() field if present. It then sets the \a
- protocolType() field depending on the \e next packet. The \c key() function is provided by the
- mixin class: It will lookup the \e type of a packet in the registry and return that packets key
- in the registry.
+ \a finalize() firs sets the \a protocolType() field depending on the \e next packet. The \c
+ key() function is provided by the mixin class: It will lookup the \e type of a packet in the
+ registry and return that packets key in the registry.
+
+ It then updates the \a checksum() field if present (this always needs to be done last since the
+ checksum depends on the other field values).
Here we are using the more generic parser assignment expressed using the \c << operator. This
operator in the most cases works like an ordinary assignment, however it can also be used to
static key_t nextPacketKey(packet p) { return p->protocolType(); }
static void finalize(packet p) {
+ p->protocolType() << key(p.next(senf::nothrow));
if (p->checksumPresent()) p->checksum() << p->calculateChecksum();
- p->protocolType() << key(p.next(senf::nothrow));
- }
+ }
static void dump(packet p, std::ostream & os);
};
GREPacket.hh:
\code
- #ifndef GRE_PACKET_HH
- #define GRE_PACKET_HH
+ #ifndef HH_GREPacket_
+ #define HH_GREPacket_
#include <senf/Packets.hh>
{ return p->valid() ? lookup(p->protocolType()) : no_factory(); }
static void finalize(packet p) {
- if (p->checksumPresent()) p->checksum() << p->calculateChecksum();
p->protocolType() << key(p.next(senf::nothrow));
+ if (p->checksumPresent()) p->checksum() << p->calculateChecksum();
}
static void dump(packet p, std::ostream & os);
senf::RawV6ClientSocketHandle isock (47u); // 47 = Read GRE packets
senf::PacketSocketHandle osock;
- while (1) {
+ while (true) {
try {
GREPacket gre (GREPacket::create(senf::noinit));
isock.read(gre.data(),0u);
senf::TapSocketHandle tap ("tap0");
senf::ConnectedRawV6ClientSocketHandle osock (47u, senf::INet6SocketAddress(argv[1]));
- while (1) {
+ while (true) {
senf::EthernetPacket eth (senf::EthernetPacket::create(senf::noinit));
isock.read(eth.data(),0u);
GREPacket gre (senf::GREPacket::createBefore(eth));
\section howto_newpacket_further Further reading
- Lets start with references to the important API's (Use the 'Show all members' link to get the
- complete API of one of the classes and templates):
+ Lets start with references to the important API's (Use the <i>List of all members</i> link to
+ get the complete API of one of the classes and templates):
+
+ <table class="senf fixedcolumn">
+
+ <tr><td>senf::ConcretePacket</td> <td>this is the API provided by the packet handles.</td></tr>
- \li senf::ConcretePacket : this is the API provided by the packet handles.
- \li senf::PacketData : this API provides raw data access accessible via the handles 'data'
- member.
- \li senf::PacketParserBase : this is the generic parser API. This API is accessible via the
- packets \c -> operator or via the sub-parsers returned by the field accessors.
+ <tr><td>senf::PacketData</td> <td>this API provides raw data access accessible via the handles
+ 'data' member.</td></tr>
+
+ <tr><td>senf::PacketParserBase</td> <td>this is the generic parser API. This API is accessible
+ via the packets \c -> operator or via the sub-parsers returned by the field accessors.</td></tr>
+
+ </table>
When implementing new packet's, the following information will be helpful:
- \li senf::PacketTypeBase : here you find a description of the members which need to be
- implemented to provide a 'packet type'. Most of these members will normally be provided by
- the mixin helper.
- \li senf::PacketTypeMixin : here you find all about the packet type mixin and how to use it.
- \li \ref packetparser : This section describes the packet parser facility.
- \li \ref packetparsermacros : A complete list and documentation of all the packet parser macros.
- \li There are several lists of available reusable packet parsers: \ref parseint, \ref
- parsecollection. However, this list is not complete as there are other protocol specific
- reusable parsers (without claiming to be exhaustive: senf::INet4AddressParser,
- senf::INet6AddressParser, senf::MACAddressParser)
+ <table class="senf fixedcolumn">
+
+ <tr><td>senf::PacketTypeBase</td> <td>here you find a description of the members which need to
+ be implemented to provide a 'packet type'. Most of these members will normally be provided by
+ the mixin helper.</td></tr>
+
+ <tr><td>senf::PacketTypeMixin</td> <td>here you find all about the packet type mixin and how to
+ use it.</td></tr>
+
+ <tr><td>\ref packetparser</td> <td>This section describes the packet parser facility.</td></tr>
+
+ <tr><td>\link packetparsermacros Packet parser macros\endlink</td> <td>A complete list and
+ documentation of all the packet parser macros.</td></tr>
+
+ <tr><td>\ref parseint, \n \ref parsecollection</td> <td>There are several lists of available
+ reusable packet parsers. However, these lists are not complete as there are other protocol
+ specific reusable parsers (without claiming to be exhaustive: senf::INet4AddressParser,
+ senf::INet6AddressParser, senf::MACAddressParser)</td></tr>
+
+ </table>
*/
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
// compile-command: "scons -u doc"
-// mode: flyspell
// mode: auto-fill
// End: