From b778520b36efd377f80975adae9f12f1f032e403 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Sun, 6 Nov 2011 19:35:25 -0200 Subject: [PATCH] The IcmpPacket's write() method returns a boolean, mirroring the read() method. --- src/icmp/icmppacket.h | 3 +-- src/icmp/icmpv4packet.cpp | 10 +++++++--- src/icmp/icmpv4packet.h | 2 +- src/icmp/icmpv6packet.cpp | 6 +++++- src/icmp/icmpv6packet.h | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/icmp/icmppacket.h b/src/icmp/icmppacket.h index 3760ede..352e105 100644 --- a/src/icmp/icmppacket.h +++ b/src/icmp/icmppacket.h @@ -24,7 +24,6 @@ #include #include -#include #include #include @@ -58,7 +57,7 @@ public: virtual void print_destination_unreachable() const = 0; virtual bool read( std::istream &is ) = 0; - virtual void write( std::ostream &os ) const = 0; + virtual bool write( std::ostream &os ) const = 0; protected: IcmpPacket(); diff --git a/src/icmp/icmpv4packet.cpp b/src/icmp/icmpv4packet.cpp index 180d464..3bd148b 100644 --- a/src/icmp/icmpv4packet.cpp +++ b/src/icmp/icmpv4packet.cpp @@ -86,13 +86,13 @@ IcmpData Icmpv4Packet::get_icmp_data() const /** * @brief Convenience method to check if this packet, matching the arguments, - * is a echo reply. + * is an echo reply. * * @param identifier The identifier. * @param sequence_number The sequence number. * @param source_address The source address. * - * @return @c true if this packet is a echo reply, or @c false otherwise. + * @return @c true if this packet is an echo reply, or @c false otherwise. */ bool Icmpv4Packet::match_echo_reply( const uint16_t identifier, @@ -211,9 +211,13 @@ bool Icmpv4Packet::read( istream &is ) return is.fail(); } -void Icmpv4Packet::write( ostream &os ) const +bool Icmpv4Packet::write( ostream &os ) const { + os.clear(); + os << *this; + + return os.fail(); } istream& operator>>( diff --git a/src/icmp/icmpv4packet.h b/src/icmp/icmpv4packet.h index 459ea58..ac1c7f0 100644 --- a/src/icmp/icmpv4packet.h +++ b/src/icmp/icmpv4packet.h @@ -98,7 +98,7 @@ public: virtual void print_destination_unreachable() const; virtual bool read( std::istream &is ); - virtual void write( std::ostream &os ) const; + virtual bool write( std::ostream &os ) const; friend std::istream& operator>>( std::istream &is, diff --git a/src/icmp/icmpv6packet.cpp b/src/icmp/icmpv6packet.cpp index 1823d31..02a08f2 100644 --- a/src/icmp/icmpv6packet.cpp +++ b/src/icmp/icmpv6packet.cpp @@ -211,9 +211,13 @@ bool Icmpv6Packet::read( istream &is ) return is.fail(); } -void Icmpv6Packet::write( ostream &os ) const +bool Icmpv6Packet::write( ostream &os ) const { + os.clear(); + os << *this; + + return os.fail(); } istream& operator>>( diff --git a/src/icmp/icmpv6packet.h b/src/icmp/icmpv6packet.h index 5ad9db1..2816b0b 100644 --- a/src/icmp/icmpv6packet.h +++ b/src/icmp/icmpv6packet.h @@ -112,7 +112,7 @@ public: virtual void print_destination_unreachable() const; virtual bool read( std::istream &is ); - virtual void write( std::ostream &os ) const; + virtual bool write( std::ostream &os ) const; friend std::istream& operator>>( std::istream &is, -- 1.7.1