How to auto select device to send packets into internet with PcapDotNet?

301 Views Asked by At

I'm doing some experimentation with sending/getting data from internet using PcapDotNet, starting with this example.

What bothers me is, that here you've got to select a device to send your packets through. When I was doing some higher level (even socket) programming, I've never had to deal with this issue. Is there any way to auto select network device to use, except pinging the server you want to contact using each of the devices? How is this normally done?

1

There are 1 best solutions below

1
On

Sockets work at a higher level in the stack and bind to an ipaddress. The NIC that is bind to that address handles the traffic.

Pcap works at a lower level and directly accesses the NIC. That causes you to select a device.

You can mimic the autoselect by enumerating the devices and select the device that is bound to the requested IP-address/network