1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-25 19:51:34 +01:00

Modified IP, ARP, ICMP and EthernetII's clone_packet.

This commit is contained in:
Matias Fontanini
2011-09-15 09:17:35 -03:00
parent 6b88a9a944
commit 4d8fb5a4e5
8 changed files with 23 additions and 66 deletions

View File

@@ -57,10 +57,6 @@ Tins::ICMP::ICMP(const uint8_t *buffer, uint32_t total_sz) : PDU(IPPROTO_ICMP) {
inner_pdu(new RawPDU(buffer + sizeof(icmphdr), total_sz));
}
Tins::ICMP::ICMP(const icmphdr *ptr) : PDU(IPPROTO_ICMP) {
std::memcpy(&_icmp, ptr, sizeof(icmphdr));
}
void Tins::ICMP::code(uint8_t new_code) {
_icmp.code = new_code;
}
@@ -190,13 +186,12 @@ bool Tins::ICMP::matches_response(uint8_t *ptr, uint32_t total_sz) {
Tins::PDU *Tins::ICMP::clone_packet(const uint8_t *ptr, uint32_t total_sz) {
if(total_sz < sizeof(icmphdr))
return 0;
const icmphdr *icmp_ptr = (icmphdr*)ptr;
PDU *child = 0, *cloned;
if(total_sz > sizeof(icmphdr)) {
if((child = PDU::clone_inner_pdu(ptr + sizeof(icmphdr), total_sz - sizeof(icmphdr))) == 0)
return 0;
}
cloned = new ICMP(icmp_ptr);
cloned = new ICMP(ptr, std::min(total_sz, (uint32_t)sizeof(_icmp)));
cloned->inner_pdu(child);
return cloned;
}