diff --git a/examples/Makefile.in b/examples/Makefile.in index 620c5d9..78710cc 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -1,26 +1,25 @@ CXX=@CXX@ -CXXFLAGS=-c -Wall @CXXFLAGS@ -LDFLAGS=-lpcap -ltins -lpthread -SOURCES=arpspoofing.cpp portscan.cpp +CXXFLAGS=-Wall @CXXFLAGS@ +LDFLAGS=-ltins +EXECUTABLES=arpspoof portscan traceroute beacon_display -OBJECTS=$(SOURCES:.cpp=.o) -INCLUDE= -EXECUTABLES=arpspoof portscan traceroute - -all: $(SOURCES) $(EXECUTABLES) +all: $(EXECUTABLES) compile: $(OBJECTS) recompile: clean all -arpspoof: arpspoofing.o - $(CXX) arpspoofing.o $(LDFLAGS) -o arpspoof +arpspoof: + $(CXX) arpspoofing.cpp -o arpspoofing $(CXXFLAGS) $(LDFLAGS) -portscan: portscan.o - $(CXX) portscan.o $(LDFLAGS) -o portscan +beacon_display: + $(CXX) beacon_display.cpp -o beacon_display $(CXXFLAGS) $(LDFLAGS) + +portscan: + $(CXX) portscan.cpp -o portscan $(CXXFLAGS) $(LDFLAGS) -lpthread traceroute: - $(CXX) traceroute.cpp -o traceroute -std=c++0x -Wall $(LDFLAGS) + $(CXX) traceroute.cpp -o traceroute -std=c++0x $(CXXFLAGS) $(LDFLAGS) .cpp.o: $(CXX) $(CXXFLAGS) $(INCLUDE) $< -o $@ diff --git a/examples/beacon_display.cpp b/examples/beacon_display.cpp new file mode 100644 index 0000000..32eaa01 --- /dev/null +++ b/examples/beacon_display.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +using namespace Tins; + +class BeaconSniffer { +public: + void run(const std::string &iface); +private: + typedef Dot11::address_type address_type; + typedef std::map ssids_type; + + bool callback(PDU &pdu); + + ssids_type ssids; +}; + +void BeaconSniffer::run(const std::string &iface) { + Sniffer sniffer(iface, 1500, true, "type mgt subtype beacon"); + sniffer.sniff_loop(make_sniffer_handler(this, &BeaconSniffer::callback)); +} + +bool BeaconSniffer::callback(PDU &pdu) { + Dot11Beacon *beacon = pdu.find_pdu(); + if(beacon && !beacon->from_ds() && !beacon->to_ds()) { + address_type addr = beacon->addr2(); + ssids_type::iterator it = ssids.find(addr); + if(it == ssids.end()) { + try { + it = ssids.insert(std::make_pair(addr, beacon->ssid())).first; + std::cout << it->first << " - " << it->second << std::endl; + } + catch(std::runtime_error&) { + // no ssid, just ignore it. + } + } + } + return true; +} + +int main(int argc, char* argv[]) { + std::string interface = "wlan0"; + if(argc == 2) + interface = argv[1]; + BeaconSniffer sniffer; + sniffer.run(interface); +} diff --git a/include/pdu.h b/include/pdu.h index 0f769d7..1103710 100644 --- a/include/pdu.h +++ b/include/pdu.h @@ -189,7 +189,7 @@ namespace Tins { T *find_pdu(PDUType type = T::pdu_flag) { PDU *pdu = this; while(pdu) { - if(pdu->pdu_type() == type) + if(pdu->matches_flag(type)) return static_cast(pdu); pdu = pdu->inner_pdu(); } diff --git a/src/radiotap.cpp b/src/radiotap.cpp index e092974..3b37e6b 100644 --- a/src/radiotap.cpp +++ b/src/radiotap.cpp @@ -115,7 +115,14 @@ Tins::RadioTap::RadioTap(const uint8_t *buffer, uint32_t total_sz) buffer += sizeof(_rx_flags); total_sz -= sizeof(_rx_flags); } - if(total_sz) + if((flags() & FCS) != 0) { + if(total_sz <= 4) + throw std::runtime_error(msg); + else { + total_sz -= sizeof(uint32_t); + } + } + if(total_sz) inner_pdu(Dot11::from_bytes(buffer, total_sz)); }