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

Added Loopback::matches_response.

This commit is contained in:
Matias Fontanini
2014-10-25 00:23:52 -05:00
parent 23a5cfb0c4
commit c4609fedd6
5 changed files with 63 additions and 4 deletions

View File

@@ -432,7 +432,7 @@ bool IP::matches_response(const uint8_t *ptr, uint32_t total_sz) const {
// checks for broadcast addr
if((_ip.saddr == ip_ptr->daddr && (_ip.daddr == ip_ptr->saddr || dst_addr().is_broadcast())) ||
(dst_addr().is_broadcast() && _ip.saddr == 0)) {
uint32_t sz = std::min<uint32_t>(_ip.ihl * sizeof(uint32_t), total_sz);
uint32_t sz = std::min<uint32_t>(header_size(), total_sz);
return inner_pdu() ? inner_pdu()->matches_response(ptr + sz, total_sz - sz) : true;
}
return false;

View File

@@ -93,8 +93,7 @@ uint32_t Loopback::header_size() const {
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, const PDU *) {
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(_family));
#endif
@@ -106,6 +105,19 @@ void Loopback::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU
*reinterpret_cast<uint32_t*>(buffer) = _family;
#endif // WIN32
}
bool Loopback::matches_response(const uint8_t *ptr, uint32_t total_sz) const {
if(total_sz < sizeof(_family)) {
return false;
}
// If there's an inner_pdu, check if the inner pdu matches.
// Otherwise, just check this loopback family.
return inner_pdu() ?
inner_pdu()->matches_response(ptr + sizeof(_family), total_sz - sizeof(_family)) :
(_family == *reinterpret_cast<const uint32_t*>(ptr));
}
#ifdef BSD
void Loopback::send(PacketSender &sender, const NetworkInterface &iface) {
if(!iface)