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 IPv4Packet non-inline non-template implementation */
31 #include "IPv4Packet.hh"
32 //#include "IPv4Packet.ih"
36 #include <boost/io/ios_state.hpp>
37 #include <senf/Utils/IpChecksum.hh>
38 #include "EthernetPacket.hh"
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44 SENF_PACKET_REGISTRY_REGISTER( senf::EtherTypes, 0x0800, senf::IPv4Packet);
45 SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 4, senf::IPv4Packet); // IP-in-IP encapsulation
48 //-/////////////////////////////////////////////////////////////////////////////////////////////////
49 // senf::IPv4PacketParser
51 prefix_ boost::uint16_t senf::IPv4PacketParser::calcChecksum()
54 validate(bytes(*this));
56 summer.feed( i(), i()+checksum_offset );
57 summer.feed( i()+checksum_offset+2, i()+bytes(*this) );
61 //-/////////////////////////////////////////////////////////////////////////////////////////////////
62 // senf::IPv4PacketType
64 prefix_ void senf::IPv4PacketType::dump(packet p, std::ostream & os)
66 boost::io::ios_all_saver ias(os);
67 os << "Internet protocol Version 4:\n"
68 << senf::fieldName("version") << p->version() << "\n"
69 << senf::fieldName("ip header length") << p->ihl() << "\n"
70 << senf::fieldName("tos") << unsigned(p->tos()) << "\n"
71 << senf::fieldName("length") << p->length() << "\n"
72 << senf::fieldName("identifier") << p->identifier() << "\n"
73 << senf::fieldName("dont fragment") << p->df() << "\n"
74 << senf::fieldName("more fragments") << p->mf() << "\n"
75 << senf::fieldName("fragment") << p->frag() << "\n"
76 << senf::fieldName("ttl") << unsigned(p->ttl()) << "\n"
77 << senf::fieldName("protocol") << unsigned(p->protocol()) << "\n"
78 << senf::fieldName("checksum")
79 << "0x" << std::hex << std::setw(4) << std::setfill('0') << std::right << p->checksum() << std::dec << "\n"
80 << senf::fieldName("source") << p->source() << "\n"
81 << senf::fieldName("destination") << p->destination() << "\n";
84 prefix_ void senf::IPv4PacketType::finalize(packet p)
86 p->length() << p.size();
87 p->protocol() << key(p.next(nothrow));
88 p->checksum() << p->calcChecksum();
91 //-/////////////////////////////////////////////////////////////////////////////////////////////////
98 // c-file-style: "senf"
99 // indent-tabs-mode: nil
100 // ispell-local-dictionary: "american"
101 // compile-command: "scons -u test"
102 // comment-column: 40