Вопрос

I using this project DLLs and after change 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;
    }
}

I need to set the UDP/TCP checksum to null before building the packet so try;

packet.Ethernet.IpV4.Tcp.Checksum = null;

But ushort is a non nullable value type, any idea how to do that ?

Это было полезно?

Решение

As per http://pcapdotnet.codeplex.com/discussions/349978 try this:

    //IP
    IpV4Layer ipLayer = (IpV4Layer)packet.Ethernet.IpV4.ExtractLayer();
    ipLayer.HeaderChecksum = null;

    //TCP
    TransportLayer transportLayer = (TransportLayer)packet.Ethernet.IpV4.Transport.ExtractLayer();
    transportLayer.Checksum = null;

    //UDP
    UdpLayer udpLayer = (UdpLayer)packet.Ethernet.IpV4.Udp.ExtractLayer();
    udpLayer.Checksum = null;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top