compilation error when change the IP Destination after moving from DLLS v0.6 to v0.10.0

Sep 6, 2012 at 9:27 AM
Edited Sep 6, 2012 at 3:28 PM

this is my function who change the ip packet and after moving to the new DLLs Property or indexer 'PcapDotNet.Packets.IpV4.IpV4Layer.Destination' cannot be assigned to -- it is read only error received, this function work fine without any compilation error with v0.6 DLL's (marked in red)

 

 

        public static Packet changePacketIp(Packet packet, string oldIpAddress, string newIpAddress)
        {
            EthernetLayer ethernet = (EthernetLayer)packet.Ethernet.ExtractLayer();
            IpV4Layer ipLayer = (IpV4Layer)packet.Ethernet.IpV4.ExtractLayer();
            DateTime packetTimestamp = packet.Timestamp;
            ILayer payload = null;
            Packet newPacket = null;
            TcpLayer tcpLayer = null;
            UdpLayer udpLayer = null;

            if (packet.Ethernet.IpV4.Protocol.ToString() == "Tcp")
            {
                payload = packet.Ethernet.IpV4.Tcp.Payload.ExtractLayer();
                tcpLayer = (TcpLayer)packet.Ethernet.IpV4.Tcp.ExtractLayer();
                tcpLayer.Checksum = null;

                if (packet.Ethernet.IpV4.Source.ToString() == oldIpAddress)
                {
                    ipLayer.Source = new IpV4Address(newIpAddress);
                    ipLayer.HeaderChecksum = null;
                }
                else if (packet.Ethernet.IpV4.Destination.ToString() == oldIpAddress)
                {
                    ipLayer.Destination = new IpV4Address(newIpAddress);
                    ipLayer.HeaderChecksum = null;
                }

                newPacket = PacketBuilder.Build(packetTimestamp, ethernet, ipLayer, tcpLayer, payload);
            }
            else if (packet.Ethernet.IpV4.Protocol.ToString() == "Udp")
            {
                payload = packet.Ethernet.IpV4.Udp.Payload.ExtractLayer();
                udpLayer = (UdpLayer)packet.Ethernet.IpV4.Udp.ExtractLayer();
                udpLayer.Checksum = null;

                if (packet.Ethernet.IpV4.Source.ToString() == oldIpAddress)
                {
                    ipLayer.Source = new IpV4Address(newIpAddress);
                    ipLayer.HeaderChecksum = null;
                }
                else if (packet.Ethernet.IpV4.Destination.ToString() == oldIpAddress)
                {
                    ipLayer.Destination = new IpV4Address(newIpAddress);
                    ipLayer.HeaderChecksum = null;
                }

                newPacket = PacketBuilder.Build(packetTimestamp, ethernet, ipLayer, udpLayer, payload);
            }

            return newPacket;
        }
Coordinator
Sep 7, 2012 at 9:13 AM

Hi schmaichel,

 

Please use CurrentDestination property instead.

Destination is used for the final destination of the packet, which is calculated based on the current destination and source routing options.

 

I hope this helps,

 

Boaz.

Sep 7, 2012 at 12:20 PM

you mean ipLayer.CurrentDestination= new IpV4Address(newIpAddress); ?

Coordinator
Sep 7, 2012 at 12:36 PM

Yes.

Sep 7, 2012 at 3:46 PM

Thanks a lot !

Gal