我正在使用PcapDorNet
DLL,我试图分割我的流量:
private IEnumerable<Packet> SplitPacket(Packet packet, int numberOfFragments)
{
IpV4Datagram ipV4Datagram = packet.Ethernet.IpV4;
Datagram datagram = packet.Ethernet.IpV4.Payload;
TransportLayer transportlayer = GetTransportLayer(packet);
if (transportlayer != null)
{
EthernetLayer ethernet = (EthernetLayer)packet.Ethernet.ExtractLayer();
ILayer layer = packet.Ethernet.IpV4.ExtractLayer();
IpV4Layer ipV4Layer = (IpV4Layer)packet.Ethernet.IpV4.ExtractLayer();
ipV4Layer.HeaderChecksum = null;
DateTime packetTimestamp = packet.Timestamp;
PayloadLayer payload = (PayloadLayer)packet.Ethernet.IpV4.Payload.ExtractLayer(); //extract the data
int totalLength = payload.Length;
int partialLength = totalLength / numberOfFragments; //split data into smaller segments
partialLength = (partialLength / 8) * 8; //make sure it's divisible with 8
if (partialLength == 0)
partialLength = 8;
//(http://en.wikipedia.org/wiki/IPv4#Fragmentation_and_reassembly)
ushort offset = 0; //send one by one
while (offset < totalLength)
{
int fragmentLength = partialLength; //get length for this fragment
IpV4FragmentationOptions options = IpV4FragmentationOptions.MoreFragments;
if (offset + fragmentLength >= totalLength) //is this the last fragment ? trim length if needed
{
options = IpV4FragmentationOptions.None;
fragmentLength = totalLength - offset;
}
byte[] newBuffer = ipV4Datagram.Payload.ToArray(); //copy the actual data into a new buffer
PayloadLayer newPayload = new PayloadLayer { Data = new Datagram(newBuffer, offset, fragmentLength) };
ipV4Layer.Fragmentation = new IpV4Fragmentation(options, offset); //change IP layer fragmentation options
transportlayer.Checksum = null;
yield return PacketBuilder.Build(packetTimestamp, ethernet, ipV4Layer, transportlayer, newPayload);
offset += (ushort)fragmentLength; //next offset
}
}
}
我的输入数据包是TCP packet
,输出是4个数据包:3 IPv4 packets
,最后一个是TCP
但是我收到的这个数据包显示在TCP层字段下这条消息:
校验和:0x5d17 [不正确,应为0xabb7(可能由&#34; TCP引起) 校验和卸载&#34;?)]
使用UDP似乎每个UDP数据包也分成几个IPv4数据包,最后一个是UDP,但在UDP情况下它看起来很好。 我做错了什么?
请查看原始数据包和碎片:http://www.filedropper.com/desktop_122