From d0c85dd8bab06d302b9857e5e7c54b0f597a8a1e Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Wed, 18 Mar 2015 11:38:22 +0100 Subject: [PATCH] added ip source and destination address to IpHeader::to_string --- src/CMakeLists.txt | 1 + src/ip/ipheader.cpp | 35 +++++++++++++++++++++++++++++++++++ src/ip/ipheader.h | 4 +--- test/CMakeLists.test_ipv4header.txt | 1 + test/CMakeLists.test_ipv6header.txt | 1 + 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/ip/ipheader.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6416546..14801e0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 index 0000000..379c3d5 --- /dev/null +++ b/src/ip/ipheader.cpp @@ -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 + +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) + diff --git a/src/ip/ipheader.h b/src/ip/ipheader.h index a103884..f0ad72e 100644 --- a/src/ip/ipheader.h +++ b/src/ip/ipheader.h @@ -24,7 +24,6 @@ #define IPHEADER_H #include -#include #include #include @@ -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 IpHeaderPtr; diff --git a/test/CMakeLists.test_ipv4header.txt b/test/CMakeLists.test_ipv4header.txt index ff48865..7ac405f 100644 --- a/test/CMakeLists.test_ipv4header.txt +++ b/test/CMakeLists.test_ipv4header.txt @@ -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 ) diff --git a/test/CMakeLists.test_ipv6header.txt b/test/CMakeLists.test_ipv6header.txt index 5fcae97..e197f21 100644 --- a/test/CMakeLists.test_ipv6header.txt +++ b/test/CMakeLists.test_ipv6header.txt @@ -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 ) -- 1.7.1