mirror of
https://github.com/mfontanini/libtins
synced 2026-01-26 20:01:35 +01:00
Add extract_metadata to main PDU classes
This commit is contained in:
@@ -46,6 +46,15 @@ using Tins::Memory::OutputMemoryStream;
|
||||
|
||||
namespace Tins {
|
||||
|
||||
PDU::metadata EAPOL::extract_metadata(const uint8_t *buffer, uint32_t total_sz) {
|
||||
if (TINS_UNLIKELY(total_sz < sizeof(eapol_header))) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
const eapol_header* header = (const eapol_header*)buffer;
|
||||
uint32_t advertised_size = Endian::be_to_host<uint16_t>(header->length) + 4;
|
||||
return metadata(min(total_sz, advertised_size), pdu_flag, PDU::UNKNOWN);
|
||||
}
|
||||
|
||||
EAPOL::EAPOL(uint8_t packet_type, EAPOLTYPE type)
|
||||
: header_() {
|
||||
header_.version = 1;
|
||||
@@ -59,7 +68,7 @@ EAPOL::EAPOL(const uint8_t* buffer, uint32_t total_sz) {
|
||||
}
|
||||
|
||||
EAPOL* EAPOL::from_bytes(const uint8_t* buffer, uint32_t total_sz) {
|
||||
if (total_sz < sizeof(eapol_header)) {
|
||||
if (TINS_UNLIKELY(total_sz < sizeof(eapol_header))) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
const eapol_header* ptr = (const eapol_header*)buffer;
|
||||
|
||||
Reference in New Issue
Block a user