added ip source and destination address to IpHeader::to_string
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 18 Mar 2015 10:38:22 +0000 (11:38 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 18 Mar 2015 10:38:22 +0000 (11:38 +0100)
src/CMakeLists.txt
src/ip/ipheader.cpp [new file with mode: 0644]
src/ip/ipheader.h
test/CMakeLists.test_ipv4header.txt
test/CMakeLists.test_ipv6header.txt

index 6416546..14801e0 100644 (file)
@@ -83,6 +83,7 @@ set(SOURCES
     icmp/icmppacket.cpp
     icmp/icmppinger.cpp
     icmp/icmppacketfactory.cpp
+    ip/ipheader.cpp
     ip/ipv4header.cpp
     ip/ipv6header.cpp
     link/linkstatus.cpp
diff --git a/src/ip/ipheader.cpp b/src/ip/ipheader.cpp
new file mode 100644 (file)
index 0000000..379c3d5
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ The software in this package is distributed under the GNU General
+ Public License version 2 (with a special exception described below).
+
+ A copy of GNU General Public License (GPL) is included in this distribution,
+ in the file COPYING.GPL.
+
+ As a special exception, if other files instantiate templates or use macros
+ or inline functions from this file, or you compile this file and link it
+ with other works to produce a work based on this file, this file
+ does not by itself cause the resulting work to be covered
+ by the GNU General Public License.
+
+ However the source code for this file must still be made available
+ in accordance with section (3) of the GNU General Public License.
+
+ This exception does not invalidate any other reasons why a work based
+ on this file might be covered by the GNU General Public License.
+
+ Christian Herdtweck, Intra2net AG 2015
+ */
+
+#include "ip/ipheader.h"
+#include <sstream>
+
+std::string IpHeader::to_string() const
+{
+    std::stringstream buf;
+    buf << "[IP header: from " << get_source_address().to_string() << " to "
+        << get_destination_address().to_string() << "]";
+    return buf.str();
+}
+
+// (created using vim -- the world's best text editor)
+
index a103884..f0ad72e 100644 (file)
@@ -24,7 +24,6 @@
 #define IPHEADER_H
 
 #include <stdint.h>
-#include <istream>
 #include <boost/shared_ptr.hpp>
 #include <boost/asio/ip/address.hpp>
 
@@ -43,8 +42,7 @@ public:
 
     virtual ~IpHeader() {}
 
-    virtual std::string to_string() const
-    {   return "[IP header]";  }
+    virtual std::string to_string() const;
 };
 
 typedef boost::shared_ptr<IpHeader> IpHeaderPtr;
index ff48865..7ac405f 100644 (file)
@@ -2,6 +2,7 @@
 add_executable(test_ipv4header
     test_ipv4header.cpp
     ${CMAKE_SOURCE_DIR}/src/boost_assert_handler.cpp
+    ${CMAKE_SOURCE_DIR}/src/ip/ipheader.cpp
     ${CMAKE_SOURCE_DIR}/src/ip/ipv4header.cpp
     ${CMAKE_SOURCE_DIR}/src/host/messagepayload.cpp
 )
index 5fcae97..e197f21 100644 (file)
@@ -2,6 +2,7 @@
 add_executable(test_ipv6header
     test_ipv6header.cpp
     ${CMAKE_SOURCE_DIR}/src/boost_assert_handler.cpp
+    ${CMAKE_SOURCE_DIR}/src/ip/ipheader.cpp
     ${CMAKE_SOURCE_DIR}/src/ip/ipv6header.cpp
     ${CMAKE_SOURCE_DIR}/src/host/messagepayload.cpp
 )