You do know that an IP packet has a checksum that has to be recalculated to match the new IP address? http://en.wikipedia.org/wiki/IPv4_header_checksum
After change packet IP Address using PcapDotNet DLLs also additional value except the packet IP Address changed
Вопрос
I am using PcapDotNet
DLLs in my application and while changing packet IP Address
and it seems that another value is changed except the IP Address
.
This is how i am change the 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;
}
}
For example, the original packets is:
http://i.stack.imgur.com/vEWuS.jpg
And the new packet after the IP Address has changed:
http://s8.postimg.org/4o78hzmyt/New_Packet.jpg
As you can see after change the IP Address
from 212.25.99.74
into 80.81.82.83
, another 2 bytes changes: from e6 16
into 7a d6
This is the way to change IPv4
packet or its a bug ?
What is this 2 bytes ?
Решение
Не связан с StackOverflow