Fix SCons 1.2.0 build failure
[senf.git] / senf / Packets / DefaultBundle / IPv4Packet.cc
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief IPv4Packet non-inline non-template implementation */
25
26 #include "IPv4Packet.hh"
27 //#include "IPv4Packet.ih"
28
29 // Custom includes
30 #include <iomanip>
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"
37
38 #define prefix_
39 ///////////////////////////////cc.p////////////////////////////////////////
40
41 namespace {
42     senf::PacketRegistry<senf::EtherTypes>::RegistrationProxy<senf::IPv4Packet>
43         registerIPv4Packet (0x0800);
44
45     senf::PacketRegistry<senf::IpTypes>::RegistrationProxy<senf::IPv4Packet>
46         regsiterIPv4Packet2 (4); // IP-in-IP encapsulation
47 }
48
49 ///////////////////////////////////////////////////////////////////////////
50 // senf::IPv4PacketParser
51
52 prefix_ boost::uint16_t senf::IPv4PacketParser::calcChecksum()
53     const
54 {
55     validate(bytes(*this));
56     IpChecksum summer;
57     summer.feed( i(),                   i()+checksum_offset );
58     summer.feed( i()+checksum_offset+2, i()+bytes(*this)    );
59     return summer.sum();
60 }
61
62 ///////////////////////////////////////////////////////////////////////////
63 // senf::IPv4PacketType
64
65 prefix_ void senf::IPv4PacketType::dump(packet p, std::ostream & os)
66 {
67     boost::io::ios_all_saver ias(os);
68     os <<     "Internet protocol Version 4:\n"
69        <<     "  version                 : " << p->version() << "\n"
70        <<     "  ip header length        : " << p->ihl() << "\n"
71        <<     "  tos                     : " << unsigned(p->tos()) << "\n"
72        <<     "  length                  : " << p->length() << "\n"
73        <<     "  identifier              : " << p->identifier() << "\n"
74        <<     "  dont fragment           : " << p->df() << "\n"
75        <<     "  more fragments          : " << p->mf() << "\n"
76        <<     "  fragment                : " << p->frag() << "\n"
77        <<     "  ttl                     : " << unsigned(p->ttl()) << "\n"
78        <<     "  protocol                : " << unsigned(p->protocol()) << "\n"
79        <<     "  checksum                : 0x" 
80          << std::hex << std::setw(4) << std::setfill('0') << p->checksum() << std::dec << "\n"
81        <<     "  source                  : " << p->source() << "\n"
82        <<     "  destination             : " << p->destination() << "\n";
83 }
84
85 prefix_ void senf::IPv4PacketType::finalize(packet p)
86 {
87     p->length()   << p.size();
88     p->protocol() << key(p.next(nothrow));
89     p->checksum() << p->calcChecksum();
90 }
91
92 ///////////////////////////////cc.e////////////////////////////////////////
93 #undef prefix_
94
95 \f
96 // Local Variables:
97 // mode: c++
98 // fill-column: 100
99 // c-file-style: "senf"
100 // indent-tabs-mode: nil
101 // ispell-local-dictionary: "american"
102 // compile-command: "scons -u test"
103 // comment-column: 40
104 // End: