Providing read() and write() methods, once operators >> and << does work properly...
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Fri, 4 Nov 2011 02:08:39 +0000 (00:08 -0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Fri, 4 Nov 2011 02:11:13 +0000 (00:11 -0200)
src/icmp/icmppacket.h
src/icmp/icmpv4packet.cpp
src/icmp/icmpv4packet.h
src/icmp/icmpv6packet.cpp
src/icmp/icmpv6packet.h

index 7949198..a2c1084 100644 (file)
 
 #include <stdint.h>
 
+#include <iostream>
 #include <string>
 
 #include <boost/asio.hpp>
 #include <boost/date_time/posix_time/posix_time_types.hpp>
+#include <boost/shared_ptr.hpp>
 
 //-----------------------------------------------------------------------------
 // IcmpPacket
@@ -58,6 +60,15 @@ public:
     ) const = 0;
     virtual void print_destination_unreachable() const = 0;
 
+    virtual bool read( std::istream &is ) = 0;
+    virtual void write( std::ostream &os ) const = 0;
+
 };
 
+//-----------------------------------------------------------------------------
+// IcmpPacketItem
+//-----------------------------------------------------------------------------
+
+typedef boost::shared_ptr<IcmpPacket> IcmpPacketItem;
+
 #endif // ICMP_PACKET_H
index 65155e2..0a60aa8 100644 (file)
@@ -202,6 +202,18 @@ void Icmpv4Packet::print_destination_unreachable() const
          << " Destination Net Unreachable" << endl;
 }
 
+bool Icmpv4Packet::read( istream &is )
+{
+    is >> *this;
+
+    return is.fail();
+}
+
+void Icmpv4Packet::write( ostream &os ) const
+{
+    os << *this;
+}
+
 istream& operator>>(
         istream &is,
         Icmpv4Packet &packet
index a2dc56d..51511a3 100644 (file)
@@ -97,6 +97,9 @@ public:
     ) const;
     void print_destination_unreachable() const;
 
+    bool read( std::istream &is );
+    void write( std::ostream &os ) const;
+
     friend std::istream& operator>>(
             std::istream &is,
             Icmpv4Packet &packet
index 0661c93..ecaff54 100644 (file)
@@ -202,6 +202,18 @@ void Icmpv6Packet::print_destination_unreachable() const
          << " Destination Net Unreachable" << endl;
 }
 
+bool Icmpv6Packet::read( istream &is )
+{
+    is >> *this;
+
+    return is.fail();
+}
+
+void Icmpv6Packet::write( ostream &os ) const
+{
+    os << *this;
+}
+
 istream& operator>>(
         istream &is,
         Icmpv6Packet &packet
index d3923b4..4e88da8 100644 (file)
@@ -111,6 +111,9 @@ public:
     ) const;
     void print_destination_unreachable() const;
 
+    bool read( std::istream &is );
+    void write( std::ostream &os ) const;
+
     friend std::istream& operator>>(
             std::istream &is,
             Icmpv6Packet &packet