1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-28 20:44:26 +01:00

Sniffer now differentiates between EthernetII and Dot3 when sniffing.

This commit is contained in:
Matias Fontanini
2013-04-23 22:55:32 -03:00
parent eb87b82c17
commit 5197e7f5f1
3 changed files with 16 additions and 4 deletions

View File

@@ -55,6 +55,7 @@ public:
RADIOTAP = DLT_IEEE802_11_RADIO,
DOT11 = DLT_IEEE802_11,
ETH2 = DLT_EN10MB,
DOT3 = DLT_EN10MB,
SLL = DLT_LINUX_SLL
};

View File

@@ -42,6 +42,7 @@
#include "packet.h"
#include "loopback.h"
#include "dot11.h"
#include "dot3.h"
#include "sll.h"
#include "cxxstd.h"
#include "exceptions.h"
@@ -221,6 +222,9 @@ namespace Tins {
BaseSniffer(const BaseSniffer&);
BaseSniffer &operator=(const BaseSniffer&);
static bool is_dot3(const uint8_t *ptr, size_t sz) {
return (sz >= 13 && ptr[12] < 8);
}
template<class ConcretePDU, class Functor>
static bool call_functor(LoopData<Functor> *data, const u_char *packet, const struct pcap_pkthdr *header);
@@ -299,8 +303,11 @@ namespace Tins {
PCapLoopBreaker _(ret_val, data->handle);
try {
Internals::smart_ptr<PDU>::type pdu;
if(data->iface_type == DLT_EN10MB)
ret_val = call_functor<Tins::EthernetII>(data, packet, header);
if(data->iface_type == DLT_EN10MB) {
ret_val = is_dot3((const uint8_t*)packet, header->caplen) ?
call_functor<Tins::Dot3>(data, packet, header) :
call_functor<Tins::EthernetII>(data, packet, header);
}
else if(data->iface_type == DLT_IEEE802_11_RADIO)
ret_val = call_functor<Tins::RadioTap>(data, packet, header);
else if(data->iface_type == DLT_IEEE802_11) {

View File

@@ -70,8 +70,12 @@ PtrPacket BaseSniffer::next_packet() {
// timestamp_ = header.ts;
if(content) {
try {
if(iface_type == DLT_EN10MB)
ret = new EthernetII((const uint8_t*)content, header.caplen);
if(iface_type == DLT_EN10MB) {
if(is_dot3((const uint8_t*)content, header.caplen))
ret = new Dot3((const uint8_t*)content, header.caplen);
else
ret = new EthernetII((const uint8_t*)content, header.caplen);
}
else if(iface_type == DLT_IEEE802_11_RADIO)
ret = new RadioTap((const uint8_t*)content, header.caplen);
else if(iface_type == DLT_IEEE802_11)