-rw-r--r-- | libopie2/opienet/opcap.cpp | 253 |
1 files changed, 225 insertions, 28 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 48f874f..913d42e 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -50,13 +50,16 @@ OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject* | |||
50 | qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); | 50 | qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); |
51 | 51 | ||
52 | _end = (unsigned char*) data + header.len; | ||
53 | qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); | ||
54 | |||
52 | if ( packetCapturer()->dataLink() == DLT_EN10MB ) | 55 | if ( packetCapturer()->dataLink() == DLT_EN10MB ) |
53 | { | 56 | { |
54 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); | 57 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); |
55 | new OEthernetPacket( (const struct ether_header*) data, this ); | 58 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); |
56 | } | 59 | } |
57 | else | 60 | else |
58 | { | 61 | { |
59 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); | 62 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); |
60 | new OWaveLanPacket( (const struct ieee_802_11_header*) data, this ); | 63 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); |
61 | } | 64 | } |
62 | } | 65 | } |
@@ -110,5 +113,5 @@ int OPacket::len() const | |||
110 | *======================================================================================*/ | 113 | *======================================================================================*/ |
111 | 114 | ||
112 | OEthernetPacket::OEthernetPacket( const struct ether_header* data, QObject* parent ) | 115 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
113 | :QObject( parent, "Ethernet" ), _ether( data ) | 116 | :QObject( parent, "Ethernet" ), _ether( data ) |
114 | 117 | ||
@@ -125,5 +128,5 @@ OEthernetPacket::OEthernetPacket( const struct ether_header* data, QObject* pare | |||
125 | switch ( type() ) | 128 | switch ( type() ) |
126 | { | 129 | { |
127 | case ETHERTYPE_IP: new OIPPacket( (const struct iphdr*) (data+1), this ); break; | 130 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
128 | case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } | 131 | case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } |
129 | case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } | 132 | case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } |
@@ -161,5 +164,5 @@ int OEthernetPacket::type() const | |||
161 | 164 | ||
162 | 165 | ||
163 | OIPPacket::OIPPacket( const struct iphdr* data, QObject* parent ) | 166 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) |
164 | :QObject( parent, "IP" ), _iphdr( data ) | 167 | :QObject( parent, "IP" ), _iphdr( data ) |
165 | 168 | ||
@@ -175,6 +178,6 @@ OIPPacket::OIPPacket( const struct iphdr* data, QObject* parent ) | |||
175 | switch ( protocol() ) | 178 | switch ( protocol() ) |
176 | { | 179 | { |
177 | case IPPROTO_UDP: new OUDPPacket( (const struct udphdr*) (data+1), this ); break; | 180 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
178 | case IPPROTO_TCP: new OTCPPacket( (const struct tcphdr*) (data+1), this ); break; | 181 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
179 | default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); | 182 | default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); |
180 | } | 183 | } |
@@ -245,5 +248,5 @@ int OIPPacket::checksum() const | |||
245 | 248 | ||
246 | 249 | ||
247 | OUDPPacket::OUDPPacket( const struct udphdr* data, QObject* parent ) | 250 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) |
248 | :QObject( parent, "UDP" ), _udphdr( data ) | 251 | :QObject( parent, "UDP" ), _udphdr( data ) |
249 | 252 | ||
@@ -262,5 +265,5 @@ OUDPPacket::~OUDPPacket() | |||
262 | 265 | ||
263 | 266 | ||
264 | OTCPPacket::OTCPPacket( const struct tcphdr* data, QObject* parent ) | 267 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) |
265 | :QObject( parent, "TCP" ), _tcphdr( data ) | 268 | :QObject( parent, "TCP" ), _tcphdr( data ) |
266 | 269 | ||
@@ -279,5 +282,5 @@ OTCPPacket::~OTCPPacket() | |||
279 | 282 | ||
280 | 283 | ||
281 | OWaveLanPacket::OWaveLanPacket( const struct ieee_802_11_header* data, QObject* parent ) | 284 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) |
282 | :QObject( parent, "802.11" ), _wlanhdr( data ) | 285 | :QObject( parent, "802.11" ), _wlanhdr( data ) |
283 | 286 | ||
@@ -296,7 +299,7 @@ OWaveLanPacket::OWaveLanPacket( const struct ieee_802_11_header* data, QObject* | |||
296 | switch ( type() ) | 299 | switch ( type() ) |
297 | { | 300 | { |
298 | case T_MGMT: new OWaveLanManagementPacket( (const struct ieee_802_11_mgmt_header*) data, this ); break; | 301 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
299 | case T_DATA: new OWaveLanDataPacket( (const struct ieee_802_11_data_header*) data, this ); break; | 302 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
300 | //case T_CTRL: new OWaveLanControlPacket( (const struct ieee_802_11_ctrl_header*) data, this ); break; | 303 | //case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_ctrl_header*) data, this ); break; |
301 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown type!" ); | 304 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown type!" ); |
302 | } | 305 | } |
@@ -384,5 +387,5 @@ bool OWaveLanPacket::usesWep() const | |||
384 | *======================================================================================*/ | 387 | *======================================================================================*/ |
385 | 388 | ||
386 | OWaveLanManagementPacket::OWaveLanManagementPacket( const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) | 389 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) |
387 | :QObject( parent, "802.11 Management" ), _header( data ), | 390 | :QObject( parent, "802.11 Management" ), _header( data ), |
388 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) | 391 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) |
@@ -394,8 +397,25 @@ OWaveLanManagementPacket::OWaveLanManagementPacket( const struct ieee_802_11_mgm | |||
394 | case ST_BEACON: | 397 | case ST_BEACON: |
395 | { | 398 | { |
396 | qDebug( "TYPE: BEACON FRAME" ); | 399 | // nice, received a beacon... |
397 | qDebug( "ESSID: %s", (const char*) SSID() ); | 400 | } |
398 | break; | 401 | } |
402 | |||
403 | // grab tagged values | ||
404 | const unsigned char* ptr = (const unsigned char*) (_body+1); | ||
405 | while (ptr < end) | ||
406 | { | ||
407 | switch ( *ptr ) | ||
408 | { | ||
409 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; | ||
410 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; | ||
411 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; | ||
412 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; | ||
413 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; | ||
414 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; | ||
415 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; | ||
416 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; | ||
399 | } | 417 | } |
418 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value | ||
419 | ptr+= 2; // skip tag ID and length | ||
400 | } | 420 | } |
401 | } | 421 | } |
@@ -407,10 +427,68 @@ OWaveLanManagementPacket::~OWaveLanManagementPacket() | |||
407 | 427 | ||
408 | 428 | ||
409 | QString OWaveLanManagementPacket::SSID() const | 429 | int OWaveLanManagementPacket::beaconInterval() const |
430 | { | ||
431 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); | ||
432 | } | ||
433 | |||
434 | |||
435 | int OWaveLanManagementPacket::capabilities() const | ||
436 | { | ||
437 | return EXTRACT_LE_16BITS( &_body->capability_info ); | ||
438 | } | ||
439 | |||
440 | |||
441 | bool OWaveLanManagementPacket::canESS() const | ||
410 | { | 442 | { |
411 | int length = _body->ssid.length; | 443 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
444 | } | ||
445 | |||
446 | |||
447 | bool OWaveLanManagementPacket::canIBSS() const | ||
448 | { | ||
449 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | ||
450 | } | ||
451 | |||
452 | |||
453 | bool OWaveLanManagementPacket::canCFP() const | ||
454 | { | ||
455 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); | ||
456 | } | ||
457 | |||
458 | |||
459 | bool OWaveLanManagementPacket::canCFP_REQ() const | ||
460 | { | ||
461 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); | ||
462 | } | ||
463 | |||
464 | |||
465 | bool OWaveLanManagementPacket::canPrivacy() const | ||
466 | { | ||
467 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); | ||
468 | } | ||
469 | |||
470 | |||
471 | /*====================================================================================== | ||
472 | * OWaveLanManagementSSID | ||
473 | *======================================================================================*/ | ||
474 | |||
475 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) | ||
476 | :QObject( parent, "802.11 SSID" ), _data( data ) | ||
477 | { | ||
478 | qDebug( "OWaveLanManagementSSID()" ); | ||
479 | } | ||
480 | |||
481 | |||
482 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | ||
483 | { | ||
484 | } | ||
485 | |||
486 | |||
487 | QString OWaveLanManagementSSID::ID() const | ||
488 | { | ||
489 | int length = _data->length; | ||
412 | if ( length > 32 ) length = 32; | 490 | if ( length > 32 ) length = 32; |
413 | char essid[length+1]; | 491 | char essid[length+1]; |
414 | memcpy( &essid, _body->ssid.ssid, length ); | 492 | memcpy( &essid, &_data->ssid, length ); |
415 | essid[length] = 0x0; | 493 | essid[length] = 0x0; |
416 | return essid; | 494 | return essid; |
@@ -419,8 +497,119 @@ QString OWaveLanManagementPacket::SSID() const | |||
419 | 497 | ||
420 | /*====================================================================================== | 498 | /*====================================================================================== |
499 | * OWaveLanManagementRates | ||
500 | *======================================================================================*/ | ||
501 | |||
502 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) | ||
503 | :QObject( parent, "802.11 Rates" ), _data( data ) | ||
504 | { | ||
505 | qDebug( "OWaveLanManagementRates()" ); | ||
506 | } | ||
507 | |||
508 | |||
509 | OWaveLanManagementRates::~OWaveLanManagementRates() | ||
510 | { | ||
511 | } | ||
512 | |||
513 | /*====================================================================================== | ||
514 | * OWaveLanManagementCF | ||
515 | *======================================================================================*/ | ||
516 | |||
517 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) | ||
518 | :QObject( parent, "802.11 CF" ), _data( data ) | ||
519 | { | ||
520 | qDebug( "OWaveLanManagementCF()" ); | ||
521 | } | ||
522 | |||
523 | |||
524 | OWaveLanManagementCF::~OWaveLanManagementCF() | ||
525 | { | ||
526 | } | ||
527 | |||
528 | /*====================================================================================== | ||
529 | * OWaveLanManagementFH | ||
530 | *======================================================================================*/ | ||
531 | |||
532 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) | ||
533 | :QObject( parent, "802.11 FH" ), _data( data ) | ||
534 | { | ||
535 | qDebug( "OWaveLanManagementFH()" ); | ||
536 | } | ||
537 | |||
538 | |||
539 | OWaveLanManagementFH::~OWaveLanManagementFH() | ||
540 | { | ||
541 | } | ||
542 | |||
543 | /*====================================================================================== | ||
544 | * OWaveLanManagementDS | ||
545 | *======================================================================================*/ | ||
546 | |||
547 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) | ||
548 | :QObject( parent, "802.11 DS" ), _data( data ) | ||
549 | { | ||
550 | qDebug( "OWaveLanManagementDS()" ); | ||
551 | } | ||
552 | |||
553 | |||
554 | OWaveLanManagementDS::~OWaveLanManagementDS() | ||
555 | { | ||
556 | } | ||
557 | |||
558 | |||
559 | int OWaveLanManagementDS::channel() const | ||
560 | { | ||
561 | return _data->channel; | ||
562 | } | ||
563 | |||
564 | /*====================================================================================== | ||
565 | * OWaveLanManagementTim | ||
566 | *======================================================================================*/ | ||
567 | |||
568 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) | ||
569 | :QObject( parent, "802.11 Tim" ), _data( data ) | ||
570 | { | ||
571 | qDebug( "OWaveLanManagementTim()" ); | ||
572 | } | ||
573 | |||
574 | |||
575 | OWaveLanManagementTim::~OWaveLanManagementTim() | ||
576 | { | ||
577 | } | ||
578 | |||
579 | /*====================================================================================== | ||
580 | * OWaveLanManagementIBSS | ||
581 | *======================================================================================*/ | ||
582 | |||
583 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) | ||
584 | :QObject( parent, "802.11 IBSS" ), _data( data ) | ||
585 | { | ||
586 | qDebug( "OWaveLanManagementIBSS()" ); | ||
587 | } | ||
588 | |||
589 | |||
590 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | ||
591 | { | ||
592 | } | ||
593 | |||
594 | /*====================================================================================== | ||
595 | * OWaveLanManagementChallenge | ||
596 | *======================================================================================*/ | ||
597 | |||
598 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) | ||
599 | :QObject( parent, "802.11 Challenge" ), _data( data ) | ||
600 | { | ||
601 | qDebug( "OWaveLanManagementChallenge()" ); | ||
602 | } | ||
603 | |||
604 | |||
605 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | ||
606 | { | ||
607 | } | ||
608 | |||
609 | /*====================================================================================== | ||
421 | * OWaveLanDataPacket | 610 | * OWaveLanDataPacket |
422 | *======================================================================================*/ | 611 | *======================================================================================*/ |
423 | 612 | ||
424 | OWaveLanDataPacket::OWaveLanDataPacket( const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) | 613 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) |
425 | :QObject( parent, "802.11 Data" ), _header( data ) | 614 | :QObject( parent, "802.11 Data" ), _header( data ) |
426 | { | 615 | { |
@@ -432,5 +621,5 @@ OWaveLanDataPacket::OWaveLanDataPacket( const struct ieee_802_11_data_header* da | |||
432 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | 621 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address |
433 | 622 | ||
434 | new OLLCPacket( (const struct ieee_802_11_802_2_header*) payload, this ); | 623 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); |
435 | } | 624 | } |
436 | 625 | ||
@@ -445,5 +634,5 @@ OWaveLanDataPacket::~OWaveLanDataPacket() | |||
445 | *======================================================================================*/ | 634 | *======================================================================================*/ |
446 | 635 | ||
447 | OLLCPacket::OLLCPacket( const struct ieee_802_11_802_2_header* data, QObject* parent ) | 636 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) |
448 | :QObject( parent, "802.11 802_2" ), _header( data ) | 637 | :QObject( parent, "802.11 802_2" ), _header( data ) |
449 | { | 638 | { |
@@ -456,5 +645,5 @@ OLLCPacket::OLLCPacket( const struct ieee_802_11_802_2_header* data, QObject* pa | |||
456 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h | 645 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h |
457 | { | 646 | { |
458 | case ETH_P_IP: new OIPPacket( (const struct iphdr*) (data+1), this ); break; | 647 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
459 | default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); | 648 | default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); |
460 | } | 649 | } |
@@ -474,5 +663,5 @@ OLLCPacket::~OLLCPacket() | |||
474 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | 663 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) |
475 | :QObject( parent, name ), _name( QString::null ), _open( false ), | 664 | :QObject( parent, name ), _name( QString::null ), _open( false ), |
476 | _pch( 0 ) | 665 | _pch( 0 ), _sn( 0 ) |
477 | { | 666 | { |
478 | } | 667 | } |
@@ -518,4 +707,9 @@ void OPacketCapturer::close() | |||
518 | if ( _open ) | 707 | if ( _open ) |
519 | { | 708 | { |
709 | if ( _sn ) | ||
710 | { | ||
711 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | ||
712 | delete _sn; | ||
713 | } | ||
520 | pcap_close( _pch ); | 714 | pcap_close( _pch ); |
521 | _open = false; | 715 | _open = false; |
@@ -546,5 +740,8 @@ OPacket* OPacketCapturer::next() | |||
546 | { | 740 | { |
547 | packetheaderstruct header; | 741 | packetheaderstruct header; |
742 | qDebug( "==> OPacketCapturer::next()" ); | ||
548 | const unsigned char* pdata = pcap_next( _pch, &header ); | 743 | const unsigned char* pdata = pcap_next( _pch, &header ); |
744 | qDebug( "<== OPacketCapturer::next()" ); | ||
745 | |||
549 | if ( header.len ) | 746 | if ( header.len ) |
550 | return new OPacket( header, pdata, this ); | 747 | return new OPacket( header, pdata, this ); |
@@ -578,9 +775,9 @@ bool OPacketCapturer::open( const QString& name ) | |||
578 | _open = true; | 775 | _open = true; |
579 | 776 | ||
580 | // in case we have a qapp, create a socket notifier | 777 | // in case we have an application object, create a socket notifier |
581 | if ( qApp ) | 778 | if ( qApp ) |
582 | { | 779 | { |
583 | QSocketNotifier* sn = new QSocketNotifier( fileno(), QSocketNotifier::Read, this ); | 780 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
584 | connect( sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 781 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
585 | } | 782 | } |
586 | 783 | ||