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()
56 summer.feed( i(), i()+checksum_offset );
57 // Not needed since the number of 0-bytes is even
60 summer.feed( i()+checksum_offset+2, i()+bytes(*this) );
64 ///////////////////////////////////////////////////////////////////////////
65 // senf::IpV4PacketType
67 prefix_ void senf::IpV4PacketType::dump(packet p, std::ostream & os)
69 boost::io::ios_all_saver ias(os);
70 os << "Internet protocol Version 4:\n"
71 << " version : " << p->version() << "\n"
72 << " IHL : " << p->ihl() << "\n"
73 << " TOS : " << unsigned(p->tos()) << "\n"
74 << " length : " << p->length() << "\n"
75 << " identifier : " << p->identifier() << "\n"
76 << " DF : " << p->df() << "\n"
77 << " MF : " << p->mf() << "\n"
78 << " fragment : " << p->frag() << "\n"
79 << " TTL : " << unsigned(p->ttl()) << "\n"
80 << " protocol : " << unsigned(p->protocol()) << "\n"
82 << std::hex << std::setw(4) << std::setfill('0') << p->checksum() << std::dec << "\n"
83 << " source : " << p->source() << "\n"
84 << " destination : " << p->destination() << "\n";
87 prefix_ void senf::IpV4PacketType::finalize(packet p)
89 p->length() << p.size();
90 p->protocol() << key(p.next());
91 p->checksum() << p->calcChecksum();
94 ///////////////////////////////cc.e////////////////////////////////////////
101 // c-file-style: "senf"
102 // indent-tabs-mode: nil
103 // ispell-local-dictionary: "american"
104 // compile-command: "scons -u test"
105 // comment-column: 40