From b49e5993550f6c762b03a8de70ff7bf70a3ad011 Mon Sep 17 00:00:00 2001 From: Erwin Nindl Date: Tue, 11 Dec 2007 13:53:03 +0000 Subject: added pretty buffer print --- anytun.cpp | 4 ++-- buffer.cpp | 9 ++++++--- buffer.h | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/anytun.cpp b/anytun.cpp index 8c5d7af..8a94dc4 100644 --- a/anytun.cpp +++ b/anytun.cpp @@ -107,7 +107,7 @@ void encryptPacket(Packet & pack, Cypher & c, ConnectionParam & conn, void* p) cLog.msg(Log::PRIO_NOTICE) << "Send Package: seq: " << conn.seq_nr_; cLog.msg(Log::PRIO_NOTICE) << "sID: " << param->opt.getSenderId(); - cLog.msg(Log::PRIO_NOTICE) << "Package dump: " << pack.getBuf(); + cLog.msg(Log::PRIO_NOTICE) << "Package dump: " << pack.getHexDump(); c.cypher(pack, conn.seq_nr_, param->opt.getSenderId()); } @@ -132,7 +132,7 @@ bool decryptPacket(Packet & pack, Cypher & c, ConnectionParam & conn) cLog.msg(Log::PRIO_NOTICE) << "Received Package: seq: " << seq; cLog.msg(Log::PRIO_NOTICE) << "sID: " << sid; - cLog.msg(Log::PRIO_NOTICE) << "Package dump: " << pack.getBuf(); + cLog.msg(Log::PRIO_NOTICE) << "Package dump: " << pack.getHexDump(); return true; } diff --git a/buffer.cpp b/buffer.cpp index 11387da..f0d7940 100644 --- a/buffer.cpp +++ b/buffer.cpp @@ -180,17 +180,20 @@ Buffer::operator u_int8_t*() // just for write/read tun return buf_; } -void Buffer::printHexDump() const +std::string Buffer::getHexDump() const { char text[10]; + std::string ret = ""; for( u_int32_t index = 0; index < length_; index++ ) { std::sprintf(text, "%#4x", buf_[index]); - std::cout << text << " "; + ret += text; + ret += ""; if( ((index+1) % 10) == 0 ) - std::cout << std::endl; + ret += '\n'; } + return ret; } Buffer Buffer::operator^(const Buffer &xor_by) const diff --git a/buffer.h b/buffer.h index e8c33e6..96201e8 100644 --- a/buffer.h +++ b/buffer.h @@ -32,6 +32,7 @@ #define _BUFFER_H_ #include "datatypes.h" +#include class TunDevice; class UDPPacketSource; @@ -58,7 +59,7 @@ public: u_int8_t* getBuf(); u_int8_t& operator[](u_int32_t index); u_int8_t operator[](u_int32_t index) const; - void printHexDump() const; + std::string getHexDump() const; operator u_int8_t*(); // just for write/read tun and packetSource protected: -- cgit v1.2.3