mirror of
https://github.com/mfontanini/libtins
synced 2026-01-30 05:24:26 +01:00
Merge branch 'master' of ssh://git.code.sf.net/p/libtins/code
This commit is contained in:
@@ -63,6 +63,7 @@ ARP::ARP(const uint8_t *buffer, uint32_t total_sz)
|
||||
throw malformed_packet();
|
||||
memcpy(&_arp, buffer, sizeof(arphdr));
|
||||
total_sz -= sizeof(arphdr);
|
||||
//TODO: Check whether this should be removed or not.
|
||||
if(total_sz)
|
||||
inner_pdu(new RawPDU(buffer + sizeof(arphdr), total_sz));
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ EAPOL *EAPOL::from_bytes(const uint8_t *buffer, uint32_t total_sz) {
|
||||
if(total_sz < sizeof(eapolhdr))
|
||||
throw malformed_packet();
|
||||
const eapolhdr *ptr = (const eapolhdr*)buffer;
|
||||
total_sz = std::min(total_sz, (uint32_t)ptr->length);
|
||||
switch(ptr->type) {
|
||||
case RC4:
|
||||
return new Tins::RC4EAPOL(buffer, total_sz);
|
||||
|
||||
@@ -82,6 +82,7 @@ EthernetII::EthernetII(const uint8_t *buffer, uint32_t total_sz)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void EthernetII::dst_addr(const address_type &new_dst_addr) {
|
||||
@@ -97,9 +98,19 @@ void EthernetII::payload_type(uint16_t new_payload_type) {
|
||||
}
|
||||
|
||||
uint32_t EthernetII::header_size() const {
|
||||
|
||||
return sizeof(ethhdr);
|
||||
}
|
||||
|
||||
uint32_t EthernetII::trailer_size() const {
|
||||
int32_t padding = 60 - sizeof(ethhdr); // EthernetII min size is 60, padding is sometimes needed
|
||||
if (inner_pdu()) {
|
||||
padding -= inner_pdu()->size();
|
||||
padding = std::max(0, padding);
|
||||
}
|
||||
return padding;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
void EthernetII::send(PacketSender &sender, const NetworkInterface &iface) {
|
||||
if(!iface)
|
||||
@@ -140,7 +151,7 @@ bool EthernetII::matches_response(const uint8_t *ptr, uint32_t total_sz) const {
|
||||
|
||||
void EthernetII::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
|
||||
#ifdef TINS_DEBUG
|
||||
assert(total_sz >= header_size());
|
||||
assert(total_sz >= header_size() + trailer_size());
|
||||
#endif
|
||||
|
||||
/* Inner type defaults to IP */
|
||||
@@ -151,6 +162,14 @@ void EthernetII::write_serialization(uint8_t *buffer, uint32_t total_sz, const P
|
||||
payload_type(static_cast<uint16_t>(flag));
|
||||
}
|
||||
memcpy(buffer, &_eth, sizeof(ethhdr));
|
||||
uint32_t trailer = trailer_size();
|
||||
if (trailer) {
|
||||
uint32_t trailer_offset = header_size();
|
||||
if (inner_pdu())
|
||||
trailer_offset += inner_pdu()->size();
|
||||
memset(buffer + trailer_offset, 0, trailer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
|
||||
@@ -115,6 +115,9 @@ IP::IP(const uint8_t *buffer, uint32_t total_sz)
|
||||
uint8_t padding = _options_size % 4;
|
||||
_padded_options_size = padding ? (_options_size - padding + 4) : _options_size;
|
||||
// check this line PLX
|
||||
total_sz = std::min(total_sz, (uint32_t)tot_len());
|
||||
if (total_sz < head_len() * sizeof(uint32_t))
|
||||
throw malformed_packet();
|
||||
total_sz -= head_len() * sizeof(uint32_t);
|
||||
if (total_sz) {
|
||||
switch(_ip.protocol) {
|
||||
|
||||
@@ -51,6 +51,7 @@ PPPoE::PPPoE(const uint8_t *buffer, uint32_t total_sz)
|
||||
std::memcpy(&_header, buffer, sizeof(_header));
|
||||
buffer += sizeof(_header);
|
||||
total_sz -= sizeof(_header);
|
||||
total_sz = std::min(total_sz, (uint32_t)payload_length());
|
||||
const uint8_t *end = buffer + total_sz;
|
||||
while(buffer < end) {
|
||||
if(buffer + sizeof(uint32_t) * 2 > end)
|
||||
|
||||
Reference in New Issue
Block a user