summaryrefslogtreecommitdiff
path: root/libopie2/opienet/opcap.cpp
Unidiff
Diffstat (limited to 'libopie2/opienet/opcap.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 7463320..fdd519c 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -101,32 +101,31 @@ void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l )
101{ 101{
102 if (!l) return; 102 if (!l) return;
103 QObject* o = l->first(); 103 QObject* o = l->first();
104 while ( o ) 104 while ( o )
105 { 105 {
106 stats[o->name()]++; 106 stats[o->name()]++;
107 updateStats( stats, const_cast<QObjectList*>( o->children() ) ); 107 updateStats( stats, const_cast<QObjectList*>( o->children() ) );
108 o = l->next(); 108 o = l->next();
109 } 109 }
110} 110}
111 111
112 112
113void OPacket::dumpStructure( QObjectList* l ) 113QString OPacket::dumpStructure() const
114{ 114{
115 QString packetString( "[ |" + _dumpStructure( l ) + " ]" ); 115 return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]";
116 odebug << "OPacket::dumpStructure: " << packetString << oendl;
117} 116}
118 117
119 118
120QString OPacket::_dumpStructure( QObjectList* l ) 119QString OPacket::_dumpStructure( QObjectList* l ) const
121{ 120{
122 if (!l) return QString::null; 121 if (!l) return QString::null;
123 QObject* o = l->first(); 122 QObject* o = l->first();
124 QString str(" "); 123 QString str(" ");
125 124
126 while ( o ) 125 while ( o )
127 { 126 {
128 str.append( o->name() ); 127 str.append( o->name() );
129 str.append( " |" ); 128 str.append( " |" );
130 str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); 129 str += _dumpStructure( const_cast<QObjectList*>( o->children() ) );
131 o = l->next(); 130 o = l->next();
132 } 131 }
@@ -170,24 +169,30 @@ QString OPacket::dump( int bpl ) const
170 } 169 }
171 str.append( '\n' ); 170 str.append( '\n' );
172 return str; 171 return str;
173} 172}
174 173
175 174
176int OPacket::len() const 175int OPacket::len() const
177{ 176{
178 return _hdr.len; 177 return _hdr.len;
179} 178}
180 179
181 180
181QTextStream& operator<<( QTextStream& s, const OPacket& p )
182{
183 s << p.dumpStructure();
184}
185
186
182/*====================================================================================== 187/*======================================================================================
183 * OEthernetPacket 188 * OEthernetPacket
184 *======================================================================================*/ 189 *======================================================================================*/
185 190
186OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) 191OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
187 :QObject( parent, "Ethernet" ), _ether( data ) 192 :QObject( parent, "Ethernet" ), _ether( data )
188{ 193{
189 194
190 odebug << "Source = " << sourceAddress().toString(); 195 odebug << "Source = " << sourceAddress().toString();
191 odebug << "Destination = " << destinationAddress().toString(); 196 odebug << "Destination = " << destinationAddress().toString();
192 197
193 if ( sourceAddress() == OMacAddress::broadcast ) 198 if ( sourceAddress() == OMacAddress::broadcast )
@@ -720,25 +725,25 @@ bool OWaveLanPacket::usesWep() const
720OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) 725OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent )
721 :QObject( parent, "802.11 Management" ), _header( data ), 726 :QObject( parent, "802.11 Management" ), _header( data ),
722 _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) 727 _body( (const struct ieee_802_11_mgmt_body*) (data+1) )
723{ 728{
724 odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl; 729 odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl;
725 odebug << "Detected subtype is " << managementType() << oendl; 730 odebug << "Detected subtype is " << managementType() << oendl;
726 731
727 // Grab tagged values. 732 // Grab tagged values.
728 // Beacons contain a 12 byte long fixed parameters set before the tagged parameters come, 733 // Beacons contain a 12 byte long fixed parameters set before the tagged parameters come,
729 // Other management frames don't - which is why we have to inspect the subtype here. 734 // Other management frames don't - which is why we have to inspect the subtype here.
730 735
731 const unsigned char* ptr = managementType() == "Beacon" ? (const unsigned char*) (_body+1) : (const unsigned char*) (_header+1); 736 const unsigned char* ptr = managementType() == "Beacon" ? (const unsigned char*) (_body+1) : (const unsigned char*) (_header+1);
732 737
733 while (ptr < end) 738 while (ptr < end)
734 { 739 {
735 switch ( *ptr ) 740 switch ( *ptr )
736 { 741 {
737 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; 742 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break;
738 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; 743 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break;
739 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; 744 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break;
740 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; 745 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break;
741 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; 746 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break;
742 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; 747 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break;
743 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; 748 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break;
744 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; 749 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break;
@@ -1179,27 +1184,25 @@ OPacket* OPacketCapturer::next()
1179 const unsigned char* pdata = pcap_next( _pch, &header ); 1184 const unsigned char* pdata = pcap_next( _pch, &header );
1180 odebug << "<== OPacketCapturer::next()" << oendl; 1185 odebug << "<== OPacketCapturer::next()" << oendl;
1181 1186
1182 if ( pdata && header.len ) 1187 if ( pdata && header.len )
1183 { 1188 {
1184 OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); 1189 OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
1185 // packets shouldn't be inserted in the QObject child-parent hierarchy, 1190 // packets shouldn't be inserted in the QObject child-parent hierarchy,
1186 // because due to memory constraints they will be deleted as soon 1191 // because due to memory constraints they will be deleted as soon
1187 // as possible - that is right after they have been processed 1192 // as possible - that is right after they have been processed
1188 // by emit() [ see below ] 1193 // by emit() [ see below ]
1189 //TODO: make gathering statistics optional, because it takes time 1194 //TODO: make gathering statistics optional, because it takes time
1190 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); 1195 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
1191 #ifndef NODEBUG 1196 odebug << "OPacket::dumpStructure: " << p->dumpStructure() << oendl;
1192 p->dumpStructure( const_cast<QObjectList*>( p->children() ) );
1193 #endif
1194 return p; 1197 return p;
1195 } 1198 }
1196 else 1199 else
1197 { 1200 {
1198 owarn << "OPacketCapturer::next() - no packet received!" << oendl; 1201 owarn << "OPacketCapturer::next() - no packet received!" << oendl;
1199 return 0; 1202 return 0;
1200 } 1203 }
1201} 1204}
1202 1205
1203 1206
1204bool OPacketCapturer::open( const QString& name ) 1207bool OPacketCapturer::open( const QString& name )
1205{ 1208{
@@ -1329,16 +1332,16 @@ int OPacketCapturer::snapShot() const
1329 return pcap_snapshot( _pch ); 1332 return pcap_snapshot( _pch );
1330} 1333}
1331 1334
1332 1335
1333bool OPacketCapturer::swapped() const 1336bool OPacketCapturer::swapped() const
1334{ 1337{
1335 return pcap_is_swapped( _pch ); 1338 return pcap_is_swapped( _pch );
1336} 1339}
1337 1340
1338 1341
1339QString OPacketCapturer::version() const 1342QString OPacketCapturer::version() const
1340{ 1343{
1341 return QString().sprintf( "%s.%s", pcap_major_version( _pch ), pcap_minor_version( _pch ) ); 1344 return QString().sprintf( "%d.%d", pcap_major_version( _pch ), pcap_minor_version( _pch ) );
1342} 1345}
1343 1346
1344 1347