1

Closed

How to increase the performance with communicator.ReceivePackets?

description

Hi guys,
Could you please show me the way to speed up our application when receiving response packet? Here is my code:
using (PacketCommunicator communicator =
            selected.Open(65536,                                  // 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
        {
            // Check the link layer. We support only Ethernet for simplicity.
            if (communicator.DataLink.Kind != DataLinkKind.Ethernet)
            {
                Console.WriteLine("This program works only on Ethernet networks.");
                return;
            }

             filterSetting = string.Format("ip dst net 192.168.0.0 mask {1} and (broadcast and not multicast)", localIp.GetNetworkAddress(subnetmask).ToString(), subnetmask.ToString());
                communicator.SetFilter(filterSetting);
            // Retrieve the packets
            Packet packet;
            do
            {
                PacketCommunicatorReceiveResult result = communicator.ReceivePackets(100, PacketHandler);

            } while (true);


             // Callback function invoked by libpcap for every incoming packet
    private static void PacketHandler(Packet packet)
    {
        IpV4Datagram ip = packet.Ethernet.IpV4;
        UdpDatagram udp = ip.Udp;
        string addressMac = packet.Ethernet.Destination.ToString();;
        if (!lst.Contains(ip.Destination.ToString()))
        {
            lst.Add(ip.Destination.ToString());
            Console.WriteLine(ip.Destination.ToString() + " -mac : " + addressMac + " - total: " + lst.Count);
        }
    }
Closed Feb 27, 2016 at 8:46 AM by Brickner
Please use https://groups.google.com/forum/#!forum/pcapdotnet to ask questions regarding Pcap.Net.

comments