Hardening the match methods through asserts.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sun, 26 Feb 2012 20:58:50 +0000 (17:58 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sun, 26 Feb 2012 20:58:50 +0000 (17:58 -0300)
src/icmp/icmpv4packet.cpp
src/icmp/icmpv6packet.cpp
src/tcp/tcpipv4segment.cpp
src/tcp/tcpipv6segment.cpp

index 3bd148b..89f038d 100644 (file)
@@ -8,6 +8,8 @@
 
 #include <iostream>
 
+#include <boost/assert.hpp>
+
 #include <logfunc.hpp>
 
 using namespace std;
@@ -100,6 +102,8 @@ bool Icmpv4Packet::match_echo_reply(
         const address &source_address
 ) const
 {
+    BOOST_ASSERT( source_address.is_v4() );
+
     return match( Icmpv4Type_EchoReply, identifier, sequence_number, source_address );
 }
 
@@ -120,6 +124,8 @@ bool Icmpv4Packet::match_destination_unreachable(
         const address &source_address
 ) const
 {
+    BOOST_ASSERT( source_address.is_v4() );
+
     return match( Icmpv4Type_DestinationUnreachable, identifier, sequence_number, source_address );
 }
 
@@ -141,6 +147,8 @@ bool Icmpv4Packet::match(
         const address &source_address
 ) const
 {
+    BOOST_ASSERT( source_address.is_v4() );
+
     bool type_match = IcmpPayloadHeader.get_type() == type ? true : false;
     bool identifier_match = IcmpPayloadHeader.get_identifier() == identifier ? true: false;
     bool seq_num_match = IcmpPayloadHeader.get_sequence_number() == sequence_number ? true : false;
index 20d9123..e31c863 100644 (file)
@@ -8,6 +8,8 @@
 
 #include <iostream>
 
+#include <boost/assert.hpp>
+
 #include <logfunc.hpp>
 
 using namespace std;
@@ -100,6 +102,8 @@ bool Icmpv6Packet::match_echo_reply(
         const address &source_address
 ) const
 {
+    BOOST_ASSERT( source_address.is_v6() );
+
     return match( Icmpv6Type_EchoReply, identifier, sequence_number, source_address );
 }
 
@@ -120,6 +124,8 @@ bool Icmpv6Packet::match_destination_unreachable(
         const address &source_address
 ) const
 {
+    BOOST_ASSERT( source_address.is_v6() );
+
     return match( Icmpv6Type_DestinationUnreachable, identifier, sequence_number, source_address );
 }
 
@@ -138,9 +144,11 @@ bool Icmpv6Packet::match(
         const Icmpv6Type type,
         const uint16_t identifier,
         const uint16_t sequence_number,
-        const address &/*source_address*/
+        const address &source_address
 ) const
 {
+    BOOST_ASSERT( source_address.is_v6() );
+
     bool type_match = IcmpPayloadHeader.get_type() == type ? true : false;
     bool identifier_match = IcmpPayloadHeader.get_identifier() == identifier ? true: false;
     bool seq_num_match = IcmpPayloadHeader.get_sequence_number() == sequence_number ? true : false;
index 8dc663c..0994bae 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "tcp/tcpipv4segment.h"
 
+#include <boost/assert.hpp>
+
 #include <logfunc.hpp>
 
 using namespace std;
@@ -92,6 +94,8 @@ bool TcpIpv4Segment::match_rst_reply(
         const address &source_address
 ) const
 {
+    BOOST_ASSERT( source_address.is_v4() );
+
     Ipv4Header ipv4_header = get_ip_header();
     TcpHeader tcp_header = get_tcp_header();
 
index 00c9734..d110a04 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "tcp/tcpipv6segment.h"
 
+#include <boost/assert.hpp>
+
 #include <logfunc.hpp>
 
 using namespace std;
@@ -92,6 +94,8 @@ bool TcpIpv6Segment::match_rst_reply(
         const address &source_address
 ) const
 {
+    BOOST_ASSERT( source_address.is_v6() );
+
     Ipv6Header ipv6_header = get_ip_header();
     TcpHeader tcp_header = get_tcp_header();