-rw-r--r-- | libopie2/opienet/opcap.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index f6d05ea..523be3e 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -553,505 +553,505 @@ QString OWaveLanManagementPacket::managementType() const | |||
553 | { | 553 | { |
554 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; | 554 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; |
555 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; | 555 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; |
556 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; | 556 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; |
557 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; | 557 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; |
558 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; | 558 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; |
559 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; | 559 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; |
560 | case ST_BEACON: return "Beacon"; break; | 560 | case ST_BEACON: return "Beacon"; break; |
561 | case ST_ATIM: return "Atim"; break; | 561 | case ST_ATIM: return "Atim"; break; |
562 | case ST_DISASSOC: return "Disassociation"; break; | 562 | case ST_DISASSOC: return "Disassociation"; break; |
563 | case ST_AUTH: return "Authentication"; break; | 563 | case ST_AUTH: return "Authentication"; break; |
564 | case ST_DEAUTH: return "Deathentication"; break; | 564 | case ST_DEAUTH: return "Deathentication"; break; |
565 | default: | 565 | default: |
566 | qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); | 566 | qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); |
567 | return "Unknown"; | 567 | return "Unknown"; |
568 | } | 568 | } |
569 | } | 569 | } |
570 | 570 | ||
571 | 571 | ||
572 | int OWaveLanManagementPacket::beaconInterval() const | 572 | int OWaveLanManagementPacket::beaconInterval() const |
573 | { | 573 | { |
574 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); | 574 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); |
575 | } | 575 | } |
576 | 576 | ||
577 | 577 | ||
578 | int OWaveLanManagementPacket::capabilities() const | 578 | int OWaveLanManagementPacket::capabilities() const |
579 | { | 579 | { |
580 | return EXTRACT_LE_16BITS( &_body->capability_info ); | 580 | return EXTRACT_LE_16BITS( &_body->capability_info ); |
581 | } | 581 | } |
582 | 582 | ||
583 | 583 | ||
584 | bool OWaveLanManagementPacket::canESS() const | 584 | bool OWaveLanManagementPacket::canESS() const |
585 | { | 585 | { |
586 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 586 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
587 | } | 587 | } |
588 | 588 | ||
589 | 589 | ||
590 | bool OWaveLanManagementPacket::canIBSS() const | 590 | bool OWaveLanManagementPacket::canIBSS() const |
591 | { | 591 | { |
592 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 592 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
593 | } | 593 | } |
594 | 594 | ||
595 | 595 | ||
596 | bool OWaveLanManagementPacket::canCFP() const | 596 | bool OWaveLanManagementPacket::canCFP() const |
597 | { | 597 | { |
598 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 598 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
599 | } | 599 | } |
600 | 600 | ||
601 | 601 | ||
602 | bool OWaveLanManagementPacket::canCFP_REQ() const | 602 | bool OWaveLanManagementPacket::canCFP_REQ() const |
603 | { | 603 | { |
604 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 604 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
605 | } | 605 | } |
606 | 606 | ||
607 | 607 | ||
608 | bool OWaveLanManagementPacket::canPrivacy() const | 608 | bool OWaveLanManagementPacket::canPrivacy() const |
609 | { | 609 | { |
610 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 610 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
611 | } | 611 | } |
612 | 612 | ||
613 | 613 | ||
614 | /*====================================================================================== | 614 | /*====================================================================================== |
615 | * OWaveLanManagementSSID | 615 | * OWaveLanManagementSSID |
616 | *======================================================================================*/ | 616 | *======================================================================================*/ |
617 | 617 | ||
618 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) | 618 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) |
619 | :QObject( parent, "802.11 SSID" ), _data( data ) | 619 | :QObject( parent, "802.11 SSID" ), _data( data ) |
620 | { | 620 | { |
621 | qDebug( "OWaveLanManagementSSID()" ); | 621 | qDebug( "OWaveLanManagementSSID()" ); |
622 | } | 622 | } |
623 | 623 | ||
624 | 624 | ||
625 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | 625 | OWaveLanManagementSSID::~OWaveLanManagementSSID() |
626 | { | 626 | { |
627 | } | 627 | } |
628 | 628 | ||
629 | 629 | ||
630 | QString OWaveLanManagementSSID::ID() const | 630 | QString OWaveLanManagementSSID::ID() const |
631 | { | 631 | { |
632 | int length = _data->length; | 632 | int length = _data->length; |
633 | if ( length > 32 ) length = 32; | 633 | if ( length > 32 ) length = 32; |
634 | char essid[length+1]; | 634 | char essid[length+1]; |
635 | memcpy( &essid, &_data->ssid, length ); | 635 | memcpy( &essid, &_data->ssid, length ); |
636 | essid[length] = 0x0; | 636 | essid[length] = 0x0; |
637 | return essid; | 637 | return essid; |
638 | } | 638 | } |
639 | 639 | ||
640 | 640 | ||
641 | /*====================================================================================== | 641 | /*====================================================================================== |
642 | * OWaveLanManagementRates | 642 | * OWaveLanManagementRates |
643 | *======================================================================================*/ | 643 | *======================================================================================*/ |
644 | 644 | ||
645 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) | 645 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) |
646 | :QObject( parent, "802.11 Rates" ), _data( data ) | 646 | :QObject( parent, "802.11 Rates" ), _data( data ) |
647 | { | 647 | { |
648 | qDebug( "OWaveLanManagementRates()" ); | 648 | qDebug( "OWaveLanManagementRates()" ); |
649 | } | 649 | } |
650 | 650 | ||
651 | 651 | ||
652 | OWaveLanManagementRates::~OWaveLanManagementRates() | 652 | OWaveLanManagementRates::~OWaveLanManagementRates() |
653 | { | 653 | { |
654 | } | 654 | } |
655 | 655 | ||
656 | /*====================================================================================== | 656 | /*====================================================================================== |
657 | * OWaveLanManagementCF | 657 | * OWaveLanManagementCF |
658 | *======================================================================================*/ | 658 | *======================================================================================*/ |
659 | 659 | ||
660 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) | 660 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) |
661 | :QObject( parent, "802.11 CF" ), _data( data ) | 661 | :QObject( parent, "802.11 CF" ), _data( data ) |
662 | { | 662 | { |
663 | qDebug( "OWaveLanManagementCF()" ); | 663 | qDebug( "OWaveLanManagementCF()" ); |
664 | } | 664 | } |
665 | 665 | ||
666 | 666 | ||
667 | OWaveLanManagementCF::~OWaveLanManagementCF() | 667 | OWaveLanManagementCF::~OWaveLanManagementCF() |
668 | { | 668 | { |
669 | } | 669 | } |
670 | 670 | ||
671 | /*====================================================================================== | 671 | /*====================================================================================== |
672 | * OWaveLanManagementFH | 672 | * OWaveLanManagementFH |
673 | *======================================================================================*/ | 673 | *======================================================================================*/ |
674 | 674 | ||
675 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) | 675 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) |
676 | :QObject( parent, "802.11 FH" ), _data( data ) | 676 | :QObject( parent, "802.11 FH" ), _data( data ) |
677 | { | 677 | { |
678 | qDebug( "OWaveLanManagementFH()" ); | 678 | qDebug( "OWaveLanManagementFH()" ); |
679 | } | 679 | } |
680 | 680 | ||
681 | 681 | ||
682 | OWaveLanManagementFH::~OWaveLanManagementFH() | 682 | OWaveLanManagementFH::~OWaveLanManagementFH() |
683 | { | 683 | { |
684 | } | 684 | } |
685 | 685 | ||
686 | /*====================================================================================== | 686 | /*====================================================================================== |
687 | * OWaveLanManagementDS | 687 | * OWaveLanManagementDS |
688 | *======================================================================================*/ | 688 | *======================================================================================*/ |
689 | 689 | ||
690 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) | 690 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) |
691 | :QObject( parent, "802.11 DS" ), _data( data ) | 691 | :QObject( parent, "802.11 DS" ), _data( data ) |
692 | { | 692 | { |
693 | qDebug( "OWaveLanManagementDS()" ); | 693 | qDebug( "OWaveLanManagementDS()" ); |
694 | } | 694 | } |
695 | 695 | ||
696 | 696 | ||
697 | OWaveLanManagementDS::~OWaveLanManagementDS() | 697 | OWaveLanManagementDS::~OWaveLanManagementDS() |
698 | { | 698 | { |
699 | } | 699 | } |
700 | 700 | ||
701 | 701 | ||
702 | int OWaveLanManagementDS::channel() const | 702 | int OWaveLanManagementDS::channel() const |
703 | { | 703 | { |
704 | return _data->channel; | 704 | return _data->channel; |
705 | } | 705 | } |
706 | 706 | ||
707 | /*====================================================================================== | 707 | /*====================================================================================== |
708 | * OWaveLanManagementTim | 708 | * OWaveLanManagementTim |
709 | *======================================================================================*/ | 709 | *======================================================================================*/ |
710 | 710 | ||
711 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) | 711 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) |
712 | :QObject( parent, "802.11 Tim" ), _data( data ) | 712 | :QObject( parent, "802.11 Tim" ), _data( data ) |
713 | { | 713 | { |
714 | qDebug( "OWaveLanManagementTim()" ); | 714 | qDebug( "OWaveLanManagementTim()" ); |
715 | } | 715 | } |
716 | 716 | ||
717 | 717 | ||
718 | OWaveLanManagementTim::~OWaveLanManagementTim() | 718 | OWaveLanManagementTim::~OWaveLanManagementTim() |
719 | { | 719 | { |
720 | } | 720 | } |
721 | 721 | ||
722 | /*====================================================================================== | 722 | /*====================================================================================== |
723 | * OWaveLanManagementIBSS | 723 | * OWaveLanManagementIBSS |
724 | *======================================================================================*/ | 724 | *======================================================================================*/ |
725 | 725 | ||
726 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) | 726 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) |
727 | :QObject( parent, "802.11 IBSS" ), _data( data ) | 727 | :QObject( parent, "802.11 IBSS" ), _data( data ) |
728 | { | 728 | { |
729 | qDebug( "OWaveLanManagementIBSS()" ); | 729 | qDebug( "OWaveLanManagementIBSS()" ); |
730 | } | 730 | } |
731 | 731 | ||
732 | 732 | ||
733 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | 733 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() |
734 | { | 734 | { |
735 | } | 735 | } |
736 | 736 | ||
737 | /*====================================================================================== | 737 | /*====================================================================================== |
738 | * OWaveLanManagementChallenge | 738 | * OWaveLanManagementChallenge |
739 | *======================================================================================*/ | 739 | *======================================================================================*/ |
740 | 740 | ||
741 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) | 741 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) |
742 | :QObject( parent, "802.11 Challenge" ), _data( data ) | 742 | :QObject( parent, "802.11 Challenge" ), _data( data ) |
743 | { | 743 | { |
744 | qDebug( "OWaveLanManagementChallenge()" ); | 744 | qDebug( "OWaveLanManagementChallenge()" ); |
745 | } | 745 | } |
746 | 746 | ||
747 | 747 | ||
748 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | 748 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() |
749 | { | 749 | { |
750 | } | 750 | } |
751 | 751 | ||
752 | /*====================================================================================== | 752 | /*====================================================================================== |
753 | * OWaveLanDataPacket | 753 | * OWaveLanDataPacket |
754 | *======================================================================================*/ | 754 | *======================================================================================*/ |
755 | 755 | ||
756 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) | 756 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) |
757 | :QObject( parent, "802.11 Data" ), _header( data ) | 757 | :QObject( parent, "802.11 Data" ), _header( data ) |
758 | { | 758 | { |
759 | qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); | 759 | qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); |
760 | 760 | ||
761 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); | 761 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); |
762 | 762 | ||
763 | #warning The next line works for most cases, but can not be correct generally! | 763 | #warning The next line works for most cases, but can not be correct generally! |
764 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | 764 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address |
765 | 765 | ||
766 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); | 766 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); |
767 | } | 767 | } |
768 | 768 | ||
769 | 769 | ||
770 | OWaveLanDataPacket::~OWaveLanDataPacket() | 770 | OWaveLanDataPacket::~OWaveLanDataPacket() |
771 | { | 771 | { |
772 | } | 772 | } |
773 | 773 | ||
774 | 774 | ||
775 | /*====================================================================================== | 775 | /*====================================================================================== |
776 | * OLLCPacket | 776 | * OLLCPacket |
777 | *======================================================================================*/ | 777 | *======================================================================================*/ |
778 | 778 | ||
779 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) | 779 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) |
780 | :QObject( parent, "802.11 LLC" ), _header( data ) | 780 | :QObject( parent, "802.11 LLC" ), _header( data ) |
781 | { | 781 | { |
782 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); | 782 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); |
783 | 783 | ||
784 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) | 784 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) |
785 | { | 785 | { |
786 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); | 786 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); |
787 | 787 | ||
788 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h | 788 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h |
789 | { | 789 | { |
790 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 790 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
791 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 791 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
792 | default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) ); | 792 | default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) ); |
793 | } | 793 | } |
794 | 794 | ||
795 | } | 795 | } |
796 | } | 796 | } |
797 | 797 | ||
798 | 798 | ||
799 | OLLCPacket::~OLLCPacket() | 799 | OLLCPacket::~OLLCPacket() |
800 | { | 800 | { |
801 | } | 801 | } |
802 | 802 | ||
803 | 803 | ||
804 | /*====================================================================================== | 804 | /*====================================================================================== |
805 | * OWaveLanControlPacket | 805 | * OWaveLanControlPacket |
806 | *======================================================================================*/ | 806 | *======================================================================================*/ |
807 | 807 | ||
808 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) | 808 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) |
809 | :QObject( parent, "802.11 Data" ), _header( data ) | 809 | :QObject( parent, "802.11 Control" ), _header( data ) |
810 | { | 810 | { |
811 | qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); | 811 | qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); |
812 | //TODO: Implement this | 812 | //TODO: Implement this |
813 | } | 813 | } |
814 | 814 | ||
815 | 815 | ||
816 | OWaveLanControlPacket::~OWaveLanControlPacket() | 816 | OWaveLanControlPacket::~OWaveLanControlPacket() |
817 | { | 817 | { |
818 | } | 818 | } |
819 | 819 | ||
820 | 820 | ||
821 | /*====================================================================================== | 821 | /*====================================================================================== |
822 | * OPacketCapturer | 822 | * OPacketCapturer |
823 | *======================================================================================*/ | 823 | *======================================================================================*/ |
824 | 824 | ||
825 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | 825 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) |
826 | :QObject( parent, name ), _name( QString::null ), _open( false ), | 826 | :QObject( parent, name ), _name( QString::null ), _open( false ), |
827 | _pch( 0 ), _pcd( 0 ), _sn( 0 ) | 827 | _pch( 0 ), _pcd( 0 ), _sn( 0 ) |
828 | { | 828 | { |
829 | } | 829 | } |
830 | 830 | ||
831 | 831 | ||
832 | OPacketCapturer::~OPacketCapturer() | 832 | OPacketCapturer::~OPacketCapturer() |
833 | { | 833 | { |
834 | if ( _open ) | 834 | if ( _open ) |
835 | { | 835 | { |
836 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); | 836 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); |
837 | close(); | 837 | close(); |
838 | } | 838 | } |
839 | } | 839 | } |
840 | 840 | ||
841 | 841 | ||
842 | void OPacketCapturer::setBlocking( bool b ) | 842 | void OPacketCapturer::setBlocking( bool b ) |
843 | { | 843 | { |
844 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) | 844 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) |
845 | { | 845 | { |
846 | qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); | 846 | qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); |
847 | } | 847 | } |
848 | else | 848 | else |
849 | { | 849 | { |
850 | qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); | 850 | qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); |
851 | } | 851 | } |
852 | } | 852 | } |
853 | 853 | ||
854 | 854 | ||
855 | bool OPacketCapturer::blocking() const | 855 | bool OPacketCapturer::blocking() const |
856 | { | 856 | { |
857 | int b = pcap_getnonblock( _pch, _errbuf ); | 857 | int b = pcap_getnonblock( _pch, _errbuf ); |
858 | if ( b == -1 ) | 858 | if ( b == -1 ) |
859 | { | 859 | { |
860 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); | 860 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); |
861 | return -1; | 861 | return -1; |
862 | } | 862 | } |
863 | return !b; | 863 | return !b; |
864 | } | 864 | } |
865 | 865 | ||
866 | 866 | ||
867 | void OPacketCapturer::close() | 867 | void OPacketCapturer::close() |
868 | { | 868 | { |
869 | if ( _open ) | 869 | if ( _open ) |
870 | { | 870 | { |
871 | if ( _sn ) | 871 | if ( _sn ) |
872 | { | 872 | { |
873 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 873 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
874 | delete _sn; | 874 | delete _sn; |
875 | } | 875 | } |
876 | if ( _pcd ) | 876 | if ( _pcd ) |
877 | { | 877 | { |
878 | pcap_dump_close( _pcd ); | 878 | pcap_dump_close( _pcd ); |
879 | _pcd = 0; | 879 | _pcd = 0; |
880 | } | 880 | } |
881 | pcap_close( _pch ); | 881 | pcap_close( _pch ); |
882 | _open = false; | 882 | _open = false; |
883 | } | 883 | } |
884 | 884 | ||
885 | qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); | 885 | qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); |
886 | qDebug( "--------------------------------------------------" ); | 886 | qDebug( "--------------------------------------------------" ); |
887 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) | 887 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) |
888 | qDebug( "%s : %d", (const char*) it.key(), it.data() ); | 888 | qDebug( "%s : %d", (const char*) it.key(), it.data() ); |
889 | qDebug( "--------------------------------------------------" ); | 889 | qDebug( "--------------------------------------------------" ); |
890 | 890 | ||
891 | } | 891 | } |
892 | 892 | ||
893 | 893 | ||
894 | int OPacketCapturer::dataLink() const | 894 | int OPacketCapturer::dataLink() const |
895 | { | 895 | { |
896 | return pcap_datalink( _pch ); | 896 | return pcap_datalink( _pch ); |
897 | } | 897 | } |
898 | 898 | ||
899 | 899 | ||
900 | int OPacketCapturer::fileno() const | 900 | int OPacketCapturer::fileno() const |
901 | { | 901 | { |
902 | if ( _open ) | 902 | if ( _open ) |
903 | { | 903 | { |
904 | return pcap_fileno( _pch ); | 904 | return pcap_fileno( _pch ); |
905 | } | 905 | } |
906 | else | 906 | else |
907 | { | 907 | { |
908 | return -1; | 908 | return -1; |
909 | } | 909 | } |
910 | } | 910 | } |
911 | 911 | ||
912 | OPacket* OPacketCapturer::next() | 912 | OPacket* OPacketCapturer::next() |
913 | { | 913 | { |
914 | packetheaderstruct header; | 914 | packetheaderstruct header; |
915 | qDebug( "==> OPacketCapturer::next()" ); | 915 | qDebug( "==> OPacketCapturer::next()" ); |
916 | const unsigned char* pdata = pcap_next( _pch, &header ); | 916 | const unsigned char* pdata = pcap_next( _pch, &header ); |
917 | qDebug( "<== OPacketCapturer::next()" ); | 917 | qDebug( "<== OPacketCapturer::next()" ); |
918 | if ( _pcd ) | 918 | if ( _pcd ) |
919 | pcap_dump( (u_char*) _pcd, &header, pdata ); | 919 | pcap_dump( (u_char*) _pcd, &header, pdata ); |
920 | 920 | ||
921 | if ( pdata && header.len ) | 921 | if ( pdata && header.len ) |
922 | { | 922 | { |
923 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); | 923 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); |
924 | // packets shouldn't be inserted in the QObject child-parent hierarchy, | 924 | // packets shouldn't be inserted in the QObject child-parent hierarchy, |
925 | // because due to memory constraints they will be deleted as soon | 925 | // because due to memory constraints they will be deleted as soon |
926 | // as possible - that is right after they have been processed | 926 | // as possible - that is right after they have been processed |
927 | // by emit() [ see below ] | 927 | // by emit() [ see below ] |
928 | //TODO: make gathering statistics optional, because it takes time | 928 | //TODO: make gathering statistics optional, because it takes time |
929 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); | 929 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); |
930 | 930 | ||
931 | return p; | 931 | return p; |
932 | } | 932 | } |
933 | else | 933 | else |
934 | { | 934 | { |
935 | qWarning( "OPacketCapturer::next() - no packet received!" ); | 935 | qWarning( "OPacketCapturer::next() - no packet received!" ); |
936 | return 0; | 936 | return 0; |
937 | } | 937 | } |
938 | } | 938 | } |
939 | 939 | ||
940 | 940 | ||
941 | bool OPacketCapturer::open( const QString& name, const QString& filename ) | 941 | bool OPacketCapturer::open( const QString& name, const QString& filename ) |
942 | { | 942 | { |
943 | if ( _open ) | 943 | if ( _open ) |
944 | { | 944 | { |
945 | if ( name == _name ) // ignore opening an already openend device | 945 | if ( name == _name ) // ignore opening an already openend device |
946 | { | 946 | { |
947 | return true; | 947 | return true; |
948 | } | 948 | } |
949 | else // close the last opened device | 949 | else // close the last opened device |
950 | { | 950 | { |
951 | close(); | 951 | close(); |
952 | } | 952 | } |
953 | } | 953 | } |
954 | 954 | ||
955 | _name = name; | 955 | _name = name; |
956 | 956 | ||
957 | // open libpcap | 957 | // open libpcap |
958 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); | 958 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); |
959 | 959 | ||
960 | if ( !handle ) | 960 | if ( !handle ) |
961 | { | 961 | { |
962 | qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); | 962 | qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); |
963 | return false; | 963 | return false; |
964 | } | 964 | } |
965 | 965 | ||
966 | qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); | 966 | qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); |
967 | _pch = handle; | 967 | _pch = handle; |
968 | _open = true; | 968 | _open = true; |
969 | _stats.clear(); | 969 | _stats.clear(); |
970 | 970 | ||
971 | // in case we have an application object, create a socket notifier | 971 | // in case we have an application object, create a socket notifier |
972 | if ( qApp ) //TODO: I don't like this here... | 972 | if ( qApp ) //TODO: I don't like this here... |
973 | { | 973 | { |
974 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 974 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
975 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 975 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
976 | } | 976 | } |
977 | 977 | ||
978 | // if requested, open a dump | 978 | // if requested, open a dump |
979 | pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); | 979 | pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); |
980 | if ( !dump ) | 980 | if ( !dump ) |
981 | { | 981 | { |
982 | qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); | 982 | qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); |
983 | return false; | 983 | return false; |
984 | } | 984 | } |
985 | qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); | 985 | qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); |
986 | _pcd = dump; | 986 | _pcd = dump; |
987 | 987 | ||
988 | return true; | 988 | return true; |
989 | } | 989 | } |
990 | 990 | ||
991 | 991 | ||
992 | bool OPacketCapturer::open( const QFile& file ) | 992 | bool OPacketCapturer::open( const QFile& file ) |
993 | { | 993 | { |
994 | QString name = file.name(); | 994 | QString name = file.name(); |
995 | 995 | ||
996 | if ( _open ) | 996 | if ( _open ) |
997 | { | 997 | { |
998 | close(); | 998 | close(); |
999 | if ( name == _name ) // ignore opening an already openend device | 999 | if ( name == _name ) // ignore opening an already openend device |
1000 | { | 1000 | { |
1001 | return true; | 1001 | return true; |
1002 | } | 1002 | } |
1003 | else // close the last opened device | 1003 | else // close the last opened device |
1004 | { | 1004 | { |
1005 | close(); | 1005 | close(); |
1006 | } | 1006 | } |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | _name = name; | 1009 | _name = name; |
1010 | 1010 | ||
1011 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); | 1011 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); |
1012 | 1012 | ||
1013 | if ( handle ) | 1013 | if ( handle ) |
1014 | { | 1014 | { |
1015 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); | 1015 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); |
1016 | _pch = handle; | 1016 | _pch = handle; |
1017 | _open = true; | 1017 | _open = true; |
1018 | 1018 | ||
1019 | // in case we have an application object, create a socket notifier | 1019 | // in case we have an application object, create a socket notifier |
1020 | if ( qApp ) | 1020 | if ( qApp ) |
1021 | { | 1021 | { |
1022 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 1022 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
1023 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1023 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1024 | } | 1024 | } |
1025 | 1025 | ||
1026 | return true; | 1026 | return true; |
1027 | } | 1027 | } |
1028 | else | 1028 | else |
1029 | { | 1029 | { |
1030 | qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); | 1030 | qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); |
1031 | return false; | 1031 | return false; |
1032 | } | 1032 | } |
1033 | 1033 | ||
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | 1036 | ||
1037 | bool OPacketCapturer::isOpen() const | 1037 | bool OPacketCapturer::isOpen() const |
1038 | { | 1038 | { |
1039 | return _open; | 1039 | return _open; |
1040 | } | 1040 | } |
1041 | 1041 | ||
1042 | 1042 | ||
1043 | void OPacketCapturer::readyToReceive() | 1043 | void OPacketCapturer::readyToReceive() |
1044 | { | 1044 | { |
1045 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); | 1045 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); |
1046 | OPacket* p = next(); | 1046 | OPacket* p = next(); |
1047 | emit receivedPacket( p ); | 1047 | emit receivedPacket( p ); |
1048 | // emit is synchronous - packet has been dealt with, now it's safe to delete | 1048 | // emit is synchronous - packet has been dealt with, now it's safe to delete |
1049 | delete p; | 1049 | delete p; |
1050 | } | 1050 | } |
1051 | 1051 | ||
1052 | 1052 | ||
1053 | const QMap<QString,int>& OPacketCapturer::statistics() const | 1053 | const QMap<QString,int>& OPacketCapturer::statistics() const |
1054 | { | 1054 | { |
1055 | return _stats; | 1055 | return _stats; |
1056 | } | 1056 | } |
1057 | 1057 | ||