mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Remove parent parameter from write_serialization
This is no longer needed as each PDU knows its parent PDU already
This commit is contained in:
@@ -334,7 +334,7 @@ private:
|
|||||||
uint32_t target_ip_address;
|
uint32_t target_ip_address;
|
||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
arp_header header_;
|
arp_header header_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -332,7 +332,7 @@ protected:
|
|||||||
*/
|
*/
|
||||||
vend_type& vend() { return vend_; }
|
vend_type& vend() { return vend_; }
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Struct that represents the Bootp datagram.
|
* Struct that represents the Bootp datagram.
|
||||||
|
|||||||
@@ -509,7 +509,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
static const uint32_t MAX_DHCP_SIZE;
|
static const uint32_t MAX_DHCP_SIZE;
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T search_and_convert(OptionTypes opt) const {
|
T search_and_convert(OptionTypes opt) const {
|
||||||
|
|||||||
@@ -890,7 +890,7 @@ public:
|
|||||||
return new DHCPv6(*this);
|
return new DHCPv6(*this);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
void write_option(const option& option, Memory::OutputMemoryStream& stream) const;
|
void write_option(const option& option, Memory::OutputMemoryStream& stream) const;
|
||||||
options_type::const_iterator search_option_iterator(OptionTypes type) const;
|
options_type::const_iterator search_option_iterator(OptionTypes type) const;
|
||||||
options_type::iterator search_option_iterator(OptionTypes type);
|
options_type::iterator search_option_iterator(OptionTypes type);
|
||||||
|
|||||||
@@ -1030,7 +1030,7 @@ private:
|
|||||||
uint8_t* update_dname(uint8_t* ptr, uint32_t threshold, uint32_t offset);
|
uint8_t* update_dname(uint8_t* ptr, uint32_t threshold, uint32_t offset);
|
||||||
static void inline_convert_v4(uint32_t value, char* output);
|
static void inline_convert_v4(uint32_t value, char* output);
|
||||||
static bool contains_dname(uint16_t type);
|
static bool contains_dname(uint16_t type);
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
void add_record(const resource& resource, const sections_type& sections);
|
void add_record(const resource& resource, const sections_type& sections);
|
||||||
|
|
||||||
dns_header header_;
|
dns_header header_;
|
||||||
|
|||||||
@@ -554,7 +554,7 @@ private:
|
|||||||
Dot11(const dot11_header* header_ptr);
|
Dot11(const dot11_header* header_ptr);
|
||||||
|
|
||||||
void internal_add_option(const option& opt);
|
void internal_add_option(const option& opt);
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
options_type::const_iterator search_option_iterator(OptionTypes type) const;
|
options_type::const_iterator search_option_iterator(OptionTypes type) const;
|
||||||
options_type::iterator search_option_iterator(OptionTypes type);
|
options_type::iterator search_option_iterator(OptionTypes type);
|
||||||
|
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool matches_response(const uint8_t* ptr, uint32_t total_sz) const;
|
bool matches_response(const uint8_t* ptr, uint32_t total_sz) const;
|
||||||
private:
|
private:
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
TINS_BEGIN_PACK
|
TINS_BEGIN_PACK
|
||||||
struct dot1q_header {
|
struct dot1q_header {
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ private:
|
|||||||
uint16_t length;
|
uint16_t length;
|
||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
dot3_header header_;
|
dot3_header header_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -185,13 +185,7 @@ protected:
|
|||||||
*/
|
*/
|
||||||
virtual void write_body(Memory::OutputMemoryStream& stream) = 0;
|
virtual void write_body(Memory::OutputMemoryStream& stream) = 0;
|
||||||
private:
|
private:
|
||||||
/**
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
* \brief Serialices this EAPOL PDU.
|
|
||||||
* \param buffer The buffer in which the PDU will be serialized.
|
|
||||||
* \param total_sz The size available in the buffer.
|
|
||||||
* \param parent The PDU that's one level below this one on the stack.
|
|
||||||
*/
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
|
||||||
|
|
||||||
eapol_header header_;
|
eapol_header header_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ private:
|
|||||||
uint16_t payload_type;
|
uint16_t payload_type;
|
||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
ethernet_header header_;
|
ethernet_header header_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -493,15 +493,8 @@ private:
|
|||||||
} un;
|
} un;
|
||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void checksum(uint16_t new_check);
|
void checksum(uint16_t new_check);
|
||||||
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
/** \brief Serialices this ICMP PDU.
|
|
||||||
* \param buffer The buffer in which the PDU will be serialized.
|
|
||||||
* \param total_sz The size available in the buffer.
|
|
||||||
* \param parent The PDU that's one level below this one on the stack.
|
|
||||||
*/
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
|
||||||
|
|
||||||
uint32_t get_adjusted_inner_pdu_size() const;
|
uint32_t get_adjusted_inner_pdu_size() const;
|
||||||
void try_parse_extensions(Memory::InputMemoryStream& stream);
|
void try_parse_extensions(Memory::InputMemoryStream& stream);
|
||||||
bool are_extensions_allowed() const;
|
bool are_extensions_allowed() const;
|
||||||
|
|||||||
@@ -1559,7 +1559,7 @@ private:
|
|||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void internal_add_option(const option& option);
|
void internal_add_option(const option& option);
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
bool has_options() const;
|
bool has_options() const;
|
||||||
void write_option(const option& opt, Memory::OutputMemoryStream& stream);
|
void write_option(const option& opt, Memory::OutputMemoryStream& stream);
|
||||||
void parse_options(Memory::InputMemoryStream& stream);
|
void parse_options(Memory::InputMemoryStream& stream);
|
||||||
|
|||||||
@@ -756,10 +756,10 @@ private:
|
|||||||
void head_len(small_uint<4> new_head_len);
|
void head_len(small_uint<4> new_head_len);
|
||||||
void tot_len(uint16_t new_tot_len);
|
void tot_len(uint16_t new_tot_len);
|
||||||
|
|
||||||
void prepare_for_serialize(const PDU* parent);
|
void prepare_for_serialize();
|
||||||
void internal_add_option(const option& option);
|
void internal_add_option(const option& option);
|
||||||
void init_ip_fields();
|
void init_ip_fields();
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
void write_option(const option& opt, Memory::OutputMemoryStream& stream);
|
void write_option(const option& opt, Memory::OutputMemoryStream& stream);
|
||||||
void add_route_option(option_identifier id, const generic_route_option_type& data);
|
void add_route_option(option_identifier id, const generic_route_option_type& data);
|
||||||
generic_route_option_type search_route_option(option_identifier id) const;
|
generic_route_option_type search_route_option(option_identifier id) const;
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ private:
|
|||||||
uint32_t spi, seq_number;
|
uint32_t spi, seq_number;
|
||||||
};
|
};
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
ipsec_header header_;
|
ipsec_header header_;
|
||||||
byte_array icv_;
|
byte_array icv_;
|
||||||
@@ -258,7 +258,7 @@ private:
|
|||||||
uint32_t spi, seq_number;
|
uint32_t spi, seq_number;
|
||||||
};
|
};
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
ipsec_header header_;
|
ipsec_header header_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -320,7 +320,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
const ext_header* search_header(ExtensionHeader id) const;
|
const ext_header* search_header(ExtensionHeader id) const;
|
||||||
private:
|
private:
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
void set_last_next_header(uint8_t value);
|
void set_last_next_header(uint8_t value);
|
||||||
static void write_header(const ext_header& header, Memory::OutputMemoryStream& stream);
|
static void write_header(const ext_header& header, Memory::OutputMemoryStream& stream);
|
||||||
static bool is_extension_header(uint8_t header_id);
|
static bool is_extension_header(uint8_t header_id);
|
||||||
|
|||||||
@@ -401,7 +401,7 @@ private:
|
|||||||
typedef std::vector<uint8_t> field_type;
|
typedef std::vector<uint8_t> field_type;
|
||||||
typedef std::list<field_type> field_list;
|
typedef std::list<field_type> field_list;
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
llchdr header_;
|
llchdr header_;
|
||||||
uint8_t control_field_length_;
|
uint8_t control_field_length_;
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ public:
|
|||||||
void send(PacketSender& sender, const NetworkInterface& iface);
|
void send(PacketSender& sender, const NetworkInterface& iface);
|
||||||
#endif // BSD
|
#endif // BSD
|
||||||
private:
|
private:
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
uint32_t family_;
|
uint32_t family_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ private:
|
|||||||
uint8_t ttl;
|
uint8_t ttl;
|
||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
mpls_header header_;
|
mpls_header header_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -494,19 +494,16 @@ protected:
|
|||||||
* is calculated.
|
* is calculated.
|
||||||
*
|
*
|
||||||
* By default, this method does nothing
|
* By default, this method does nothing
|
||||||
*
|
|
||||||
* \param parent The parent PDU.
|
|
||||||
*/
|
*/
|
||||||
virtual void prepare_for_serialize(const PDU* parent);
|
virtual void prepare_for_serialize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Serializes this PDU and propagates this action to child PDUs.
|
* \brief Serializes this PDU and propagates this action to child PDUs.
|
||||||
*
|
*
|
||||||
* \param buffer The buffer in which to store this PDU's serialization.
|
* \param buffer The buffer in which to store this PDU's serialization.
|
||||||
* \param total_sz The total size of the buffer.
|
* \param total_sz The total size of the buffer.
|
||||||
* \param parent The parent PDU. Will be 0 if there's the parent does not exist.
|
|
||||||
*/
|
*/
|
||||||
void serialize(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void serialize(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Serializes this TCP PDU.
|
* \brief Serializes this TCP PDU.
|
||||||
@@ -515,9 +512,8 @@ protected:
|
|||||||
* serialization.
|
* serialization.
|
||||||
* \param buffer The buffer in which the PDU will be serialized.
|
* \param buffer The buffer in which the PDU will be serialized.
|
||||||
* \param total_sz The size available in the buffer.
|
* \param total_sz The size available in the buffer.
|
||||||
* \param parent The PDU that's one level below this one on the stack. Might be 0.
|
|
||||||
*/
|
*/
|
||||||
virtual void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) = 0;
|
virtual void write_serialization(uint8_t* buffer, uint32_t total_sz) = 0;
|
||||||
private:
|
private:
|
||||||
void parent_pdu(PDU* parent);
|
void parent_pdu(PDU* parent);
|
||||||
|
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ public:
|
|||||||
return cached_.pdu_type();
|
return cached_.pdu_type();
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
if (cached_serialization_.size() != total_sz) {
|
if (cached_serialization_.size() != total_sz) {
|
||||||
cached_serialization_ = cached_.serialize();
|
cached_serialization_ = cached_.serialize();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ private:
|
|||||||
uint8_t ecommand[20];
|
uint8_t ecommand[20];
|
||||||
};
|
};
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
pktap_header header_;
|
pktap_header header_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ public:
|
|||||||
return new PPI(*this);
|
return new PPI(*this);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
void parse_80211(const uint8_t* buffer, uint32_t total_sz);
|
void parse_80211(const uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
struct ppi_header {
|
struct ppi_header {
|
||||||
|
|||||||
@@ -390,7 +390,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
std::string generic_error() const;
|
std::string generic_error() const;
|
||||||
private:
|
private:
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void add_tag_iterable(TagTypes id, const T& data) {
|
void add_tag_iterable(TagTypes id, const T& data) {
|
||||||
|
|||||||
@@ -486,7 +486,7 @@ private:
|
|||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
uint32_t find_extra_flag_fields_size(const uint8_t* buffer, uint32_t total_sz);
|
uint32_t find_extra_flag_fields_size(const uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
template <size_t n>
|
template <size_t n>
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ public:
|
|||||||
return new RawPDU(*this);
|
return new RawPDU(*this);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
payload_type payload_;
|
payload_type payload_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ private:
|
|||||||
uint16_t protocol;
|
uint16_t protocol;
|
||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
sll_header header_;
|
sll_header header_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ private:
|
|||||||
uint16_t eth_type;
|
uint16_t eth_type;
|
||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
snap_header snap_;
|
snap_header snap_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ private:
|
|||||||
static bpdu_id_type convert(const pvt_bpdu_id& id);
|
static bpdu_id_type convert(const pvt_bpdu_id& id);
|
||||||
static pvt_bpdu_id convert(const bpdu_id_type& id);
|
static pvt_bpdu_id convert(const bpdu_id_type& id);
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
stp_header header_;
|
stp_header header_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -610,7 +610,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void internal_add_option(const option& option);
|
void internal_add_option(const option& option);
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
void checksum(uint16_t new_check);
|
void checksum(uint16_t new_check);
|
||||||
void update_options_size();
|
void update_options_size();
|
||||||
options_type::const_iterator search_option_iterator(OptionTypes type) const;
|
options_type::const_iterator search_option_iterator(OptionTypes type) const;
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ private:
|
|||||||
uint16_t check;
|
uint16_t check;
|
||||||
} TINS_END_PACK;
|
} TINS_END_PACK;
|
||||||
|
|
||||||
void write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent);
|
void write_serialization(uint8_t* buffer, uint32_t total_sz);
|
||||||
|
|
||||||
udp_header header_;
|
udp_header header_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ uint32_t ARP::header_size() const {
|
|||||||
return sizeof(header_);
|
return sizeof(header_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) {
|
void ARP::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
stream.write(header_);
|
stream.write(header_);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ void BootP::vend(const vend_type& newvend_) {
|
|||||||
vend_ = newvend_;
|
vend_ = newvend_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BootP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
void BootP::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
stream.write(bootp_);
|
stream.write(bootp_);
|
||||||
stream.write(vend_.begin(), vend_.end());
|
stream.write(vend_.begin(), vend_.end());
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ uint32_t DHCP::header_size() const {
|
|||||||
return static_cast<uint32_t>(BootP::header_size() - vend().size() + size_);
|
return static_cast<uint32_t>(BootP::header_size() - vend().size() + size_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHCP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void DHCP::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
if (size_) {
|
if (size_) {
|
||||||
vend_type& result = BootP::vend();
|
vend_type& result = BootP::vend();
|
||||||
result.resize(size_);
|
result.resize(size_);
|
||||||
@@ -261,7 +261,7 @@ void DHCP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* pa
|
|||||||
stream.write(it->data_ptr(), it->data_size());
|
stream.write(it->data_ptr(), it->data_size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BootP::write_serialization(buffer, total_sz, parent);
|
BootP::write_serialization(buffer, total_sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Tins
|
} // Tins
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ bool DHCPv6::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHCPv6::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) {
|
void DHCPv6::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
const uint32_t required_size = is_relay_message() ? 2 : 4;
|
const uint32_t required_size = is_relay_message() ? 2 : 4;
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
stream.write(header_data_, required_size);
|
stream.write(header_data_, required_size);
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ uint32_t DNS::compose_name(const uint8_t* ptr, char* out_ptr) const {
|
|||||||
return end_ptr - start_ptr;
|
return end_ptr - start_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DNS::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
void DNS::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
stream.write(header_);
|
stream.write(header_);
|
||||||
stream.write(records_data_.begin(), records_data_.end());
|
stream.write(records_data_.begin(), records_data_.end());
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ void Dot11::send(PacketSender& sender, const NetworkInterface& iface) {
|
|||||||
}
|
}
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
void Dot11::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
void Dot11::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
stream.write(header_);
|
stream.write(header_);
|
||||||
write_ext_header(stream);
|
write_ext_header(stream);
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ uint32_t Dot1Q::trailer_size() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dot1Q::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) {
|
void Dot1Q::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
if (inner_pdu()) {
|
if (inner_pdu()) {
|
||||||
Constants::Ethernet::e flag;
|
Constants::Ethernet::e flag;
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ bool Dot3::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dot3::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
void Dot3::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
header_.length = Endian::host_to_be<uint16_t>(size() - sizeof(header_));
|
header_.length = Endian::host_to_be<uint16_t>(size() - sizeof(header_));
|
||||||
stream.write(header_);
|
stream.write(header_);
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ void EAPOL::type(uint8_t new_type) {
|
|||||||
header_.type = new_type;
|
header_.type = new_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EAPOL::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) {
|
void EAPOL::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
length(total_sz - 4);
|
length(total_sz - 4);
|
||||||
stream.write(header_);
|
stream.write(header_);
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ bool EthernetII::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EthernetII::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
void EthernetII::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
if (inner_pdu()) {
|
if (inner_pdu()) {
|
||||||
Constants::Ethernet::e flag;
|
Constants::Ethernet::e flag;
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ void ICMP::use_length_field(bool value) {
|
|||||||
header_.un.rfc4884.length = value ? 1 : 0;
|
header_.un.rfc4884.length = value ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ICMP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) {
|
void ICMP::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
|
|
||||||
// If extensions are allowed and we have to set the length field
|
// If extensions are allowed and we have to set the length field
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ bool ICMPv6::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ICMPv6::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void ICMPv6::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
|
|
||||||
// If extensions are allowed and we have to set the length field
|
// If extensions are allowed and we have to set the length field
|
||||||
@@ -361,7 +361,7 @@ void ICMPv6::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU*
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Tins::IPv6* ipv6 = tins_cast<const Tins::IPv6*>(parent);
|
const Tins::IPv6* ipv6 = tins_cast<const Tins::IPv6*>(parent_pdu());
|
||||||
if (ipv6) {
|
if (ipv6) {
|
||||||
uint32_t checksum = Utils::pseudoheader_checksum(
|
uint32_t checksum = Utils::pseudoheader_checksum(
|
||||||
ipv6->src_addr(),
|
ipv6->src_addr(),
|
||||||
|
|||||||
10
src/ip.cpp
10
src/ip.cpp
@@ -418,14 +418,14 @@ PDU* IP::recv_response(PacketSender& sender, const NetworkInterface &) {
|
|||||||
return sender.recv_l3(*this, 0, sizeof(link_addr), type);
|
return sender.recv_l3(*this, 0, sizeof(link_addr), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IP::prepare_for_serialize(const PDU* parent) {
|
void IP::prepare_for_serialize() {
|
||||||
if (!parent && header_.saddr == 0) {
|
if (!parent_pdu()&& header_.saddr == 0) {
|
||||||
NetworkInterface iface(dst_addr());
|
NetworkInterface iface(dst_addr());
|
||||||
src_addr(iface.addresses().ip_addr);
|
src_addr(iface.addresses().ip_addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void IP::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
checksum(0);
|
checksum(0);
|
||||||
if (inner_pdu()) {
|
if (inner_pdu()) {
|
||||||
@@ -446,12 +446,10 @@ void IP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* pare
|
|||||||
uint16_t original_frag_off = header_.frag_off;
|
uint16_t original_frag_off = header_.frag_off;
|
||||||
|
|
||||||
#if __FreeBSD__ || defined(__FreeBSD_kernel__) || __APPLE__
|
#if __FreeBSD__ || defined(__FreeBSD_kernel__) || __APPLE__
|
||||||
if (!parent) {
|
if (!parent_pdu()) {
|
||||||
total_sz = Endian::host_to_be<uint16_t>(total_sz);
|
total_sz = Endian::host_to_be<uint16_t>(total_sz);
|
||||||
header_.frag_off = Endian::be_to_host(header_.frag_off);
|
header_.frag_off = Endian::be_to_host(header_.frag_off);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
Internals::unused(parent);
|
|
||||||
#endif
|
#endif
|
||||||
tot_len(total_sz);
|
tot_len(total_sz);
|
||||||
head_len(static_cast<uint8_t>(header_size() / sizeof(uint32_t)));
|
head_len(static_cast<uint8_t>(header_size() / sizeof(uint32_t)));
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ uint32_t IPSecAH::header_size() const {
|
|||||||
return static_cast<uint32_t>(sizeof(header_) + icv_.size());
|
return static_cast<uint32_t>(sizeof(header_) + icv_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void IPSecAH::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) {
|
void IPSecAH::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
if (inner_pdu()) {
|
if (inner_pdu()) {
|
||||||
next_header(Internals::pdu_flag_to_ip_type(inner_pdu()->pdu_type()));
|
next_header(Internals::pdu_flag_to_ip_type(inner_pdu()->pdu_type()));
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ uint32_t IPSecESP::header_size() const {
|
|||||||
return sizeof(header_);
|
return sizeof(header_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IPSecESP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) {
|
void IPSecESP::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream output(buffer, total_sz);
|
OutputMemoryStream output(buffer, total_sz);
|
||||||
output.write(header_);
|
output.write(header_);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ bool IPv6::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IPv6::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
void IPv6::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
if (inner_pdu()) {
|
if (inner_pdu()) {
|
||||||
uint8_t new_flag = Internals::pdu_flag_to_ip_type(inner_pdu()->pdu_type());
|
uint8_t new_flag = Internals::pdu_flag_to_ip_type(inner_pdu()->pdu_type());
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ void LLC::clear_information_fields() {
|
|||||||
information_fields_.clear();
|
information_fields_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLC::write_serialization(uint8_t* buffer, uint32_t total_sz, const Tins::PDU* /*parent*/) {
|
void LLC::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
if (inner_pdu() && inner_pdu()->pdu_type() == PDU::STP) {
|
if (inner_pdu() && inner_pdu()->pdu_type() == PDU::STP) {
|
||||||
dsap(0x42);
|
dsap(0x42);
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ uint32_t Loopback::header_size() const {
|
|||||||
return sizeof(family_);
|
return sizeof(family_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Loopback::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) {
|
void Loopback::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
if (tins_cast<const Tins::IP*>(inner_pdu())) {
|
if (tins_cast<const Tins::IP*>(inner_pdu())) {
|
||||||
|
|||||||
@@ -91,10 +91,10 @@ uint32_t MPLS::header_size() const {
|
|||||||
return sizeof(header_);
|
return sizeof(header_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPLS::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void MPLS::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
// If we have a parent PDU, we might set the bottom-of-stack field
|
// If we have a parent PDU, we might set the bottom-of-stack field
|
||||||
if (parent) {
|
if (parent_pdu()) {
|
||||||
// We'll set it if we either don't have a child or we have one and it's not MPLS
|
// We'll set it if we either don't have a child or we have one and it's not MPLS
|
||||||
if (!inner_pdu() || inner_pdu()->pdu_type() != PDU::MPLS) {
|
if (!inner_pdu() || inner_pdu()->pdu_type() != PDU::MPLS) {
|
||||||
bottom_of_stack(1);
|
bottom_of_stack(1);
|
||||||
|
|||||||
12
src/pdu.cpp
12
src/pdu.cpp
@@ -73,7 +73,7 @@ void PDU::copy_inner_pdu(const PDU& pdu) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDU::prepare_for_serialize(const PDU* /*parent*/) {
|
void PDU::prepare_for_serialize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t PDU::size() const {
|
uint32_t PDU::size() const {
|
||||||
@@ -121,21 +121,21 @@ PDU* PDU::release_inner_pdu() {
|
|||||||
|
|
||||||
PDU::serialization_type PDU::serialize() {
|
PDU::serialization_type PDU::serialize() {
|
||||||
vector<uint8_t> buffer(size());
|
vector<uint8_t> buffer(size());
|
||||||
serialize(&buffer[0], static_cast<uint32_t>(buffer.size()), 0);
|
serialize(&buffer[0], static_cast<uint32_t>(buffer.size()));
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDU::serialize(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void PDU::serialize(uint8_t* buffer, uint32_t total_sz) {
|
||||||
uint32_t sz = header_size() + trailer_size();
|
uint32_t sz = header_size() + trailer_size();
|
||||||
// Must not happen...
|
// Must not happen...
|
||||||
#ifdef TINS_DEBUG
|
#ifdef TINS_DEBUG
|
||||||
assert(total_sz >= sz);
|
assert(total_sz >= sz);
|
||||||
#endif
|
#endif
|
||||||
prepare_for_serialize(parent);
|
prepare_for_serialize();
|
||||||
if (inner_pdu_) {
|
if (inner_pdu_) {
|
||||||
inner_pdu_->serialize(buffer + header_size(), total_sz - sz, this);
|
inner_pdu_->serialize(buffer + header_size(), total_sz - sz);
|
||||||
}
|
}
|
||||||
write_serialization(buffer, total_sz, parent);
|
write_serialization(buffer, total_sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDU::parent_pdu(PDU* parent) {
|
void PDU::parent_pdu(PDU* parent) {
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ uint32_t PKTAP::header_size() const {
|
|||||||
return sizeof(header_);
|
return sizeof(header_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PKTAP::write_serialization(uint8_t* /*buffer*/, uint32_t /*total_sz*/, const PDU* /*parent*/) {
|
void PKTAP::write_serialization(uint8_t* /*buffer*/, uint32_t /*total_sz*/) {
|
||||||
throw pdu_not_serializable();
|
throw pdu_not_serializable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ uint32_t PPI::header_size() const {
|
|||||||
return static_cast<uint32_t>(sizeof(header_) + data_.size());
|
return static_cast<uint32_t>(sizeof(header_) + data_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PPI::write_serialization(uint8_t* /*buffer*/, uint32_t /*total_sz*/, const PDU *) {
|
void PPI::write_serialization(uint8_t* /*buffer*/, uint32_t /*total_sz*/) {
|
||||||
throw pdu_not_serializable();
|
throw pdu_not_serializable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ uint32_t PPPoE::header_size() const {
|
|||||||
return sizeof(header_) + tags_size_;
|
return sizeof(header_) + tags_size_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PPPoE::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) {
|
void PPPoE::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
if (tags_size_ > 0) {
|
if (tags_size_ > 0) {
|
||||||
payload_length(tags_size_);
|
payload_length(tags_size_);
|
||||||
|
|||||||
@@ -507,7 +507,7 @@ bool RadioTap::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioTap::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
void RadioTap::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
uint8_t* buffer_start = buffer;
|
uint8_t* buffer_start = buffer;
|
||||||
radio_.it_len = Endian::host_to_le<uint16_t>(header_size());
|
radio_.it_len = Endian::host_to_le<uint16_t>(header_size());
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ uint32_t RawPDU::header_size() const {
|
|||||||
return static_cast<uint32_t>(payload_.size());
|
return static_cast<uint32_t>(payload_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawPDU::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) {
|
void RawPDU::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
stream.write(payload_.begin(), payload_.end());
|
stream.write(payload_.begin(), payload_.end());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ uint32_t SLL::header_size() const {
|
|||||||
return sizeof(header_);
|
return sizeof(header_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SLL::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) {
|
void SLL::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
if (inner_pdu()) {
|
if (inner_pdu()) {
|
||||||
Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type(
|
Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type(
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ uint32_t SNAP::header_size() const {
|
|||||||
return sizeof(snap_);
|
return sizeof(snap_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SNAP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* /*parent*/) {
|
void SNAP::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
if (inner_pdu()) {
|
if (inner_pdu()) {
|
||||||
Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type(
|
Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type(
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ void STP::bridge_id(const bpdu_id_type& id) {
|
|||||||
header_.bridge_id = convert(id);
|
header_.bridge_id = convert(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void STP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) {
|
void STP::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
stream.write(header_);
|
stream.write(header_);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ uint32_t TCP::header_size() const {
|
|||||||
return sizeof(header_) + total_options_size_;
|
return sizeof(header_) + total_options_size_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void TCP::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
// Set checksum to 0, we'll calculate it at the end
|
// Set checksum to 0, we'll calculate it at the end
|
||||||
checksum(0);
|
checksum(0);
|
||||||
@@ -311,6 +311,7 @@ void TCP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* par
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t check = 0;
|
uint32_t check = 0;
|
||||||
|
const PDU* parent = parent_pdu();
|
||||||
if (const Tins::IP* ip_packet = tins_cast<const Tins::IP*>(parent)) {
|
if (const Tins::IP* ip_packet = tins_cast<const Tins::IP*>(parent)) {
|
||||||
check = Utils::pseudoheader_checksum(
|
check = Utils::pseudoheader_checksum(
|
||||||
ip_packet->src_addr(),
|
ip_packet->src_addr(),
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ uint32_t pseudoheader_checksum(IPv4Address source_ip, IPv4Address dest_ip, uint3
|
|||||||
return checksum;
|
return checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
void UDP::write_serialization(uint8_t* buffer, uint32_t total_sz) {
|
||||||
OutputMemoryStream stream(buffer, total_sz);
|
OutputMemoryStream stream(buffer, total_sz);
|
||||||
// Set checksum to 0, we'll calculate it at the end
|
// Set checksum to 0, we'll calculate it at the end
|
||||||
header_.check = 0;
|
header_.check = 0;
|
||||||
@@ -129,6 +129,7 @@ void UDP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* par
|
|||||||
}
|
}
|
||||||
stream.write(header_);
|
stream.write(header_);
|
||||||
uint32_t checksum = 0;
|
uint32_t checksum = 0;
|
||||||
|
const PDU* parent = parent_pdu();
|
||||||
if (const Tins::IP* ip_packet = tins_cast<const Tins::IP*>(parent)) {
|
if (const Tins::IP* ip_packet = tins_cast<const Tins::IP*>(parent)) {
|
||||||
checksum = Utils::pseudoheader_checksum(
|
checksum = Utils::pseudoheader_checksum(
|
||||||
ip_packet->src_addr(),
|
ip_packet->src_addr(),
|
||||||
|
|||||||
@@ -52,8 +52,7 @@ public:
|
|||||||
DummyPDU* clone() const { return new DummyPDU<n>(*this); }
|
DummyPDU* clone() const { return new DummyPDU<n>(*this); }
|
||||||
uint32_t header_size() const { return (uint32_t)buffer.size(); }
|
uint32_t header_size() const { return (uint32_t)buffer.size(); }
|
||||||
PDUType pdu_type() const { return pdu_flag; }
|
PDUType pdu_type() const { return pdu_flag; }
|
||||||
void write_serialization(uint8_t* data, uint32_t, const PDU *)
|
void write_serialization(uint8_t* data, uint32_t) {
|
||||||
{
|
|
||||||
std::copy(buffer.begin(), buffer.end(), data);
|
std::copy(buffer.begin(), buffer.end(), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user