mfontanini / libtins

High-level, multiplatform C++ network packet sniffing and crafting library.
http://libtins.github.io/
BSD 2-Clause "Simplified" License
1.89k stars 374 forks source link

Question about next_packet() method in the Sniffer class. #482

Open gleb-kun opened 2 years ago

gleb-kun commented 2 years ago

Hello and thanks for your work!

I have a question about using a Sniffer. I use Sniffer like this:

// Init
Tins::SnifferConfiguration snifferConfiguration;
snifferConfiguration.set_promisc_mode(true);
std::unique_ptr<Tins::Sniffer> sniffer = std::make_unique<Tins::Sniffer>(interfaceName, snifferConfiguration);
...

// Sniff
void f1()
{
  Tins::PDU *currentPduPacket = sniffer->next_packet();
  ...
     // Doing the processing
  ...
}

// Change channel
void f2()
{
  ...
  // Executing a channel change
  ...
}

Functions f1() and f2() are executed on a timer in the same thread. If there is no packets on some channel, then next_packet() method will wait until the packet appears, although it may never appear. Is there any way I can make sure there is a potential packet to capture before executing next_packet() method? Or if there is no package, then after some time, break the execution of the next_packet() method?