From 0aa3b99f422bd58018d8060e0cfa8ec9127b81d4 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Wed, 28 Mar 2012 22:46:43 -0300 Subject: [PATCH] Fix: the boolean logic was inverted. - When fail() returns false, the read() and write() methods should return true; - This avoids the annoying "Error: Could not read ICMP packet" and "Error: could not read TCP Segment." messages. --- src/icmp/icmpv4packet.cpp | 18 ++++++++++++++++-- src/icmp/icmpv6packet.cpp | 18 ++++++++++++++++-- src/tcp/tcpipv4segment.cpp | 8 ++++---- src/tcp/tcpipv6segment.cpp | 8 ++++---- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/icmp/icmpv4packet.cpp b/src/icmp/icmpv4packet.cpp index 89f038d..6a20879 100644 --- a/src/icmp/icmpv4packet.cpp +++ b/src/icmp/icmpv4packet.cpp @@ -210,22 +210,36 @@ void Icmpv4Packet::print_destination_unreachable() const << " Destination Net Unreachable" << endl; } +/** + * @brief Read the ICMP packet from the @c istream. + * + * @param is The input stream. + * + * @return @c true if the read was successful, or @c false if an error occurred. + */ bool Icmpv4Packet::read( istream &is ) { is.clear(); is >> *this; - return is.fail(); + return !is.fail(); } +/** + * @brief Write the ICMP packet to the @c ostream. + * + * @param os The output stream. + * + * @return @c true if the write was successful, or @c false if an error occurred. + */ bool Icmpv4Packet::write( ostream &os ) const { os.clear(); os << *this; - return os.fail(); + return !os.fail(); } istream& operator>>( diff --git a/src/icmp/icmpv6packet.cpp b/src/icmp/icmpv6packet.cpp index e31c863..f45356e 100644 --- a/src/icmp/icmpv6packet.cpp +++ b/src/icmp/icmpv6packet.cpp @@ -223,22 +223,36 @@ void Icmpv6Packet::print_destination_unreachable() const << " Destination Net Unreachable" << endl; } +/** + * @brief Read the ICMP packet from the @c istream. + * + * @param is The input stream. + * + * @return @c true if the read was successful, or @c false if an error occurred. + */ bool Icmpv6Packet::read( istream &is ) { is.clear(); is >> *this; - return is.fail(); + return !is.fail(); } +/** + * @brief Write the ICMP packet to the @c ostream. + * + * @param os The output stream. + * + * @return @c true if the write was successful, or @c false if an error occurred. + */ bool Icmpv6Packet::write( ostream &os ) const { os.clear(); os << *this; - return os.fail(); + return !os.fail(); } istream& operator>>( diff --git a/src/tcp/tcpipv4segment.cpp b/src/tcp/tcpipv4segment.cpp index 0994bae..f9071c1 100644 --- a/src/tcp/tcpipv4segment.cpp +++ b/src/tcp/tcpipv4segment.cpp @@ -137,7 +137,7 @@ void TcpIpv4Segment::print_rst_reply( * * @param is The input stream. * - * @return @c true if the read was successful, or @c false if an error occured. + * @return @c true if the read was successful, or @c false if an error occurred. */ bool TcpIpv4Segment::read( istream &is ) { @@ -145,7 +145,7 @@ bool TcpIpv4Segment::read( istream &is ) is >> *this; - return is.fail(); + return !is.fail(); } /** @@ -153,7 +153,7 @@ bool TcpIpv4Segment::read( istream &is ) * * @param os The output stream. * - * @return @c true if the write was successful, or @c false if an error occured. + * @return @c true if the write was successful, or @c false if an error occurred. */ bool TcpIpv4Segment::write( ostream &os ) const { @@ -161,7 +161,7 @@ bool TcpIpv4Segment::write( ostream &os ) const os << *this; - return os.fail(); + return !os.fail(); } istream& operator>>( diff --git a/src/tcp/tcpipv6segment.cpp b/src/tcp/tcpipv6segment.cpp index d110a04..499f896 100644 --- a/src/tcp/tcpipv6segment.cpp +++ b/src/tcp/tcpipv6segment.cpp @@ -137,7 +137,7 @@ void TcpIpv6Segment::print_rst_reply( * * @param is The input stream. * - * @return @c true if the read was successful, or @c false if an error occured. + * @return @c true if the read was successful, or @c false if an error occurred. */ bool TcpIpv6Segment::read( istream &is ) { @@ -145,7 +145,7 @@ bool TcpIpv6Segment::read( istream &is ) is >> *this; - return is.fail(); + return !is.fail(); } /** @@ -153,7 +153,7 @@ bool TcpIpv6Segment::read( istream &is ) * * @param os The output stream. * - * @return @c true if the write was successful, or @c false if an error occured. + * @return @c true if the write was successful, or @c false if an error occurred. */ bool TcpIpv6Segment::write( ostream &os ) const { @@ -161,7 +161,7 @@ bool TcpIpv6Segment::write( ostream &os ) const os << *this; - return os.fail(); + return !os.fail(); } istream& operator>>( -- 1.7.1