我在我的应用程序中使用PcapDotNet
DLL,在更改数据包IP Address
时,似乎除IP Address
之外的其他值已更改。
这是我改变IP Address
:
private Packet ChangePacketIp(Packet packet, IpV4Address oldIpAddress, IpV4Address newIpAddress)
{
try
{
EthernetLayer ethernet = (EthernetLayer)packet.Ethernet.ExtractLayer();
IpV4Layer ipV4Layer = (IpV4Layer)packet.Ethernet.IpV4.ExtractLayer();
IpV4Datagram ipV4Datagram = packet.Ethernet.IpV4;
ILayer layer = ipV4Datagram.ExtractLayer();
DateTime packetTimestamp = packet.Timestamp;
ILayer payload = packet.Ethernet.IpV4.Payload.ExtractLayer();
if (packet.Ethernet.IpV4.Source == oldIpAddress)
{
ipV4Layer.Source = newIpAddress;
ipV4Layer.HeaderChecksum = null;
}
else if (packet.Ethernet.IpV4.Destination == oldIpAddress)
{
ipV4Layer.CurrentDestination = newIpAddress;
ipV4Layer.HeaderChecksum = null;
}
return PacketBuilder.Build(packetTimestamp, ethernet, ipV4Layer, payload);
}
catch (Exception)
{
return null;
}
}
例如,原始数据包是:
http://i.stack.imgur.com/vEWuS.jpg
IP地址更改后的新数据包:
http://s8.postimg.org/4o78hzmyt/New_Packet.jpg
在将IP Address
从212.25.99.74
更改为80.81.82.83
之后,您可以看到另外2个字节的变化:从e6 16
变为7a d6
这是更改IPv4
数据包或其错误的方法吗?
这2个字节是什么?
答案 0 :(得分:1)
您是否知道IP数据包的校验和必须重新计算以匹配新的IP地址? http://en.wikipedia.org/wiki/IPv4_header_checksum