4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Dennis Goslar <dennis.goslar@inf.hochschule-bonn-rhein-sieg.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 TCPPacket public header */
26 #ifndef HH_SENF_Packets_DefaultBundle_TCPPacket_
27 #define HH_SENF_Packets_DefaultBundle_TCPPacket_ 1
30 #include <senf/Packets/Packets.hh>
32 //#include "TCPPacket.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
37 /** \brief Parse a TCP packet
39 Parser implementing the TCP header. The fields implemented are:
40 \image html TCPPacket.png
43 <a href="http://tools.ietf.org/html/rfc793">RFC 793</a>
45 struct TCPPacketParser : public PacketParserBase
47 # include SENF_PARSER()
49 SENF_PARSER_FIELD( source, UInt16Parser );
50 SENF_PARSER_FIELD( destination, UInt16Parser );
51 SENF_PARSER_FIELD( sequencenumber, UInt32Parser );
52 SENF_PARSER_FIELD( acknowledgmentnumber, UInt32Parser );
54 SENF_PARSER_BITFIELD ( dataoffset, 4, unsigned );
55 SENF_PARSER_PRIVATE_BITFIELD( reserved, 6, unsigned );
56 SENF_PARSER_BITFIELD ( urgf, 1, bool );
57 SENF_PARSER_BITFIELD ( ackf, 1, bool );
58 SENF_PARSER_BITFIELD ( pshf, 1, bool );
59 SENF_PARSER_BITFIELD ( rstf, 1, bool );
60 SENF_PARSER_BITFIELD ( synf, 1, bool );
61 SENF_PARSER_BITFIELD ( finf, 1, bool );
63 SENF_PARSER_FIELD( window, UInt16Parser );
64 SENF_PARSER_FIELD( checksum, UInt16Parser );
65 SENF_PARSER_FIELD( urgentpointer, UInt16Parser );
67 // skip option part in TCP-Header, dataoffset()*4 = TCP header length in byte
68 // for options see http://www.iana.org/assignments/tcp-parameters/
69 // if dataoffset() < 5 packet is invalid
70 SENF_PARSER_SKIP( (dataoffset() < 5 ? 0 : dataoffset()*4-20), 0);
72 SENF_PARSER_FINALIZE(TCPPacketParser);
75 // Reserved: 6 bits, reserved for future use. Must be zero.
76 // see http://tools.ietf.org/html/rfc793
78 // dataoffset per default 5, 5*4 = 20 Byte Header Length
82 boost::uint16_t calcChecksum() const; ///< calculate (pseudo-)header checksum
83 /**< calculate and return the checksum of the
84 (pseudo-)header \see \ref senf::IpChecksum */
86 bool validateChecksum() const {
87 return checksum() == 0u || checksum() == calcChecksum();
88 } ///< validate header checksum
89 /**< return \c true if the \ref checksum() "checksum"
90 field is equal to the \ref calcChecksum() "calculated checksum" */
95 \par Packet type (typedef):
101 <table class="packet" cellpadding="5" cellspacing="1" border="1">
103 <th width="12%">0</th>
104 <th width="20%">4</th>
105 <th width="3%">10</th>
106 <th width="3%">11</th>
107 <th width="3%">12</th>
108 <th width="3%">13</th>
109 <th width="3%">14</th>
110 <th width="3%">15</th>
111 <th width="25%">16</th>
112 <th style="text-align:right" width="25%">31</th>
115 <td colspan="8">\ref TCPPacketParser::source() "Source Port"</td>
116 <td colspan="2">\ref TCPPacketParser::destination() "Destination Port"</td>
118 <td colspan="10">\ref TCPPacketParser::sequencenumber() "Sequence Number"</td>
120 <td colspan="10">\ref TCPPacketParser::acknowledgmentnumber() "Acknowledgment Number"</td>
122 <td colspan="1">\ref TCPPacketParser::dataoffset() "DataOffset"</td>
123 <td colspan="1">Reserved</td>
124 <td colspan="1">\ref TCPPacketParser::urgf() "UR"</td>
125 <td colspan="1">\ref TCPPacketParser::ackf() "AC"</td>
126 <td colspan="1">\ref TCPPacketParser::pshf() "PS"</td>
127 <td colspan="1">\ref TCPPacketParser::rstf() "RS"</td>
128 <td colspan="1">\ref TCPPacketParser::synf() "SY"</td>
129 <td colspan="1">\ref TCPPacketParser::finf() "FI"</td>
130 <td colspan="2">\ref TCPPacketParser::window() "Window Size"</td>
132 <td colspan="8">\ref TCPPacketParser::checksum() "Checksum"</td>
133 <td colspan="2">\ref TCPPacketParser::urgentpointer() "Urgent Pointer"</td>
137 \par Finalize action:
138 \copydetails finalize()
140 \ingroup protocolbundle_default
143 : public PacketTypeBase,
144 public PacketTypeMixin<TCPPacketType>
147 typedef PacketTypeMixin<TCPPacketType> mixin;
149 typedef ConcretePacket<TCPPacketType> packet; ///< TCP packet typedef
150 typedef TCPPacketParser parser; ///< typedef to the parser of TCP packet
152 using mixin::nextPacketRange;
153 using mixin::initSize;
156 /** \brief Dump given TCPPacket in readable form to given output stream */
157 static void dump(packet p, std::ostream & os);
159 static void finalize(packet p); ///< Finalize packet.
160 /**< \li set \ref TCPPacketParser::dataoffset() "Data Offset" from
162 \li calculate and set \ref TCPPacketParser::checksum()
166 /** \brief TCP packet typedef */
167 typedef ConcretePacket<TCPPacketType> TCPPacket;
171 ///////////////////////////////hh.e////////////////////////////////////////
172 //#include "TCPPacket.cci"
173 //#include "TCPPacket.ct"
174 //#include "TCPPacket.cti"
181 // c-file-style: "senf"
182 // indent-tabs-mode: nil
183 // ispell-local-dictionary: "american"
184 // compile-command: "scons -u test"
185 // comment-column: 40