0

I am trying to make a program that will receive packets on multiple network devices and send them on other devices (something like software hub). I am using C# and pcapdotnet. This simple method captures communication on device:

    public void sniff(LivePacketDevice device)
    {
        using(PacketCommunicator comm = device.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
        {
            comm.ReceivePackets(0, printandsend);
        }          
    }

In callback method "printandsend" I want to send packets on every device except device where the packet came from. To prevent sending packet to device where it came from, I need to know from which device packet came. Problem is that I cant figure out how to parse currently used device into that callback method. Variable outside of methods is not a solution for me, because capturing packets is used on multiple devices at the same time. Captuting device on the same time si provided by creating threads of "sniff" method.

There is a possible workaround by using method receivePacket:

Packet packet;
While(true)
{
    comm.ReceivePacket(out packet);
    send(packet,device)                
   //this would send packet on every device except the one which is used as a parameter
}

Problem is that I am not sure if this workaround can provide that all packets will be successfully received and sent.

aron23
  • 293
  • 2
  • 3
  • 11

1 Answers1

1

I suggest using ReceivePacket() unless you find you have a real issue that is due to using it.

ReceivePacket() is simple to use and would be good enough for most applications.

If you still want to use ReceivePackets() you can create a class with a callback method and create an instance of this class for each device.

brickner
  • 6,595
  • 3
  • 41
  • 54