1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Merge pull request #324 from pepper-jk/fix_frame_length

Fix frame length
This commit is contained in:
Matias Fontanini
2019-01-27 09:20:58 -08:00
committed by GitHub
4 changed files with 20 additions and 2 deletions

View File

@@ -281,6 +281,10 @@ public:
/* Getters */
uint32_t advertised_size() const {
return static_cast<uint32_t>(tot_len());
}
/**
* \brief Getter for the header length field.
*

View File

@@ -281,6 +281,12 @@ public:
*/
uint32_t size() const;
/** \brief The whole chain of PDU's advertised size, including this one.
*
* Returns the sum of this and all children PDU's advertised size.
*/
virtual uint32_t advertised_size() const;
/**
* \brief Getter for the inner PDU.
* \return The current inner PDU. Might be a null pointer.

View File

@@ -70,12 +70,12 @@ void PacketWriter::write(Packet& packet) {
}
void PacketWriter::write(PDU& pdu, const struct timeval& tv) {
PDU::serialization_type buffer = pdu.serialize();
struct pcap_pkthdr header;
memset(&header, 0, sizeof(header));
header.ts = tv;
header.len = static_cast<bpf_u_int32>(pdu.advertised_size());
PDU::serialization_type buffer = pdu.serialize();
header.caplen = static_cast<bpf_u_int32>(buffer.size());
header.len = static_cast<bpf_u_int32>(buffer.size());
pcap_dump((u_char*)dumper_, &header, &buffer[0]);
}

View File

@@ -85,6 +85,14 @@ uint32_t PDU::size() const {
return sz;
}
uint32_t PDU::advertised_size() const {
uint32_t result = header_size() + trailer_size();
if (inner_pdu_) {
result += inner_pdu()->advertised_size();
}
return result;
}
void PDU::send(PacketSender &, const NetworkInterface &) {
}