From 8dcc3682dab0d4ed77700f4d30cecc31898adeb8 Mon Sep 17 00:00:00 2001 From: Erwin Nindl Date: Wed, 12 Sep 2007 11:21:31 +0000 Subject: overloaded std::ostream& operator<< for Buffer --- buffer.cpp | 14 ++++++++++++++ buffer.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/buffer.cpp b/buffer.cpp index 1b194bd..808f639 100644 --- a/buffer.cpp +++ b/buffer.cpp @@ -30,6 +30,8 @@ #include #include +#include +#include #include "datatypes.h" #include "buffer.h" @@ -163,3 +165,15 @@ Buffer::operator u_int8_t*() // just for write/read tun return buf_; } +std::ostream& operator<<(std::ostream& output, const Buffer &src) +{ + char buf[10]; + + for( u_int32_t index = 0; index < src.getLength(); index++ ) + { + std::sprintf(buf, "%#x", src[index]); + output << buf << " "; + } + + return output; +} diff --git a/buffer.h b/buffer.h index 2e3a75e..fc9d78b 100644 --- a/buffer.h +++ b/buffer.h @@ -33,6 +33,8 @@ #include "datatypes.h" +#include + class TunDevice; class UDPPacketSource; @@ -52,6 +54,7 @@ public: u_int8_t* getBuf(); u_int8_t& operator[](u_int32_t index); u_int8_t operator[](u_int32_t index) const; + friend std::ostream& operator<<(std::ostream& output, const Buffer &src); protected: operator u_int8_t*(); // just for write/read tun and packetSource -- cgit v1.2.3