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

Added several tests for EAPOL. Now both RadioTap and EAPOL work on big endian architectures.

This commit is contained in:
Matias Fontanini
2012-10-18 23:22:42 -03:00
parent d4bcefb1d6
commit b7ea989530
13 changed files with 538 additions and 78 deletions

View File

@@ -31,22 +31,41 @@
#include "rsn_information.h"
namespace Tins {
template<typename T>
void check_size(uint32_t total_sz, const char* err_msg) {
if(total_sz < sizeof(T))
throw std::runtime_error(err_msg);
}
RSNInformation::RSNInformation() : _version(1), _capabilities(0) {
}
RSNInformation::RSNInformation(const serialization_type &buffer) {
init(&buffer[0], buffer.size());
}
RSNInformation::RSNInformation(const uint8_t *buffer, uint32_t total_sz) {
init(buffer, total_sz);
}
void RSNInformation::init(const uint8_t *buffer, uint32_t total_sz) {
const char *err_msg = "Malformed RSN information structure";
check_size<uint16_t>(total_sz, err_msg);
version(Endian::le_to_host(*(uint16_t*)buffer));
buffer += sizeof(uint16_t);
total_sz -= sizeof(uint16_t);
group_suite((RSNInformation::CypherSuites)*(uint32_t*)buffer);
check_size<uint32_t>(total_sz, err_msg);
buffer += sizeof(uint32_t);
total_sz -= sizeof(uint32_t);
check_size<uint16_t>(total_sz, err_msg);
total_sz -= (sizeof(uint16_t) << 1) + sizeof(uint32_t);
if(total_sz < sizeof(uint16_t))
throw std::runtime_error(err_msg);
uint16_t count = *(uint16_t*)buffer;
buffer += sizeof(uint16_t);
total_sz -= sizeof(uint16_t);
if(count * sizeof(uint32_t) > total_sz)
throw std::runtime_error(err_msg);
total_sz -= count * sizeof(uint32_t);
@@ -54,8 +73,8 @@ RSNInformation::RSNInformation(const uint8_t *buffer, uint32_t total_sz) {
add_pairwise_cypher((RSNInformation::CypherSuites)*(uint32_t*)buffer);
buffer += sizeof(uint32_t);
}
if(total_sz < sizeof(uint16_t))
throw std::runtime_error(err_msg);
check_size<uint16_t>(total_sz, err_msg);
count = *(uint16_t*)buffer;
buffer += sizeof(uint16_t);
total_sz -= sizeof(uint16_t);
@@ -66,8 +85,8 @@ RSNInformation::RSNInformation(const uint8_t *buffer, uint32_t total_sz) {
add_akm_cypher((RSNInformation::AKMSuites)*(uint32_t*)buffer);
buffer += sizeof(uint32_t);
}
if(total_sz < sizeof(uint16_t))
throw std::runtime_error(err_msg);
check_size<uint16_t>(total_sz, err_msg);
capabilities(Endian::le_to_host(*(uint16_t*)buffer));
}