Question

I'm making program that should receive packet and send it on the other port on PC (other port is doing the same, also send what he gets), based on MAC address. But when I open device like this:

device_port1.Open(DeviceMode.Promiscuous);

and then send some packet on one port, that same port get that same packet like it was received. And when both adapters are doing the same, they are sending each other one packet over and over.

How could I stopped this? I tried

device_port1.Open(OpenFlags.NoCaptureLocal, 1000);

but then it wasn't sending anything thru that program (and then it's useless).

This is the code:

        device_port0 = devices[pole[0]];
        device_port0.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival_port0);
        //device_port0.Open(OpenFlags.NoCaptureLocal, 1000);
        device_port0.Open(DeviceMode.Promiscuous);
        device_port0.StartCapture();

And onPacketArrival

private void device_OnPacketArrival_port0(object sender, CaptureEventArgs packet)
        {
            device_port1 = devices[pole[1]];
            device_port1.Open();

            try
            {
                device_port1.SendPacket(packet.Packet.Data);
            }
            catch (Exception ee)
            {
                Console.Writeline("Exception: " + ee.Message);
            }
        }

And on the port1 is the same. It just send what he gets and that's the reason for the loop.

Was it helpful?

Solution

I take it both Network cards have the same address? If that is NOT the case then, before forwarding a packet you have to check if the packet's destination network is the network connected to the second network card.

If however both cards have the same address, then the only solution i can see (I'm no expert) is to have some sort of list where you store the packets for a short time after sending them. And every time you capture a packet you check if it already is in the list(to check if it's one you've already sent). This way of solving your problem is inefficient as every packet sent is resent back again But it beats infinity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top