-rw-r--r-- | libopie2/opienet/opcap.cpp | 42 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 2 |
2 files changed, 35 insertions, 9 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 913d42e..6ddd457 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp @@ -88,17 +88,43 @@ int OPacket::caplen() const } -void OPacket::dump() const -{ - printf( "OPacket::dump()\n" ); - printf( "----------------\n" ); +QString OPacket::dump( int bpl ) const +{ + static int index = 0; + index++; + int len = _hdr.caplen; + QString str; + str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); + str.append( "0000: " ); + QString tmp; + QString bytes; + QString chars; + + for ( int i = 0; i < len; ++i ) + { + tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); + if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); + else chars.append( '.' ); + + if ( !((i+1) % bpl) ) + { + str.append( bytes ); + str.append( ' ' ); + str.append( chars ); + str.append( '\n' ); + tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); + bytes = ""; + chars = ""; + } - for ( int i = 0; i < _hdr.caplen; ++i ) + } + if ( (len % bpl) ) { - printf( "%02x ", _data[i] ); - if ( !((i+1) % 32) ) printf( "\n" ); + str.append( bytes.leftJustify( 1 + 3*bpl ) ); + str.append( chars ); } - printf( "\n\n" ); + str.append( '\n' ); + return str; } diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index 0b06572..04d22ff 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h @@ -80,7 +80,7 @@ class OPacket : public QObject int caplen() const; int len() const; - void dump() const; + QString dump( int = 32 ) const; private: const packetheaderstruct _hdr; // pcap packet header |