mirror of
https://github.com/mfontanini/libtins
synced 2026-01-27 12:14:26 +01:00
Added BaseSniffer::set_extract_raw_pdus.
This commit is contained in:
@@ -200,6 +200,22 @@ namespace Tins {
|
||||
*/
|
||||
void set_timeout(int ms);
|
||||
|
||||
/**
|
||||
* \brief Sets whether to extract RawPDUs or fully parsed packets.
|
||||
*
|
||||
* By default, packets will be parsed starting from link layer.
|
||||
* However, if you're parsing a lot of traffic, then you might
|
||||
* want to extract packets and push them into a queue,
|
||||
* so a consumer can parse them when they're popped.
|
||||
*
|
||||
* This method allows doing that. If the parameter is true,
|
||||
* then packets taken from this BaseSniffer will only contain
|
||||
* a RawPDU which will have to entire contents of the packet.
|
||||
*
|
||||
* \param value Whether to extract RawPDUs or not.
|
||||
*/
|
||||
void set_extract_raw_pdus(bool value);
|
||||
|
||||
/**
|
||||
* \brief Retrieves this sniffer's link type.
|
||||
*
|
||||
@@ -239,6 +255,7 @@ namespace Tins {
|
||||
|
||||
pcap_t *handle;
|
||||
bpf_u_int32 mask;
|
||||
bool extract_raw;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "ethernetII.h"
|
||||
#include "radiotap.h"
|
||||
#include "loopback.h"
|
||||
#include "rawpdu.h"
|
||||
#include "dot3.h"
|
||||
#include "sll.h"
|
||||
#include "ppi.h"
|
||||
@@ -42,7 +43,7 @@ using std::runtime_error;
|
||||
|
||||
namespace Tins {
|
||||
BaseSniffer::BaseSniffer()
|
||||
: handle(0), mask(0)
|
||||
: handle(0), mask(0), extract_raw(false)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -116,7 +117,9 @@ PtrPacket BaseSniffer::next_packet() {
|
||||
sniff_data data;
|
||||
const int iface_type = pcap_datalink(handle);
|
||||
pcap_handler handler = 0;
|
||||
if(iface_type == DLT_EN10MB)
|
||||
if(extract_raw)
|
||||
handler = &sniff_loop_handler<RawPDU>;
|
||||
else if(iface_type == DLT_EN10MB)
|
||||
handler = sniff_loop_eth_handler;
|
||||
else if(iface_type == DLT_IEEE802_11_RADIO) {
|
||||
#ifdef HAVE_DOT11
|
||||
@@ -149,6 +152,10 @@ PtrPacket BaseSniffer::next_packet() {
|
||||
return PtrPacket(data.pdu, data.tv);
|
||||
}
|
||||
|
||||
void BaseSniffer::set_extract_raw_pdus(bool value) {
|
||||
extract_raw = value;
|
||||
}
|
||||
|
||||
void BaseSniffer::stop_sniff() {
|
||||
pcap_breakloop(handle);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user