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 IPv4Packet non-inline non-template implementation */
26 #include "IPv4Packet.hh"
27 //#include "IPv4Packet.ih"
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
34 #include <boost/io/ios_state.hpp>
35 #include <senf/Utils/IpChecksum.hh>
36 #include "EthernetPacket.hh"
39 ///////////////////////////////cc.p////////////////////////////////////////
42 SENF_PACKET_REGISTRY_REGISTER( senf::EtherTypes, 0x0800, senf::IPv4Packet);
43 SENF_PACKET_REGISTRY_REGISTER( senf::IpTypes, 4, senf::IPv4Packet); // IP-in-IP encapsulation
46 ///////////////////////////////////////////////////////////////////////////
47 // senf::IPv4PacketParser
49 prefix_ boost::uint16_t senf::IPv4PacketParser::calcChecksum()
52 validate(bytes(*this));
54 summer.feed( i(), i()+checksum_offset );
55 summer.feed( i()+checksum_offset+2, i()+bytes(*this) );
59 ///////////////////////////////////////////////////////////////////////////
60 // senf::IPv4PacketType
62 prefix_ void senf::IPv4PacketType::dump(packet p, std::ostream & os)
64 boost::io::ios_all_saver ias(os);
65 os << "Internet protocol Version 4:\n"
66 << " version : " << p->version() << "\n"
67 << " ip header length : " << p->ihl() << "\n"
68 << " tos : " << unsigned(p->tos()) << "\n"
69 << " length : " << p->length() << "\n"
70 << " identifier : " << p->identifier() << "\n"
71 << " dont fragment : " << p->df() << "\n"
72 << " more fragments : " << p->mf() << "\n"
73 << " fragment : " << p->frag() << "\n"
74 << " ttl : " << unsigned(p->ttl()) << "\n"
75 << " protocol : " << unsigned(p->protocol()) << "\n"
77 << std::hex << std::setw(4) << std::setfill('0') << p->checksum() << std::dec << "\n"
78 << " source : " << p->source() << "\n"
79 << " destination : " << p->destination() << "\n";
82 prefix_ void senf::IPv4PacketType::finalize(packet p)
84 p->length() << p.size();
85 p->protocol() << key(p.next(nothrow));
86 p->checksum() << p->calcChecksum();
89 ///////////////////////////////cc.e////////////////////////////////////////
96 // c-file-style: "senf"
97 // indent-tabs-mode: nil
98 // ispell-local-dictionary: "american"
99 // compile-command: "scons -u test"
100 // comment-column: 40