author | Adrian S Tam <adrian.sw.tam@gmail.com> |
Wed, 07 Dec 2011 11:22:10 -0500 | |
changeset 7619 | b4dee6307aa7 |
parent 7386 | 2310ed220a61 |
child 7717 | cfa1741013dd |
permissions | -rw-r--r-- |
7385
10beb0e53130
standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents:
7256
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
2 |
/* |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
3 |
* Copyright (c) 2005 INRIA |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
4 |
* |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
8 |
* |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
13 |
* |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
17 |
* |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
18 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
19 |
*/ |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
20 |
|
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
21 |
#include "udp-header.h" |
3404
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
22 |
#include "ns3/address-utils.h" |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
23 |
|
1236
cfa5e0b39281
rework the NS_XX_ENSURE_REGISTERED macros and make sure we typecheck the input to TraceContext::Add and TraceContext::Get methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1234
diff
changeset
|
24 |
namespace ns3 { |
1152
1d06449f0a98
macros to ensure proper initialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1151
diff
changeset
|
25 |
|
2643
2a3324f4dabe
define a TypeId for each Header/Trailer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1236
diff
changeset
|
26 |
NS_OBJECT_ENSURE_REGISTERED (UdpHeader); |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
27 |
|
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
28 |
/* The magic values below are used only for debugging. |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
29 |
* They can be used to easily detect memory corruption |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
30 |
* problems so you can see the patterns in memory. |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
31 |
*/ |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
32 |
UdpHeader::UdpHeader () |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
33 |
: m_sourcePort (0xfffd), |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
34 |
m_destinationPort (0xfffd), |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
35 |
m_payloadSize (0xfffd), |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
36 |
m_calcChecksum (false), |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
37 |
m_goodChecksum (true) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
38 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
39 |
} |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
40 |
UdpHeader::~UdpHeader () |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
41 |
{ |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
42 |
m_sourcePort = 0xfffe; |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
43 |
m_destinationPort = 0xfffe; |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
44 |
m_payloadSize = 0xfffe; |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
45 |
} |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
46 |
|
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
47 |
void |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
48 |
UdpHeader::EnableChecksums (void) |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
49 |
{ |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
50 |
m_calcChecksum = true; |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
51 |
} |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
52 |
|
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
53 |
void |
3238
3b24ac252fba
bug 195: naming inconsistency.
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2834
diff
changeset
|
54 |
UdpHeader::SetDestinationPort (uint16_t port) |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
55 |
{ |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
56 |
m_destinationPort = port; |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
57 |
} |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
58 |
void |
3238
3b24ac252fba
bug 195: naming inconsistency.
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2834
diff
changeset
|
59 |
UdpHeader::SetSourcePort (uint16_t port) |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
60 |
{ |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
61 |
m_sourcePort = port; |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
62 |
} |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
63 |
uint16_t |
3238
3b24ac252fba
bug 195: naming inconsistency.
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2834
diff
changeset
|
64 |
UdpHeader::GetSourcePort (void) const |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
65 |
{ |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
66 |
return m_sourcePort; |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
67 |
} |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
68 |
uint16_t |
3238
3b24ac252fba
bug 195: naming inconsistency.
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2834
diff
changeset
|
69 |
UdpHeader::GetDestinationPort (void) const |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
70 |
{ |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
71 |
return m_destinationPort; |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
72 |
} |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
73 |
void |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
74 |
UdpHeader::InitializeChecksum (Ipv4Address source, |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
75 |
Ipv4Address destination, |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
76 |
uint8_t protocol) |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
77 |
{ |
3404
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
78 |
m_source = source; |
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
79 |
m_destination = destination; |
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
80 |
m_protocol = protocol; |
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
81 |
} |
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
82 |
uint16_t |
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
83 |
UdpHeader::CalculateHeaderChecksum (uint16_t size) const |
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
84 |
{ |
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
85 |
Buffer buf = Buffer (12); |
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
86 |
buf.AddAtStart (12); |
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
87 |
Buffer::Iterator it = buf.Begin (); |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
88 |
|
3404
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
89 |
WriteTo (it, m_source); |
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
90 |
WriteTo (it, m_destination); |
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
91 |
it.WriteU8 (0); /* protocol */ |
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
92 |
it.WriteU8 (m_protocol); /* protocol */ |
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
93 |
it.WriteU8 (size >> 8); /* length */ |
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
94 |
it.WriteU8 (size & 0xff); /* length */ |
3363
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
95 |
|
3404
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
96 |
it = buf.Begin (); |
3363
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
97 |
/* we don't CompleteChecksum ( ~ ) now */ |
3404
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
98 |
return ~(it.CalculateIpChecksum (12)); |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
99 |
} |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
100 |
|
3363
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
101 |
bool |
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
102 |
UdpHeader::IsChecksumOk (void) const |
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
103 |
{ |
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
104 |
return m_goodChecksum; |
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
105 |
} |
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
106 |
|
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
107 |
|
2646
c1fef7686472
remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2643
diff
changeset
|
108 |
TypeId |
c1fef7686472
remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2643
diff
changeset
|
109 |
UdpHeader::GetTypeId (void) |
795
cd108c9817d0
add Chunk::GetName and implement it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
524
diff
changeset
|
110 |
{ |
2646
c1fef7686472
remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2643
diff
changeset
|
111 |
static TypeId tid = TypeId ("ns3::UdpHeader") |
c1fef7686472
remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2643
diff
changeset
|
112 |
.SetParent<Header> () |
2650
3de4cacb8981
make sure all headers and trailers gets a constructor registered in their TypeId.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2646
diff
changeset
|
113 |
.AddConstructor<UdpHeader> () |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
114 |
; |
2646
c1fef7686472
remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2643
diff
changeset
|
115 |
return tid; |
795
cd108c9817d0
add Chunk::GetName and implement it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
524
diff
changeset
|
116 |
} |
2646
c1fef7686472
remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2643
diff
changeset
|
117 |
TypeId |
c1fef7686472
remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2643
diff
changeset
|
118 |
UdpHeader::GetInstanceTypeId (void) const |
c1fef7686472
remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2643
diff
changeset
|
119 |
{ |
c1fef7686472
remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2643
diff
changeset
|
120 |
return GetTypeId (); |
c1fef7686472
remove dead code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2643
diff
changeset
|
121 |
} |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
122 |
void |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1152
diff
changeset
|
123 |
UdpHeader::Print (std::ostream &os) const |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
124 |
{ |
2653
b8eff7186c5c
improve pretty-printing output.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2650
diff
changeset
|
125 |
os << "length: " << m_payloadSize + GetSerializedSize () |
b8eff7186c5c
improve pretty-printing output.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2650
diff
changeset
|
126 |
<< " " |
900
2087082ba3ed
change default pretty printing output format, add doc to metadata data structures
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
795
diff
changeset
|
127 |
<< m_sourcePort << " > " << m_destinationPort |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
128 |
; |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
129 |
} |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
130 |
|
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
131 |
uint32_t |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
132 |
UdpHeader::GetSerializedSize (void) const |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
133 |
{ |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
134 |
return 8; |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
135 |
} |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
136 |
|
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
235
diff
changeset
|
137 |
void |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1152
diff
changeset
|
138 |
UdpHeader::Serialize (Buffer::Iterator start) const |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
139 |
{ |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
140 |
Buffer::Iterator i = start; |
3363
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
141 |
|
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
142 |
i.WriteHtonU16 (m_sourcePort); |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
143 |
i.WriteHtonU16 (m_destinationPort); |
3404
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
144 |
i.WriteHtonU16 (start.GetSize ()); |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
145 |
i.WriteU16 (0); |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
146 |
|
3363
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
147 |
if (m_calcChecksum) |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
148 |
{ |
3404
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
149 |
uint16_t headerChecksum = CalculateHeaderChecksum (start.GetSize ()); |
3363
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
150 |
i = start; |
3404
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
151 |
uint16_t checksum = i.CalculateIpChecksum (start.GetSize (), headerChecksum); |
3363
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
152 |
|
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
153 |
i = start; |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
154 |
i.Next (6); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
155 |
i.WriteU16 (checksum); |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
156 |
} |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
157 |
} |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
235
diff
changeset
|
158 |
uint32_t |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1152
diff
changeset
|
159 |
UdpHeader::Deserialize (Buffer::Iterator start) |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
160 |
{ |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
161 |
Buffer::Iterator i = start; |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
162 |
m_sourcePort = i.ReadNtohU16 (); |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
163 |
m_destinationPort = i.ReadNtohU16 (); |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1152
diff
changeset
|
164 |
m_payloadSize = i.ReadNtohU16 () - GetSerializedSize (); |
3404
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
165 |
i.Next (2); |
3363
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
166 |
|
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
167 |
if(m_calcChecksum) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
168 |
{ |
3404
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
169 |
uint16_t headerChecksum = CalculateHeaderChecksum (start.GetSize ()); |
3363
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
170 |
i = start; |
3404
b5d4a04c7b68
bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3363
diff
changeset
|
171 |
uint16_t checksum = i.CalculateIpChecksum (start.GetSize (), headerChecksum); |
3363
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
172 |
|
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
173 |
m_goodChecksum = (checksum == 0); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
174 |
} |
3363
33d1ca2e4ba4
bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
3260
diff
changeset
|
175 |
|
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
235
diff
changeset
|
176 |
return GetSerializedSize (); |
235
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
177 |
} |
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
178 |
|
190d5bef3254
add ipv4 and udp header, add ipv4 checksum support to make the udp header compile. Need to be fixed in UdpHeader later.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
179 |
|
7386
2310ed220a61
standardize ns-3 namespace declaration format
Vedran Miletić <rivanvx@gmail.com>
parents:
7385
diff
changeset
|
180 |
} // namespace ns3 |