summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-05 23:07:43 (UTC)
committer mickeyl <mickeyl>2003-04-05 23:07:43 (UTC)
commit6a949f685bd3fb50f810ad603eaafdb57720077c (patch) (unidiff)
tree12f1945f8eda7c58c355e25a2b267011ecde19da
parent30e5401a945ebdfd92eedb9f3def9a6acd0fc6ca (diff)
downloadopie-6a949f685bd3fb50f810ad603eaafdb57720077c.zip
opie-6a949f685bd3fb50f810ad603eaafdb57720077c.tar.gz
opie-6a949f685bd3fb50f810ad603eaafdb57720077c.tar.bz2
improve output of OPacket::dump()
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp42
-rw-r--r--libopie2/opienet/opcap.h2
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
@@ -79,35 +79,61 @@ OPacketCapturer* OPacket::packetCapturer() const
79timevalstruct OPacket::timeval() const 79timevalstruct OPacket::timeval() const
80{ 80{
81 return _hdr.ts; 81 return _hdr.ts;
82} 82}
83 83
84 84
85int OPacket::caplen() const 85int OPacket::caplen() const
86{ 86{
87 return _hdr.caplen; 87 return _hdr.caplen;
88} 88}
89 89
90 90
91void OPacket::dump() const 91QString OPacket::dump( int bpl ) const
92{ 92{
93 printf( "OPacket::dump()\n" ); 93 static int index = 0;
94 printf( "----------------\n" ); 94 index++;
95 int len = _hdr.caplen;
96 QString str;
97 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len );
98 str.append( "0000: " );
99 QString tmp;
100 QString bytes;
101 QString chars;
102
103 for ( int i = 0; i < len; ++i )
104 {
105 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp );
106 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] );
107 else chars.append( '.' );
108
109 if ( !((i+1) % bpl) )
110 {
111 str.append( bytes );
112 str.append( ' ' );
113 str.append( chars );
114 str.append( '\n' );
115 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp );
116 bytes = "";
117 chars = "";
118 }
95 119
96 for ( int i = 0; i < _hdr.caplen; ++i ) 120 }
121 if ( (len % bpl) )
97 { 122 {
98 printf( "%02x ", _data[i] ); 123 str.append( bytes.leftJustify( 1 + 3*bpl ) );
99 if ( !((i+1) % 32) ) printf( "\n" ); 124 str.append( chars );
100 } 125 }
101 printf( "\n\n" ); 126 str.append( '\n' );
127 return str;
102} 128}
103 129
104 130
105 131
106int OPacket::len() const 132int OPacket::len() const
107{ 133{
108 return _hdr.len; 134 return _hdr.len;
109} 135}
110 136
111/*====================================================================================== 137/*======================================================================================
112 * OEthernetPacket 138 * OEthernetPacket
113 *======================================================================================*/ 139 *======================================================================================*/
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
@@ -71,25 +71,25 @@ class OPacket : public QObject
71 Q_OBJECT 71 Q_OBJECT
72 72
73 public: 73 public:
74 OPacket( packetheaderstruct, const unsigned char*, QObject* parent ); 74 OPacket( packetheaderstruct, const unsigned char*, QObject* parent );
75 virtual ~OPacket(); 75 virtual ~OPacket();
76 76
77 timevalstruct timeval() const; 77 timevalstruct timeval() const;
78 78
79 OPacketCapturer* packetCapturer() const; 79 OPacketCapturer* packetCapturer() const;
80 80
81 int caplen() const; 81 int caplen() const;
82 int len() const; 82 int len() const;
83 void dump() const; 83 QString dump( int = 32 ) const;
84 84
85 private: 85 private:
86 const packetheaderstruct _hdr; // pcap packet header 86 const packetheaderstruct _hdr; // pcap packet header
87 const unsigned char* _data; // pcap packet data 87 const unsigned char* _data; // pcap packet data
88 const unsigned char* _end; // end of pcap packet data 88 const unsigned char* _end; // end of pcap packet data
89}; 89};
90 90
91/*====================================================================================== 91/*======================================================================================
92 * OEthernetPacket - DLT_EN10MB frame 92 * OEthernetPacket - DLT_EN10MB frame
93 *======================================================================================*/ 93 *======================================================================================*/
94 94
95class OEthernetPacket : public QObject 95class OEthernetPacket : public QObject