author | mickeyl <mickeyl> | 2003-04-05 23:07:43 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-05 23:07:43 (UTC) |
commit | 6a949f685bd3fb50f810ad603eaafdb57720077c (patch) (side-by-side diff) | |
tree | 12f1945f8eda7c58c355e25a2b267011ecde19da /libopie2/opienet/opcap.cpp | |
parent | 30e5401a945ebdfd92eedb9f3def9a6acd0fc6ca (diff) | |
download | opie-6a949f685bd3fb50f810ad603eaafdb57720077c.zip opie-6a949f685bd3fb50f810ad603eaafdb57720077c.tar.gz opie-6a949f685bd3fb50f810ad603eaafdb57720077c.tar.bz2 |
improve output of OPacket::dump()
-rw-r--r-- | libopie2/opienet/opcap.cpp | 42 |
1 files changed, 34 insertions, 8 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 @@ -67,59 +67,85 @@ OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject* OPacket::~OPacket() { } OPacketCapturer* OPacket::packetCapturer() const { return parent()->inherits( "OPacketCapturer" ) ? static_cast<OPacketCapturer*>( parent() ) : 0; } timevalstruct OPacket::timeval() const { return _hdr.ts; } int OPacket::caplen() const { return _hdr.caplen; } -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; } int OPacket::len() const { return _hdr.len; } /*====================================================================================== * OEthernetPacket *======================================================================================*/ OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) :QObject( parent, "Ethernet" ), _ether( data ) { qDebug( "Source = %s", (const char*) sourceAddress().toString() ); qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); if ( sourceAddress() == OMacAddress::broadcast ) qDebug( "Source is broadcast address" ); if ( destinationAddress() == OMacAddress::broadcast ) |