mirror of
https://github.com/mfontanini/libtins
synced 2026-01-28 04:34:27 +01:00
The FCS-at-end flag was being ignored in RadioTap. Added beacon display example.
This commit is contained in:
49
examples/beacon_display.cpp
Normal file
49
examples/beacon_display.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <tins/tins.h>
|
||||
|
||||
using namespace Tins;
|
||||
|
||||
class BeaconSniffer {
|
||||
public:
|
||||
void run(const std::string &iface);
|
||||
private:
|
||||
typedef Dot11::address_type address_type;
|
||||
typedef std::map<address_type, std::string> 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<Dot11Beacon>();
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user