Whats wrong with this packet and why i cannot fix it ?

Jan 19, 2013 at 8:54 AM

i try to fix this packet and i dont know how, in Wireshark it's seems the the checksum is bad but with this code It does not help me to fix it:

        public Packet fixBadChecksum(Packet packet)
        {
            try
            {
                EthernetLayer ethernet = (EthernetLayer)packet.Ethernet.ExtractLayer();
                IpV4Layer ipV4Layer = (IpV4Layer)packet.Ethernet.IpV4.ExtractLayer();
                PayloadLayer payload = (PayloadLayer)packet.Ethernet.IpV4.Payload.ExtractLayer();
                DateTime packetTimestamp = packet.Timestamp;
                ipV4Layer.HeaderChecksum = null;

                return PacketBuilder.Build(packetTimestamp, ethernet, ipV4Layer, payload);
            }
            catch (Exception)
            {
                return null;
            }
        }
pcap file: http://www.freefilehosting.net/1_26

Coordinator
Jan 19, 2013 at 10:48 AM

Is the pcap file you've linked to is after the fix or before?

If it is before the fix, can you link to what you get after?

Jan 19, 2013 at 1:28 PM
Edited Jan 19, 2013 at 1:29 PM

the pcap file is before the fix because after i cannot get any packet

Coordinator
Jan 24, 2013 at 6:55 PM

Why can't you get any packet?

What happens when you save the resulting packets to a .pcap file?

Jan 25, 2013 at 12:36 PM
Edited Jan 25, 2013 at 12:38 PM

the pcap file is empty, see my code:

    class Program
    {
        static void Main(string[] args)
        {            
            IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;
            for (int i = 0; i != allDevices.Count; ++i)
            {
                LivePacketDevice device = allDevices[i];
                Console.Write((i + 1) + ". " + device.Name);
                if (device.Description != null)
                {
                    Console.WriteLine(" (" + device.Description + ")");
                }
                else
                {
                    Console.WriteLine(" (No description available)");
                }
            }

            PacketDevice selectedOutputDevice = allDevices[int.Parse(args[0])];
            long capLength = new FileInfo(args[1]).Length;
            bool isSync = true;
            OfflinePacketDevice selectedInputDevice = new OfflinePacketDevice(args[1]);
            List<Packet> packetList = new List<Packet>();
            using (PacketCommunicator inputCommunicator = selectedInputDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
            {
                using (PacketCommunicator outputCommunicator = selectedOutputDevice.Open(100, PacketDeviceOpenAttributes.Promiscuous, 1000))
                {
                    using (PacketSendBuffer sendBuffer = new PacketSendBuffer((uint)capLength))
                    {
                        Packet packet;
                        while (inputCommunicator.ReceivePacket(out packet) == PacketCommunicatorReceiveResult.Ok)
                        {
                            packet = fixBadChecksum(packet);

                            if (packet.IsValid)
                            {
                                sendBuffer.Enqueue(packet);
                            }
                        }

                        PacketDumpFile.Dump(@"path", DataLinkKind.Ethernet, PacketDevice.DefaultSnapshotLength, packetList);

                        try
                        {
                            outputCommunicator.Transmit(sendBuffer, isSync);
                        }
                        catch (Exception)
                        {

                        }
                    }
                }
            }
        }

        public static Packet fixBadChecksum(Packet packet)
        {
            try
            {
                EthernetLayer ethernet = (EthernetLayer)packet.Ethernet.ExtractLayer();
                IpV4Layer ipV4Layer = (IpV4Layer)packet.Ethernet.IpV4.ExtractLayer();
                PayloadLayer payload = (PayloadLayer)packet.Ethernet.IpV4.Payload.ExtractLayer();
                DateTime packetTimestamp = packet.Timestamp;
                ipV4Layer.HeaderChecksum = null;

                return PacketBuilder.Build(packetTimestamp, ethernet, ipV4Layer, payload);
            }
            catch (Exception)
            {
                return null;
            }
        }
    }

Coordinator
Feb 8, 2013 at 11:46 AM
You don't fill the packetList before dumping it to a file.
That's why it's empty.