Closing a LivePacketDevice

May 13, 2011 at 2:53 PM

There's a method to 'Open' a LivePacketDevice, but there's no corresponding 'Close.'

1) Is 'Open' really a misnomer for 'GetPacketCommunicator'?

2) Is there any reason not to Open a LivePacketDevice more than once in the same session? For example, I first Open AllLocalMachine LivePacketDevices to 'discover' which one is transmitting my App-specific ethernet packet types. After discovery of valid ethernet adaptor, I save this adaptor's identify (including MacAddress). Later, I initiate a comm-session with the discovered adaptor. During this post-discovery session, I intend to exchange packets (send and receive) with the discovered adaptor, so I re-open. This appears to be working, but are there issues with this approach?



May 13, 2011 at 9:51 PM

Please confirm what I alluded to above:

1) After I Open a single LivePacketDevice, I am free to issue both .ReceivePacket() and .SendPacket() calls on the same opened device in the same session.

2) The 'name of the device' comment in the code snippet below (there are several such instances in the tutorials) is not correct.

using (PacketCommunicator communicator = selectedDevice.Open(100, // name of the device
                                                             PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                                                             1000)) // read timeout
But what IS 100?

3) Why do I want to be .Promiscuous if I'm only issuing .ReceivePacket() and .SendPacket() calls?



May 16, 2011 at 9:12 PM

I verified 1), above, but until I added the 'NoCaptureLocal' PacketDeviceOpenAttribute, whenever I sent a packet, I received it myself. The following code snippet fixed my problem and allowed the sent packet to reach the destination:

                _communicator = applNetworkAdaptorConnectedToAmp.Open(
                    65536, // portion of the packet to capture; 65536 > any ethernet payload and just insures we get it all
                        | PacketDeviceOpenAttributes.MaximumResponsiveness
                        | PacketDeviceOpenAttributes.NoCaptureLocal,
                    200); // timeout is ms

I'm still unclear about the need for Promiscuous, and I just added MaximumResponsiveness because it sounded good.

May 20, 2011 at 3:19 PM

Hi sandrews,

Sorry for the late response.


Yes, Open() creates a PacketCommunicator that you need to dispose when finish with it.

Yes, you can create more than one PacketCommunicator on the same Device.

The different PacketDeviceOpenAttributes are documented.

NoCaptureLocal does make the communicator not capture its own generated packets, but in a lot of cases you filter that anyways so there's no need to specify it.

Promiscuous mode means that the communicator will try to capture packets that aren't aimed to that device (most simple Ethernet device drivers support this, with Wifi devices this is more complicated).

You can read more about these flags here:


I've added more detailed description in the code and it will be available in the next version of Pcap.Net.