You either need to hardcode the name of the Wi-Fi device (probably wlan0
) into your program, or give it a UI option (command-line flag, etc.) to let the user specify the device on which to capture traffic.
There is no setting on your system that will change the device returned by pcap_lookupdev()
.
Tcpdump and Wireshark/TShark/etc. have a -i
command-line option to specify the device on which to capture, and Wireshark has a GUI dialog to allow the user to specify it. They don't rely on pcap_lookupdev()
if the user specifies the device explicitly.
Note that if you're capturing on Wi-Fi, you will, by default, only capture traffic to and from your machine. If you want to capture all the traffic on your network, including traffic to and from other machines, you will need to capture in monitor mode; newer versions of libpcap have APIs to support that, but they're only guaranteed to work on OS X (for various complicated reasons, they may or may not work on Linux, which, given the device name eth0
, I assume you're using; until that's fixed, you'd need to use something such as aircrack-ng to turn on monitor mode - see the WLAN capture setup page section on Linux in the Wireshark Wiki for informationon that).