PCap.Net code appears to be optimized out

38 views
Skip to first unread message

Jack Gold

unread,
Oct 25, 2023, 12:06:28 PM10/25/23
to Pcap.Net Q&A
I have a function that works fine and when I try to incorporate the code below, it appears that my function is optimized out and just throws an exception:

 private bool DumpPcap()
        {

            string ext = Path.GetExtension(textBox_ServerFilePath.Text);

            if (ext.Equals(".pcapng"))
            {
                // process PCAP file
                // Create the offline device
                OfflinePacketDevice selectedDevice = new OfflinePacketDevice(textBox_ServerFilePath.Text);

                // Open the capture file
                using (PacketCommunicator communicator =
                    selectedDevice.Open(Convert.ToInt32(textBox_ClientPortNumber.Text), // portion of the packet to capture
                                                                                        // 65536 guarantees that the whole packet will be captured on all the link layers
                                        PacketDeviceOpenAttributes.Promiscuous,         // promiscuous mode
                                        1000))                                          // read timeout
                {
                    // Read and dispatch packets until EOF is reached
                    communicator.ReceivePackets(0, DispatcherHandler);
                }

                return true;
            }

return false;
}
Reply all
Reply to author
Forward
0 new messages