Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C语言中的IP报头校验和函数#_C#_Packet - Fatal编程技术网

C# C语言中的IP报头校验和函数#

C# C语言中的IP报头校验和函数#,c#,packet,C#,Packet,我有数据包字节[]: byte[] arr = { 17, 34, 51, 68, 85, 102, 0, 20, 34, 24, 129, 17, 8, 0, 69, 0, 0, 95, 88, 117, 0, 0, 128, 17, 136, 254, 10, 61, 50, 135, 172, 49, 112, 37, 9, 129, 6, 110, 0, 75, 244, 143, 4, 1, 0, 67, 0, 0, 0, 0, 0, 0, 0, 0,

我有
数据包
字节[]

byte[] arr = {
    17, 34, 51, 68, 85, 102, 0, 20, 34, 24, 129, 17, 8, 0, 69, 0, 0, 95,
    88, 117, 0, 0, 128, 17, 136, 254, 10, 61, 50, 135, 172, 49, 112, 37,
    9, 129, 6, 110, 0, 75, 244, 143, 4, 1, 0, 67, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 107, 105, 110, 111, 8, 6, 10, 61 ,50, 135,
    9, 6, 255, 255, 255, 255, 31, 8, 55, 55, 55, 55, 55, 55, 40, 6, 0, 0, 0,
    1, 44, 6, 53, 53, 53, 53, 30, 9, 55, 53, 50, 50, 53, 53, 53 };
我想做的是尝试更改我的
数据包
IP地址,这样我就找到了计算
校验和的函数,我只想了解我需要向这个函数发送哪些参数(我在网络方面没有太多知识,我开始学习)

那就是

// calculate the checksum
ushort checksum = XYClassName.ComputeHeaderIpChecksum(arr, 0, arr.Length);

// create header from checksum and data
byte[] header = new byte[arr.Length + 2];
Array.Copy(arr, 0, header, 2, arr.Length);
header[0] = checksum >> 8; // high byte first
header[1] = checksum & 0xff; // low byte 2nd

例如,如果我更改了4个字节的IP地址,则在此之后将更改后的数组发送到此函数,并将更改前的2个字节发送到此函数?使用first ComputeHeaderIpChecksum,然后更新?是,如果要在开头“插入”校验和。新的数据(带校验和)是
标题
数组。很抱歉,我不知道首先要做什么以及如何做,你能更新你的答案并告诉我如何做吗?试试我更新的答案,它非常简单。我甚至为你写了一些评论。。。
// calculate the checksum
ushort checksum = XYClassName.ComputeHeaderIpChecksum(arr, 0, arr.Length);

// create header from checksum and data
byte[] header = new byte[arr.Length + 2];
Array.Copy(arr, 0, header, 2, arr.Length);
header[0] = checksum >> 8; // high byte first
header[1] = checksum & 0xff; // low byte 2nd