1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-28 04:34:27 +01:00

Code cleanup and use same syntax on the entire project

Initial code cleanup

More code cleanup

Cleanup more code

Cleanup Dot11 code

Fix OSX build issue

Cleanup examples

Fix ref and pointer declaration syntax

Fix braces
This commit is contained in:
Matias Fontanini
2016-01-02 08:17:59 -08:00
parent f5a82b1a17
commit d84f10cf08
177 changed files with 13203 additions and 12272 deletions

View File

@@ -33,68 +33,77 @@
#include "dot11/dot11_data.h"
using std::max_element;
using std::pair;
namespace Tins {
bool RSNHandshakeCapturer::process_packet(const PDU &pdu) {
const RSNEAPOL *eapol = pdu.find_pdu<RSNEAPOL>();
const Dot11Data *dot11 = pdu.find_pdu<Dot11Data>();
if(!eapol || !dot11)
return false;
std::pair<address_type, address_type> addresses;
if(dot11->to_ds()) {
addresses.first = dot11->addr1();
addresses.second = dot11->addr2();
}
else if(dot11->from_ds()) {
addresses.first = dot11->addr2();
addresses.second = dot11->addr1();
}
else
return false;
// 1st
if(eapol->key_t() && eapol->key_ack() && !eapol->key_mic() && !eapol->install()) {
handshakes_[addresses].assign(eapol, eapol + 1);
}
else if(eapol->key_t() && eapol->key_mic() && !eapol->install() && !eapol->key_ack()) {
if(*std::max_element(eapol->nonce(), eapol->nonce() + RSNEAPOL::nonce_size) > 0)
do_insert(addresses, eapol, 1);
else if(do_insert(addresses, eapol, 3)) {
completed_handshakes_.push_back(
handshake_type(
addresses.first,
addresses.second,
handshakes_[addresses]
)
);
handshakes_.erase(addresses);
return true;
}
}
else if(eapol->key_t() && eapol->install() && eapol->key_ack() && eapol->key_mic()) {
do_insert(addresses, eapol, 2);
}
bool RSNHandshakeCapturer::process_packet(const PDU& pdu) {
const RSNEAPOL* eapol = pdu.find_pdu<RSNEAPOL>();
const Dot11Data* dot11 = pdu.find_pdu<Dot11Data>();
if (!eapol || !dot11) {
return false;
}
bool RSNHandshakeCapturer::do_insert(const handshake_map::key_type &key,
const RSNEAPOL *eapol, size_t expected)
{
handshake_map::iterator iter = handshakes_.find(key);
if(iter != handshakes_.end()) {
if(iter->second.size() != expected) {
// skip repeated
if(iter->second.size() != expected + 1)
iter->second.clear();
}
else {
iter->second.push_back(*eapol);
return true;
}
}
pair<address_type, address_type> addresses;
if (dot11->to_ds()) {
addresses.first = dot11->addr1();
addresses.second = dot11->addr2();
}
else if (dot11->from_ds()) {
addresses.first = dot11->addr2();
addresses.second = dot11->addr1();
}
else {
return false;
}
// 1st
if (eapol->key_t() && eapol->key_ack() && !eapol->key_mic() && !eapol->install()) {
handshakes_[addresses].assign(eapol, eapol + 1);
}
else if (eapol->key_t() && eapol->key_mic() && !eapol->install() && !eapol->key_ack()) {
if (*max_element(eapol->nonce(), eapol->nonce() + RSNEAPOL::nonce_size) > 0) {
do_insert(addresses, eapol, 1);
}
else if (do_insert(addresses, eapol, 3)) {
completed_handshakes_.push_back(
handshake_type(
addresses.first,
addresses.second,
handshakes_[addresses]
)
);
handshakes_.erase(addresses);
return true;
}
}
else if (eapol->key_t() && eapol->install() && eapol->key_ack() && eapol->key_mic()) {
do_insert(addresses, eapol, 2);
}
return false;
}
bool RSNHandshakeCapturer::do_insert(const handshake_map::key_type& key,
const RSNEAPOL* eapol,
size_t expected) {
handshake_map::iterator iter = handshakes_.find(key);
if (iter != handshakes_.end()) {
if (iter->second.size() != expected) {
// skip repeated
if (iter->second.size() != expected + 1) {
iter->second.clear();
}
}
else {
iter->second.push_back(*eapol);
return true;
}
}
return false;
}
} // namespace Tins;
#endif // HAVE_DOT11