From d1b64ec48ec1de73e1a0ff9d285d033665100d82 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 21 Apr 2013 20:03:47 -0300 Subject: [PATCH] PDU::matches_response is now const. --- include/arp.h | 2 +- include/bootp.h | 2 +- include/dhcpv6.h | 2 +- include/dns.h | 2 +- include/dot1q.h | 2 +- include/dot3.h | 2 +- include/ethernetII.h | 2 +- include/icmp.h | 2 +- include/icmpv6.h | 2 +- include/ip.h | 2 +- include/ipv6.h | 2 +- include/pdu.h | 4 +++- include/pdu_cacher.h | 2 +- include/radiotap.h | 2 +- include/rawpdu.h | 2 +- include/tcp.h | 2 +- include/udp.h | 2 +- src/arp.cpp | 4 ++-- src/bootp.cpp | 2 +- src/dhcpv6.cpp | 2 +- src/dns.cpp | 2 +- src/dot1q.cpp | 2 +- src/dot3.cpp | 2 +- src/ethernetII.cpp | 2 +- src/icmp.cpp | 2 +- src/icmpv6.cpp | 2 +- src/ip.cpp | 2 +- src/ipv6.cpp | 2 +- src/radiotap.cpp | 2 +- src/rawpdu.cpp | 2 +- src/tcp.cpp | 2 +- src/udp.cpp | 2 +- 32 files changed, 35 insertions(+), 33 deletions(-) diff --git a/include/arp.h b/include/arp.h index 47cf44a..b7e90ad 100644 --- a/include/arp.h +++ b/include/arp.h @@ -271,7 +271,7 @@ namespace Tins { * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; /** * \sa PDU::clone diff --git a/include/bootp.h b/include/bootp.h index 55f4a43..08c06c3 100644 --- a/include/bootp.h +++ b/include/bootp.h @@ -305,7 +305,7 @@ namespace Tins { * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; /** * \brief Getter for the PDU's type. diff --git a/include/dhcpv6.h b/include/dhcpv6.h index 363835f..81313ff 100644 --- a/include/dhcpv6.h +++ b/include/dhcpv6.h @@ -813,7 +813,7 @@ public: * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; /** * \brief Getter for the PDU's type. diff --git a/include/dns.h b/include/dns.h index 3e23326..f5996b3 100644 --- a/include/dns.h +++ b/include/dns.h @@ -577,7 +577,7 @@ namespace Tins { * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; /** * \sa PDU::clone diff --git a/include/dot1q.h b/include/dot1q.h index 88b3cf7..38fad43 100644 --- a/include/dot1q.h +++ b/include/dot1q.h @@ -179,7 +179,7 @@ public: * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; private: void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent); diff --git a/include/dot3.h b/include/dot3.h index 6ff808f..04434d7 100644 --- a/include/dot3.h +++ b/include/dot3.h @@ -151,7 +151,7 @@ namespace Tins { * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; #ifndef WIN32 /** diff --git a/include/ethernetII.h b/include/ethernetII.h index fe6a2c2..241c483 100644 --- a/include/ethernetII.h +++ b/include/ethernetII.h @@ -153,7 +153,7 @@ namespace Tins { * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; #ifndef WIN32 /** diff --git a/include/icmp.h b/include/icmp.h index 1cdb06b..22e4a7a 100644 --- a/include/icmp.h +++ b/include/icmp.h @@ -279,7 +279,7 @@ namespace Tins { * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; /** * \brief Getter for the PDU's type. diff --git a/include/icmpv6.h b/include/icmpv6.h index f10067a..4e4e293 100644 --- a/include/icmpv6.h +++ b/include/icmpv6.h @@ -769,7 +769,7 @@ public: * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; /** * \brief Searchs for an option that matchs the given flag. diff --git a/include/ip.h b/include/ip.h index 99e9918..93ee269 100644 --- a/include/ip.h +++ b/include/ip.h @@ -579,7 +579,7 @@ namespace Tins { * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; /** * \brief Receives a matching response for this packet. diff --git a/include/ipv6.h b/include/ipv6.h index b71315a..0f8913b 100644 --- a/include/ipv6.h +++ b/include/ipv6.h @@ -255,7 +255,7 @@ public: * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; /** * \sa PDU::clone diff --git a/include/pdu.h b/include/pdu.h index bf22197..21ab87f 100644 --- a/include/pdu.h +++ b/include/pdu.h @@ -326,7 +326,9 @@ namespace Tins { * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - virtual bool matches_response(uint8_t *ptr, uint32_t total_sz) { return false; } + virtual bool matches_response(const uint8_t *ptr, uint32_t total_sz) const { + return false; + } /** * \brief Check wether this PDU matches the specified flag. diff --git a/include/pdu_cacher.h b/include/pdu_cacher.h index 968b387..20e73cd 100644 --- a/include/pdu_cacher.h +++ b/include/pdu_cacher.h @@ -109,7 +109,7 @@ public: /** * Forwards the call to the cached PDU. \sa PDU::matches_response. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz) { + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const { return cached.matches_response(ptr, total_sz); } diff --git a/include/radiotap.h b/include/radiotap.h index 89e6bad..f2c213d 100644 --- a/include/radiotap.h +++ b/include/radiotap.h @@ -299,7 +299,7 @@ namespace Tins { * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; /** * \brief Returns the RadioTap frame's header length. diff --git a/include/rawpdu.h b/include/rawpdu.h index c787a0e..32ed3cf 100644 --- a/include/rawpdu.h +++ b/include/rawpdu.h @@ -126,7 +126,7 @@ namespace Tins { * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; /** * \brief Getter for the PDU's type. diff --git a/include/tcp.h b/include/tcp.h index 517214f..78acbe8 100644 --- a/include/tcp.h +++ b/include/tcp.h @@ -395,7 +395,7 @@ namespace Tins { * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; /** * \brief Getter for the PDU's type. diff --git a/include/udp.h b/include/udp.h index ff46536..f43b9fc 100644 --- a/include/udp.h +++ b/include/udp.h @@ -120,7 +120,7 @@ namespace Tins { * \param ptr The pointer to the buffer. * \param total_sz The size of the buffer. */ - bool matches_response(uint8_t *ptr, uint32_t total_sz); + bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; /** * \brief Returns the header size. diff --git a/src/arp.cpp b/src/arp.cpp index d7c135e..fc578bd 100644 --- a/src/arp.cpp +++ b/src/arp.cpp @@ -112,10 +112,10 @@ void ARP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) { memcpy(buffer, &_arp, sizeof(arphdr)); } -bool ARP::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool ARP::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(total_sz < sizeof(arphdr)) return false; - arphdr *arp_ptr = (arphdr*)ptr; + const arphdr *arp_ptr = (const arphdr*)ptr; return arp_ptr->ar_sip == _arp.ar_tip && arp_ptr->ar_tip == _arp.ar_sip; } diff --git a/src/bootp.cpp b/src/bootp.cpp index f66972a..3f7947f 100644 --- a/src/bootp.cpp +++ b/src/bootp.cpp @@ -119,7 +119,7 @@ void BootP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *p std::copy(_vend.begin(), _vend.end(), buffer + sizeof(bootphdr)); } -bool BootP::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool BootP::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(total_sz < sizeof(bootphdr)) return false; const bootphdr *bootp_ptr = (const bootphdr *)ptr; diff --git a/src/dhcpv6.cpp b/src/dhcpv6.cpp index bf63944..32cfa92 100644 --- a/src/dhcpv6.cpp +++ b/src/dhcpv6.cpp @@ -131,7 +131,7 @@ uint32_t DHCPv6::header_size() const { return (is_relay_message() ? (2 + ipaddress_type::address_size * 2) : 4) + options_size; } -bool DHCPv6::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool DHCPv6::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(!is_relay_message()) { if(total_sz < 4 || (ptr[0] == 12 || ptr[0] == 13)) return false; diff --git a/src/dns.cpp b/src/dns.cpp index 892cd9f..d3a606d 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -481,7 +481,7 @@ DNS::resources_type DNS::answers() const { return res; } -bool DNS::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool DNS::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(total_sz < sizeof(dnshdr)) return false; const dnshdr *hdr = (const dnshdr*)ptr; diff --git a/src/dot1q.cpp b/src/dot1q.cpp index bf867a3..21855d9 100644 --- a/src/dot1q.cpp +++ b/src/dot1q.cpp @@ -129,7 +129,7 @@ void Dot1Q::append_padding(bool value) { _append_padding = value; } -bool Dot1Q::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool Dot1Q::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(total_sz < sizeof(_header)) return false; const dot1q_hdr *dot1q_ptr = (const dot1q_hdr*)ptr; diff --git a/src/dot3.cpp b/src/dot3.cpp index 3c58b95..6734fcf 100644 --- a/src/dot3.cpp +++ b/src/dot3.cpp @@ -110,7 +110,7 @@ void Dot3::send(PacketSender &sender, const NetworkInterface &iface) { } #endif // WIN32 -bool Dot3::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool Dot3::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(total_sz < sizeof(ethhdr)) return false; const size_t addr_sz = address_type::address_size; diff --git a/src/ethernetII.cpp b/src/ethernetII.cpp index 65e7204..1c36301 100644 --- a/src/ethernetII.cpp +++ b/src/ethernetII.cpp @@ -122,7 +122,7 @@ void EthernetII::send(PacketSender &sender, const NetworkInterface &iface) { } #endif // WIN32 -bool EthernetII::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool EthernetII::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(total_sz < sizeof(ethhdr)) return false; const size_t addr_sz = address_type::address_size; diff --git a/src/icmp.cpp b/src/icmp.cpp index 282c851..2a59b22 100644 --- a/src/icmp.cpp +++ b/src/icmp.cpp @@ -160,7 +160,7 @@ void ICMP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) _icmp.check = 0; } -bool ICMP::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool ICMP::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(total_sz < sizeof(icmphdr)) return false; const icmphdr *icmp_ptr = (const icmphdr*)ptr; diff --git a/src/icmpv6.cpp b/src/icmpv6.cpp index 0d7451e..f3e44be 100644 --- a/src/icmpv6.cpp +++ b/src/icmpv6.cpp @@ -181,7 +181,7 @@ uint32_t ICMPv6::header_size() const { (has_dest_addr() ? ipaddress_type::address_size : 0); } -bool ICMPv6::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool ICMPv6::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(total_sz < sizeof(icmp6hdr)) return false; const icmp6hdr *hdr_ptr = (const icmp6hdr*)ptr; diff --git a/src/ip.cpp b/src/ip.cpp index 797b46e..a8b36ef 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -429,7 +429,7 @@ void IP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU* pare } } -bool IP::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool IP::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(total_sz < sizeof(iphdr)) return false; const iphdr *ip_ptr = (const iphdr*)ptr; diff --git a/src/ipv6.cpp b/src/ipv6.cpp index 797dac8..891d308 100644 --- a/src/ipv6.cpp +++ b/src/ipv6.cpp @@ -162,7 +162,7 @@ uint32_t IPv6::header_size() const { return sizeof(_header) + headers_size; } -bool IPv6::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool IPv6::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(total_sz < sizeof(ipv6_header)) return false; const ipv6_header *hdr_ptr = (const ipv6_header*)ptr; diff --git a/src/radiotap.cpp b/src/radiotap.cpp index 368ea29..8aa6171 100644 --- a/src/radiotap.cpp +++ b/src/radiotap.cpp @@ -263,7 +263,7 @@ void RadioTap::send(PacketSender &sender, const NetworkInterface &iface) { } #endif -bool RadioTap::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool RadioTap::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(sizeof(_radio) < total_sz) return false; const radiotap_hdr *radio_ptr = (const radiotap_hdr*)ptr; diff --git a/src/rawpdu.cpp b/src/rawpdu.cpp index 98cd1dd..6c8661d 100644 --- a/src/rawpdu.cpp +++ b/src/rawpdu.cpp @@ -57,7 +57,7 @@ void RawPDU::payload(const payload_type &pload) { _payload = pload; } -bool RawPDU::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool RawPDU::matches_response(const uint8_t *ptr, uint32_t total_sz) const { return true; } } diff --git a/src/tcp.cpp b/src/tcp.cpp index 9e1e5fd..e84058b 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -370,7 +370,7 @@ void TCP::internal_add_option(const option &opt) { _total_options_size = (padding) ? _options_size - padding + 4 : _options_size; } -bool TCP::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool TCP::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(total_sz < sizeof(tcphdr)) return false; const tcphdr *tcp_ptr = (const tcphdr*)ptr; diff --git a/src/udp.cpp b/src/udp.cpp index f7f81f0..5e3bb34 100644 --- a/src/udp.cpp +++ b/src/udp.cpp @@ -98,7 +98,7 @@ void UDP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *par } } -bool UDP::matches_response(uint8_t *ptr, uint32_t total_sz) { +bool UDP::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(total_sz < sizeof(udphdr)) return false; const udphdr *udp_ptr = (const udphdr*)ptr;