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 UDPPacket public header */
31 #ifndef HH_SENF_Packets_DefaultBundle_UDPPacket_
32 #define HH_SENF_Packets_DefaultBundle_UDPPacket_ 1
35 #include <senf/Packets/Packets.hh>
37 //#include "UDPPacket.mpp"
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 /** \brief Parse a UDP packet
44 Parser implementing the UDP header. The fields implemented are:
45 \image html UDPPacket.png
48 <a href="http://tools.ietf.org/html/rfc768">RFC 768</a>
50 struct UDPPacketParser : public PacketParserBase
52 # include SENF_FIXED_PARSER()
54 SENF_PARSER_FIELD( source, senf::UInt16Parser );
55 SENF_PARSER_FIELD( destination, senf::UInt16Parser );
56 SENF_PARSER_FIELD( length, senf::UInt16Parser );
57 SENF_PARSER_FIELD( checksum, senf::UInt16Parser );
59 SENF_PARSER_FINALIZE(UDPPacketParser);
61 boost::uint16_t calcChecksum() const; ///< calculate (pseudo-)header checksum
62 /**< calculate and return the checksum of the
63 (pseudo-)header \see \ref senf::IpChecksum */
64 bool validateChecksum() const {
65 return checksum() == 0u || checksum() == calcChecksum();
66 } ///< validate header checksum
67 /**< return \c true if the \ref checksum() "checksum"
68 field is equal to the \ref calcChecksum() "calculated checksum" */
73 \par Packet type (typedef):
79 <table class="packet" cellpadding="5" cellspacing="1" border="1">
81 <th width="25%">0</th> <th width="25%">8</th> <th width="25%">16</th>
82 <th width="15%">24</th> <th style="text-align:right" width="10%">31</th>
84 <td colspan="2">\ref UDPPacketParser::source() "Source Port"</td>
85 <td colspan="3">\ref UDPPacketParser::destination() "Destination Port"</td>
87 <td colspan="2">\ref UDPPacketParser::length() "Length"</td>
88 <td colspan="3">\ref UDPPacketParser::checksum() "Checksum"</td>
93 \copydetails finalize()
95 \ingroup protocolbundle_default
98 : public PacketTypeBase,
99 public PacketTypeMixin<UDPPacketType>
102 typedef PacketTypeMixin<UDPPacketType> mixin;
104 typedef ConcretePacket<UDPPacketType> packet; ///< UDP packet typedef
105 typedef UDPPacketParser parser; ///< typedef to the parser of UDP packet
107 using mixin::nextPacketRange;
108 using mixin::initSize;
111 /** \brief Dump given UDPPacket in readable form to given output stream */
112 static void dump(packet p, std::ostream & os);
114 static void finalize(packet p); ///< Finalize packet.
115 /**< \li set \ref UDPPacketParser::length() "length" from
117 \li calculate and set \ref UDPPacketParser::checksum()
121 /** \brief UDP packet typedef
122 \ingroup protocolbundle_default
124 typedef ConcretePacket<UDPPacketType> UDPPacket;
128 //-/////////////////////////////////////////////////////////////////////////////////////////////////
129 //#include "UDPPacket.cci"
130 //#include "UDPPacket.ct"
131 //#include "UDPPacket.cti"
138 // c-file-style: "senf"
139 // indent-tabs-mode: nil
140 // ispell-local-dictionary: "american"
141 // compile-command: "scons -u test"
142 // comment-column: 40