-
March 2nd, 2017, 05:30 AM
#1
[RESOLVED] ICMPv6 Checksum
Hey there,
I am trying to figure out how to calculate the [ICMPv6 checksum](https://tools.ietf.org/html/rfc4443#section-2.3).
Let's assume I have an IPv6 packet like this:
Source IP: fe 80 00 00 00 00 00 00 be ae c5 ff fe df 31 d1
Destination IP: ff 02 00 00 00 00 00 00 00 00 00 00 00 00 00 01
Payload length: 00 18
Next header: 3a
ICMPv6: 80 00 00 c8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
What I am doing wrong when performing this calculation:
sum of:
fe80
0
0
0
beae
c5ff
fedf
31d1
ff02
0
0
0
0
0
0
1
18
3a
8000
now moving the bytes and adding them to the end
result now is 3337
inverting the value
result is c800
wireshark says it should be ccc8
I can't find the mistake here, can anyone please take a look at it?
Thanks and have a nice day!
Here is the wireshark screenshot:
http://i.imgur.com/Y7HaDZS.jpg
-
March 2nd, 2017, 06:40 AM
#2
Re: ICMPv6 Checksum
What is the type of sum? Consider
Code:
#include <iostream>
using namespace std;
int main()
{
short int chk = 0x3337;
short int inv = ~chk;
cout << hex << "0x" << chk << " 0x" << inv << endl;
}
which displays
Last edited by 2kaud; March 2nd, 2017 at 06:49 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 2nd, 2017, 08:57 AM
#3
Re: ICMPv6 Checksum
From the data in post #1,
Code:
#include <iostream>
using namespace std;
int main()
{
const unsigned short int bytes[] = {
0xfe80, 0x0000, 0x0000, 0x0000, 0xbeae, 0xc5ff, 0xfedf, 0x31d1,
0xff02, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001,
0x0018,
0x003a,
0x8000};
unsigned int sum = 0;
for (auto i : bytes)
sum += i;
while (sum & 0xffff0000)
sum = (sum >> 16) + (sum & 0xffff);
sum = ~sum;
cout << hex << "0x" << (unsigned short) sum << endl;
}
displays
Last edited by 2kaud; March 2nd, 2017 at 11:29 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 2nd, 2017, 01:42 PM
#4
Re: ICMPv6 Checksum
Originally Posted by 2kaud
From the data in post #1,
Code:
#include <iostream>
using namespace std;
int main()
{
const unsigned short int bytes[] = {
0xfe80, 0x0000, 0x0000, 0x0000, 0xbeae, 0xc5ff, 0xfedf, 0x31d1,
0xff02, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001,
0x0018,
0x003a,
0x8000};
....
Thank you so much for this check. The problem was in the data type but this has really helped me!
-
March 2nd, 2017, 01:43 PM
#5
Re: ICMPv6 Checksum
Originally Posted by 2kaud
What is the type of sum? Consider
Code:
#include <iostream>
using namespace std;
int main()
{
short int chk = 0x3337;
short int inv = ~chk;
cout << hex << "0x" << chk << " 0x" << inv << endl;
}
which displays
Many thanks. Now I feel really dumb. It was the data type after all...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|