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 UDPPacket public header */
26 #ifndef HH_SENF_Packets_DefaultBundle_UDPPacket_
27 #define HH_SENF_Packets_DefaultBundle_UDPPacket_ 1
30 #include <senf/Packets/Packets.hh>
32 //#include "UDPPacket.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
37 /** \brief Parse a UDP packet
39 Parser implementing the UDP header. The fields implemented are:
40 \image html UDPPacket.png
43 <a href="http://tools.ietf.org/html/rfc768">RFC 768</a>
45 struct UDPPacketParser : public PacketParserBase
47 # include SENF_FIXED_PARSER()
49 SENF_PARSER_FIELD( source, senf::UInt16Parser );
50 SENF_PARSER_FIELD( destination, senf::UInt16Parser );
51 SENF_PARSER_FIELD( length, senf::UInt16Parser );
52 SENF_PARSER_FIELD( checksum, senf::UInt16Parser );
54 SENF_PARSER_FINALIZE(UDPPacketParser);
56 boost::uint16_t calcChecksum() const; ///< calculate (pseudo-)header checksum
57 /**< calculate and return the checksum of the
58 (pseudo-)header \see \ref senf::IpChecksum */
59 bool validateChecksum() const {
60 return checksum() == 0u || checksum() == calcChecksum();
61 } ///< validate header checksum
62 /**< return \c true if the \ref checksum() "checksum"
63 field is equal to the \ref calcChecksum() "calculated checksum" */
68 \par Packet type (typedef):
74 <table class="packet" cellpadding="5" cellspacing="1" border="1">
76 <th width="25%">0</th> <th width="25%">8</th> <th width="25%">16</th>
77 <th width="15%">24</th> <th style="text-align:right" width="10%">31</th>
79 <td colspan="2">\ref UDPPacketParser::source() "Source Port"</td>
80 <td colspan="3">\ref UDPPacketParser::destination() "Destination Port"</td>
82 <td colspan="2">\ref UDPPacketParser::length() "Length"</td>
83 <td colspan="3">\ref UDPPacketParser::checksum() "Checksum"</td>
88 \copydetails finalize()
90 \ingroup protocolbundle_default
93 : public PacketTypeBase,
94 public PacketTypeMixin<UDPPacketType>
97 typedef PacketTypeMixin<UDPPacketType> mixin;
99 typedef ConcretePacket<UDPPacketType> packet; ///< UDP packet typedef
100 typedef UDPPacketParser parser; ///< typedef to the parser of UDP packet
102 using mixin::nextPacketRange;
103 using mixin::initSize;
106 /** \brief Dump given UDPPacket in readable form to given output stream */
107 static void dump(packet p, std::ostream & os);
109 static void finalize(packet p); ///< Finalize packet.
110 /**< \li set \ref UDPPacketParser::length() "length" from
112 \li calculate and set \ref UDPPacketParser::checksum()
116 /** \brief UDP packet typedef */
117 typedef ConcretePacket<UDPPacketType> UDPPacket;
121 ///////////////////////////////hh.e////////////////////////////////////////
122 //#include "UDPPacket.cci"
123 //#include "UDPPacket.ct"
124 //#include "UDPPacket.cti"
131 // c-file-style: "senf"
132 // indent-tabs-mode: nil
133 // ispell-local-dictionary: "american"
134 // compile-command: "scons -u test"
135 // comment-column: 40