Fix: the boolean logic was inverted.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Thu, 29 Mar 2012 01:46:43 +0000 (22:46 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Thu, 29 Mar 2012 01:46:43 +0000 (22:46 -0300)
- 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
src/icmp/icmpv6packet.cpp
src/tcp/tcpipv4segment.cpp
src/tcp/tcpipv6segment.cpp

index 89f038d..6a20879 100644 (file)
@@ -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>>(
index e31c863..f45356e 100644 (file)
@@ -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>>(
index 0994bae..f9071c1 100644 (file)
@@ -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>>(
index d110a04..499f896 100644 (file)
@@ -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>>(