This is a minimum pcap wrapper that creates a live Tx or Rx object for a network interface. For a more comprehensive tool check out PcapPlusPlus.
For some applications, an interface may be created prior to creating Chipset::Rx or Chipset::Tx instances, then the name of that interface shall be passed to Chipset::Rx / Chipset::Tx constructors.
Here is an example of creating a new interface on a wifi card on a linux machine with iw tool:
>> iw PHY_NAME interface add INTERFACE_NAME type monitor flags fcsfail control
>> ifconfig INTERFACE_NAME up-
PHY_NAMEis usually something likephy2(you can typeiwto get a list of avaiable phys and declared interfaces on eachphy). -
INTERFACE_NAMEis arbitrary and is the name that should be passed toChipset::Rx/Chipset::Txconstructors. -
In many cases the interface needs to be in
monitormode to allow arbitrary Tx or receive frames that are not addressed to the device. -
fscfailand andcontrolflags are optional, you can learn more about the flags in iw manual. -
In some cases depending on the wifi card, other interfaces on the same card should be down. To shut down and interface (
wlan1) for example:>> ifconfig wlan1 down
#include <unistd.h>
#include "chipset_rx.h"
#include "chipset_tx.h"
// all debug messages are printed to std::cout
bool verbose = true;
// Warnings are always printed to std::cout, errors to std::cerr. See out.h.
void rx_callback(uint64_t timeStamp, std::string packet){
/* take care of the incoming packet */
std::cout << timeStamp;
}
int main(int argc, char **argv)
{
Chipset::Rx rx("rxInterfaceName", rx_callback);
// Set filter (optional)
std::string filter ("ether host 00:de:ad:be:ef:00");
rx.setFilter(filter);
// Open interface for capturing
rx.open();
// Run for 10 seconds
usleep(10000);
// Stop capture
rx.stop();
return 0;
}