Skip to content

Fix frame length #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/tins/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ class TINS_API IP : public PDU {

/* Getters */

uint32_t advertised_size() const {
return static_cast<uint32_t>(tot_len());
}

/**
* \brief Getter for the header length field.
*
Expand Down
6 changes: 6 additions & 0 deletions include/tins/pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ class TINS_API PDU {
*/
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.
Expand Down
4 changes: 2 additions & 2 deletions src/packet_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down
8 changes: 8 additions & 0 deletions src/pdu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &) {

}
Expand Down