4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.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 "../../Utils/IpChecksum.hh"
36 #include "EthernetPacket.hh"
39 ///////////////////////////////cc.p////////////////////////////////////////
42 senf::PacketRegistry<senf::EtherTypes>::RegistrationProxy<senf::IpV4Packet>
43 registerIpV4Packet (0x0800);
45 senf::PacketRegistry<senf::IpTypes>::RegistrationProxy<senf::IpV4Packet>
46 regsiterIpV4Packet2 (4); // IP-in-IP encapsulation
49 ///////////////////////////////////////////////////////////////////////////
52 prefix_ boost::uint16_t senf::Parse_IpV4::calcChecksum()
55 validate(bytes(*this));
57 summer.feed( i(), i()+checksum_offset );
58 // Not needed since the number of 0-bytes is even
61 summer.feed( i()+checksum_offset+2, i()+bytes(*this) );
65 ///////////////////////////////////////////////////////////////////////////
66 // senf::IpV4PacketType
68 prefix_ void senf::IpV4PacketType::dump(packet p, std::ostream & os)
70 boost::io::ios_all_saver ias(os);
71 os << "Internet protocol Version 4:\n"
72 << " version : " << p->version() << "\n"
73 << " IHL : " << p->ihl() << "\n"
74 << " TOS : " << unsigned(p->tos()) << "\n"
75 << " length : " << p->length() << "\n"
76 << " identifier : " << p->identifier() << "\n"
77 << " DF : " << p->df() << "\n"
78 << " MF : " << p->mf() << "\n"
79 << " fragment : " << p->frag() << "\n"
80 << " TTL : " << unsigned(p->ttl()) << "\n"
81 << " protocol : " << unsigned(p->protocol()) << "\n"
83 << std::hex << std::setw(4) << std::setfill('0') << p->checksum() << std::dec << "\n"
84 << " source : " << p->source() << "\n"
85 << " destination : " << p->destination() << "\n";
88 prefix_ void senf::IpV4PacketType::finalize(packet p)
90 p->length() << p.size();
91 p->protocol() << key(p.next());
92 p->checksum() << p->calcChecksum();
95 ///////////////////////////////cc.e////////////////////////////////////////
102 // c-file-style: "senf"
103 // indent-tabs-mode: nil
104 // ispell-local-dictionary: "american"
105 // compile-command: "scons -u test"
106 // comment-column: 40