summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp6
1 files changed, 2 insertions, 4 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 8ec4f47..8184f21 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -103,116 +103,114 @@ timevalstruct OPacket::timeval() const
103 103
104 104
105int OPacket::caplen() const 105int OPacket::caplen() const
106{ 106{
107 return _hdr.caplen; 107 return _hdr.caplen;
108} 108}
109 109
110 110
111void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) 111void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l )
112{ 112{
113 if (!l) return; 113 if (!l) return;
114 QObject* o = l->first(); 114 QObject* o = l->first();
115 while ( o ) 115 while ( o )
116 { 116 {
117 stats[o->name()]++; 117 stats[o->name()]++;
118 updateStats( stats, const_cast<QObjectList*>( o->children() ) ); 118 updateStats( stats, const_cast<QObjectList*>( o->children() ) );
119 o = l->next(); 119 o = l->next();
120 } 120 }
121} 121}
122 122
123 123
124QString OPacket::dumpStructure() const 124QString OPacket::dumpStructure() const
125{ 125{
126 return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; 126 return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]";
127} 127}
128 128
129 129
130QString OPacket::_dumpStructure( QObjectList* l ) const 130QString OPacket::_dumpStructure( QObjectList* l ) const
131{ 131{
132 if (!l) return QString::null; 132 if (!l) return QString::null;
133 QObject* o = l->first(); 133 QObject* o = l->first();
134 QString str(" "); 134 QString str(" ");
135 135
136 while ( o ) 136 while ( o )
137 { 137 {
138 str.append( o->name() ); 138 str.append( o->name() );
139 str.append( " |" ); 139 str.append( " |" );
140 str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); 140 str += _dumpStructure( const_cast<QObjectList*>( o->children() ) );
141 o = l->next(); 141 o = l->next();
142 } 142 }
143 return str; 143 return str;
144} 144}
145 145
146QString OPacket::dump( int bpl ) const 146QString OPacket::dump( int bpl ) const
147{ 147{
148 static int index = 0; 148 static int index = 0;
149 index++; 149 index++;
150 int len = _hdr.caplen; 150 int len = _hdr.caplen;
151 QString str; 151 QString str( "000:" );
152 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len );
153 str.append( "0000: " );
154 QString tmp; 152 QString tmp;
155 QString bytes; 153 QString bytes;
156 QString chars; 154 QString chars;
157 155
158 for ( int i = 0; i < len; ++i ) 156 for ( int i = 0; i < len; ++i )
159 { 157 {
160 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); 158 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp );
161 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); 159 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] );
162 else chars.append( '.' ); 160 else chars.append( '.' );
163 161
164 if ( !((i+1) % bpl) ) 162 if ( !((i+1) % bpl) )
165 { 163 {
166 str.append( bytes ); 164 str.append( bytes );
167 str.append( ' ' ); 165 str.append( ' ' );
168 str.append( chars ); 166 str.append( chars );
169 str.append( '\n' ); 167 str.append( '\n' );
170 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); 168 tmp.sprintf( "%03X:", i+1 ); str.append( tmp );
171 bytes = ""; 169 bytes = "";
172 chars = ""; 170 chars = "";
173 } 171 }
174 172
175 } 173 }
176 if ( (len % bpl) ) 174 if ( (len % bpl) )
177 { 175 {
178 str.append( bytes.leftJustify( 1 + 3*bpl ) ); 176 str.append( bytes.leftJustify( 1 + 3*bpl ) );
179 str.append( chars ); 177 str.append( chars );
180 } 178 }
181 str.append( '\n' ); 179 str.append( '\n' );
182 return str; 180 return str;
183} 181}
184 182
185 183
186int OPacket::len() const 184int OPacket::len() const
187{ 185{
188 return _hdr.len; 186 return _hdr.len;
189} 187}
190 188
191 189
192QTextStream& operator<<( QTextStream& s, const OPacket& p ) 190QTextStream& operator<<( QTextStream& s, const OPacket& p )
193{ 191{
194 s << p.dumpStructure(); 192 s << p.dumpStructure();
195} 193}
196 194
197 195
198/*====================================================================================== 196/*======================================================================================
199 * OEthernetPacket 197 * OEthernetPacket
200 *======================================================================================*/ 198 *======================================================================================*/
201 199
202OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) 200OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
203 :QObject( parent, "Ethernet" ), _ether( data ) 201 :QObject( parent, "Ethernet" ), _ether( data )
204{ 202{
205 203
206 odebug << "Source = " << sourceAddress().toString() << oendl; 204 odebug << "Source = " << sourceAddress().toString() << oendl;
207 odebug << "Destination = " << destinationAddress().toString() << oendl; 205 odebug << "Destination = " << destinationAddress().toString() << oendl;
208 206
209 if ( sourceAddress() == OMacAddress::broadcast ) 207 if ( sourceAddress() == OMacAddress::broadcast )
210 odebug << "Source is broadcast address" << oendl; 208 odebug << "Source is broadcast address" << oendl;
211 if ( destinationAddress() == OMacAddress::broadcast ) 209 if ( destinationAddress() == OMacAddress::broadcast )
212 odebug << "Destination is broadcast address" << oendl; 210 odebug << "Destination is broadcast address" << oendl;
213 211
214 switch ( type() ) 212 switch ( type() )
215 { 213 {
216 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 214 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
217 case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; 215 case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break;
218 case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } 216 case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; }