summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp31
-rw-r--r--libopie2/opienet/onetwork.h11
-rw-r--r--libopie2/opienet/opcap.cpp2
3 files changed, 25 insertions, 19 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 2dfff1d..6cef5cf 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -620,389 +620,394 @@ int OWirelessNetworkInterface::channels() const
620 620
621 621
622void OWirelessNetworkInterface::setChannelHopping( int interval ) 622void OWirelessNetworkInterface::setChannelHopping( int interval )
623{ 623{
624 if ( !_hopper ) _hopper = new OChannelHopper( this ); 624 if ( !_hopper ) _hopper = new OChannelHopper( this );
625 _hopper->setInterval( interval ); 625 _hopper->setInterval( interval );
626 //FIXME: When and by whom will the channel hopper be deleted? 626 //FIXME: When and by whom will the channel hopper be deleted?
627 //TODO: rely on QObject hierarchy 627 //TODO: rely on QObject hierarchy
628} 628}
629 629
630 630
631int OWirelessNetworkInterface::channelHopping() const 631int OWirelessNetworkInterface::channelHopping() const
632{ 632{
633 return _hopper->interval(); 633 return _hopper->interval();
634} 634}
635 635
636 636
637OChannelHopper* OWirelessNetworkInterface::channelHopper() const 637OChannelHopper* OWirelessNetworkInterface::channelHopper() const
638{ 638{
639 return _hopper; 639 return _hopper;
640} 640}
641 641
642 642
643void OWirelessNetworkInterface::setMode( const QString& mode ) 643void OWirelessNetworkInterface::setMode( const QString& mode )
644{ 644{
645 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; 645 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO;
646 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; 646 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC;
647 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; 647 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA;
648 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; 648 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER;
649 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; 649 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT;
650 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; 650 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND;
651 #if WIRELESS_EXT > 14 651 #if WIRELESS_EXT > 14
652 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; 652 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR;
653 #endif 653 #endif
654 else 654 else
655 { 655 {
656 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); 656 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode );
657 return; 657 return;
658 } 658 }
659 wioctl( SIOCSIWMODE ); 659 wioctl( SIOCSIWMODE );
660} 660}
661 661
662 662
663QString OWirelessNetworkInterface::mode() const 663QString OWirelessNetworkInterface::mode() const
664{ 664{
665 if ( !wioctl( SIOCGIWMODE ) ) 665 if ( !wioctl( SIOCGIWMODE ) )
666 { 666 {
667 return "<unknown>"; 667 return "<unknown>";
668 } 668 }
669 switch ( _iwr.u.mode ) 669 switch ( _iwr.u.mode )
670 { 670 {
671 case IW_MODE_AUTO: return "auto"; 671 case IW_MODE_AUTO: return "auto";
672 case IW_MODE_ADHOC: return "adhoc"; 672 case IW_MODE_ADHOC: return "adhoc";
673 case IW_MODE_INFRA: return "managed"; 673 case IW_MODE_INFRA: return "managed";
674 case IW_MODE_MASTER: return "master"; 674 case IW_MODE_MASTER: return "master";
675 case IW_MODE_REPEAT: return "repeater"; 675 case IW_MODE_REPEAT: return "repeater";
676 case IW_MODE_SECOND: return "secondary"; 676 case IW_MODE_SECOND: return "secondary";
677 #if WIRELESS_EXT > 14 677 #if WIRELESS_EXT > 14
678 case IW_MODE_MONITOR: return "monitor"; 678 case IW_MODE_MONITOR: return "monitor";
679 #endif 679 #endif
680 default: assert( 0 ); // shouldn't happen 680 default: assert( 0 ); // shouldn't happen
681 } 681 }
682} 682}
683 683
684 684
685void OWirelessNetworkInterface::setMonitorMode( bool b ) 685void OWirelessNetworkInterface::setMonitorMode( bool b )
686{ 686{
687 if ( _mon ) 687 if ( _mon )
688 _mon->setEnabled( b ); 688 _mon->setEnabled( b );
689 else 689 else
690 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 690 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
691} 691}
692 692
693 693
694bool OWirelessNetworkInterface::monitorMode() const 694bool OWirelessNetworkInterface::monitorMode() const
695{ 695{
696 qDebug( "dataLinkType = %d", dataLinkType() ); 696 qDebug( "dataLinkType = %d", dataLinkType() );
697 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); 697 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 );
698 // 802 is the header type for PRISM - Linux support for this is pending... 698 // 802 is the header type for PRISM - Linux support for this is pending...
699} 699}
700 700
701 701
702void OWirelessNetworkInterface::setNickName( const QString& nickname ) 702void OWirelessNetworkInterface::setNickName( const QString& nickname )
703{ 703{
704 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); 704 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
705 _iwr.u.essid.length = nickname.length(); 705 _iwr.u.essid.length = nickname.length();
706 wioctl( SIOCSIWNICKN ); 706 wioctl( SIOCSIWNICKN );
707} 707}
708 708
709 709
710QString OWirelessNetworkInterface::nickName() const 710QString OWirelessNetworkInterface::nickName() const
711{ 711{
712 char str[IW_ESSID_MAX_SIZE]; 712 char str[IW_ESSID_MAX_SIZE];
713 _iwr.u.data.pointer = &str[0]; 713 _iwr.u.data.pointer = &str[0];
714 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 714 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
715 if ( !wioctl( SIOCGIWNICKN ) ) 715 if ( !wioctl( SIOCGIWNICKN ) )
716 { 716 {
717 return "<unknown>"; 717 return "<unknown>";
718 } 718 }
719 else 719 else
720 { 720 {
721 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 721 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
722 return str; 722 return str;
723 } 723 }
724} 724}
725 725
726 726
727void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) 727void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
728{ 728{
729 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); 729 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
730 if ( !priv ) 730 if ( !priv )
731 { 731 {
732 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); 732 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call );
733 return; 733 return;
734 } 734 }
735 if ( priv->numberSetArgs() != numargs ) 735 if ( priv->numberSetArgs() != numargs )
736 { 736 {
737 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); 737 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs );
738 return; 738 return;
739 } 739 }
740 740
741 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); 741 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() );
742 memset( &_iwr, 0, sizeof _iwr ); 742 memset( &_iwr, 0, sizeof _iwr );
743 va_list argp; 743 va_list argp;
744 va_start( argp, numargs ); 744 va_start( argp, numargs );
745 for ( int i = 0; i < numargs; ++i ) 745 for ( int i = 0; i < numargs; ++i )
746 { 746 {
747 priv->setParameter( i, va_arg( argp, int ) ); 747 priv->setParameter( i, va_arg( argp, int ) );
748 } 748 }
749 va_end( argp ); 749 va_end( argp );
750 priv->invoke(); 750 priv->invoke();
751} 751}
752 752
753 753
754void OWirelessNetworkInterface::getPrivate( const QString& call ) 754void OWirelessNetworkInterface::getPrivate( const QString& call )
755{ 755{
756 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); 756 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." );
757} 757}
758 758
759 759
760bool OWirelessNetworkInterface::hasPrivate( const QString& call ) 760bool OWirelessNetworkInterface::hasPrivate( const QString& call )
761{ 761{
762 return child( (const char*) call ); 762 return child( (const char*) call );
763} 763}
764 764
765 765
766QString OWirelessNetworkInterface::SSID() const 766QString OWirelessNetworkInterface::SSID() const
767{ 767{
768 char str[IW_ESSID_MAX_SIZE]; 768 char str[IW_ESSID_MAX_SIZE];
769 _iwr.u.essid.pointer = &str[0]; 769 _iwr.u.essid.pointer = &str[0];
770 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 770 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
771 if ( !wioctl( SIOCGIWESSID ) ) 771 if ( !wioctl( SIOCGIWESSID ) )
772 { 772 {
773 return "<unknown>"; 773 return "<unknown>";
774 } 774 }
775 else 775 else
776 { 776 {
777 return str; 777 return str;
778 } 778 }
779} 779}
780 780
781 781
782void OWirelessNetworkInterface::setSSID( const QString& ssid ) 782void OWirelessNetworkInterface::setSSID( const QString& ssid )
783{ 783{
784 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 784 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
785 _iwr.u.essid.length = ssid.length(); 785 _iwr.u.essid.length = ssid.length();
786 wioctl( SIOCSIWESSID ); 786 wioctl( SIOCSIWESSID );
787} 787}
788 788
789 789
790bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const 790bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
791{ 791{
792 int result = ::ioctl( _sfd, call, &iwreq ); 792 int result = ::ioctl( _sfd, call, &iwreq );
793 if ( result == -1 ) 793 if ( result == -1 )
794 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 794 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
795 else 795 else
796 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); 796 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call );
797 return ( result != -1 ); 797 return ( result != -1 );
798} 798}
799 799
800 800
801bool OWirelessNetworkInterface::wioctl( int call ) const 801bool OWirelessNetworkInterface::wioctl( int call ) const
802{ 802{
803 strcpy( _iwr.ifr_name, name() ); 803 strcpy( _iwr.ifr_name, name() );
804 return wioctl( call, _iwr ); 804 return wioctl( call, _iwr );
805} 805}
806 806
807 807
808/*====================================================================================== 808/*======================================================================================
809 * OMonitoringInterface 809 * OMonitoringInterface
810 *======================================================================================*/ 810 *======================================================================================*/
811 811
812OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) 812OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
813 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ) 813 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader )
814{ 814{
815} 815}
816 816
817 817
818OMonitoringInterface::~OMonitoringInterface() 818OMonitoringInterface::~OMonitoringInterface()
819{ 819{
820} 820}
821 821
822 822
823void OMonitoringInterface::setChannel( int c ) 823void OMonitoringInterface::setChannel( int c )
824{ 824{
825 // use standard WE channel switching protocol 825 // use standard WE channel switching protocol
826 memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); 826 memset( &_if->_iwr, 0, sizeof( struct iwreq ) );
827 _if->_iwr.u.freq.m = c; 827 _if->_iwr.u.freq.m = c;
828 _if->_iwr.u.freq.e = 0; 828 _if->_iwr.u.freq.e = 0;
829 _if->wioctl( SIOCSIWFREQ ); 829 _if->wioctl( SIOCSIWFREQ );
830} 830}
831 831
832 832
833bool OMonitoringInterface::enabled() const 833bool OMonitoringInterface::enabled() const
834{ 834{
835 return _if->monitorMode(); 835 return _if->monitorMode();
836} 836}
837 837
838 838
839void OMonitoringInterface::setEnabled( bool b ) 839void OMonitoringInterface::setEnabled( bool b )
840{ 840{
841} 841}
842 842
843 843
844/*====================================================================================== 844/*======================================================================================
845 * OCiscoMonitoringInterface 845 * OCiscoMonitoringInterface
846 *======================================================================================*/ 846 *======================================================================================*/
847 847
848OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) 848OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
849 :OMonitoringInterface( iface ) 849 :OMonitoringInterface( iface, prismHeader )
850{ 850{
851 iface->setMonitoring( this ); 851 iface->setMonitoring( this );
852} 852}
853 853
854 854
855OCiscoMonitoringInterface::~OCiscoMonitoringInterface() 855OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
856{ 856{
857} 857}
858 858
859 859
860void OCiscoMonitoringInterface::setEnabled( bool b ) 860void OCiscoMonitoringInterface::setEnabled( bool b )
861{ 861{
862 QString fname; 862 QString fname;
863 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); 863 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
864 QFile f( fname ); 864 QFile f( fname );
865 if ( !f.exists() ) return; 865 if ( !f.exists() ) return;
866 866
867 if ( f.open( IO_WriteOnly ) ) 867 if ( f.open( IO_WriteOnly ) )
868 { 868 {
869 QTextStream s( &f ); 869 QTextStream s( &f );
870 s << "Mode: r"; 870 s << "Mode: r";
871 s << "Mode: y"; 871 s << "Mode: y";
872 s << "XmitPower: 1"; 872 s << "XmitPower: 1";
873 } 873 }
874 874
875 // flushing and closing will be done automatically when f goes out of scope 875 // flushing and closing will be done automatically when f goes out of scope
876} 876}
877 877
878 878
879QString OCiscoMonitoringInterface::name() const 879QString OCiscoMonitoringInterface::name() const
880{ 880{
881 return "cisco"; 881 return "cisco";
882} 882}
883 883
884 884
885void OCiscoMonitoringInterface::setChannel( int ) 885void OCiscoMonitoringInterface::setChannel( int )
886{ 886{
887 // cisco devices automatically switch channels when in monitor mode 887 // cisco devices automatically switch channels when in monitor mode
888} 888}
889 889
890 890
891/*====================================================================================== 891/*======================================================================================
892 * OWlanNGMonitoringInterface 892 * OWlanNGMonitoringInterface
893 *======================================================================================*/ 893 *======================================================================================*/
894 894
895 895
896OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) 896OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
897 :OMonitoringInterface( iface ) 897 :OMonitoringInterface( iface, prismHeader )
898{ 898{
899 iface->setMonitoring( this ); 899 iface->setMonitoring( this );
900} 900}
901 901
902 902
903OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() 903OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
904{ 904{
905} 905}
906 906
907 907
908void OWlanNGMonitoringInterface::setEnabled( bool b ) 908void OWlanNGMonitoringInterface::setEnabled( bool b )
909{ 909{
910 //FIXME: do nothing if its already in the same mode 910 //FIXME: do nothing if its already in the same mode
911 911
912 QString enable = b ? "true" : "false"; 912 QString enable = b ? "true" : "false";
913 QString prism = _prismHeader ? "true" : "false";
913 QString cmd; 914 QString cmd;
914 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); 915 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
916 (const char*) _if->name(), 1, (const char*) enable, (const char*) prism );
915 system( cmd ); 917 system( cmd );
916} 918}
917 919
918 920
919QString OWlanNGMonitoringInterface::name() const 921QString OWlanNGMonitoringInterface::name() const
920{ 922{
921 return "wlan-ng"; 923 return "wlan-ng";
922} 924}
923 925
924 926
925void OWlanNGMonitoringInterface::setChannel( int ) 927void OWlanNGMonitoringInterface::setChannel( int )
926{ 928{
927 // wlan-ng devices automatically switch channels when in monitor mode 929 // wlan-ng devices automatically switch channels when in monitor mode
928} 930}
929 931
930 932
931/*====================================================================================== 933/*======================================================================================
932 * OHostAPMonitoringInterface 934 * OHostAPMonitoringInterface
933 *======================================================================================*/ 935 *======================================================================================*/
934 936
935OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) 937OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
936 :OMonitoringInterface( iface ) 938 :OMonitoringInterface( iface, prismHeader )
937{ 939{
938 iface->setMonitoring( this ); 940 iface->setMonitoring( this );
939} 941}
940 942
941OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 943OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
942{ 944{
943} 945}
944 946
945void OHostAPMonitoringInterface::setEnabled( bool b ) 947void OHostAPMonitoringInterface::setEnabled( bool b )
946{ 948{
947 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 949 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
948 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 950 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
949 951
950 //TODO: check wireless extensions version on runtime and use 952 //TODO: check wireless extensions version on runtime and use
951 //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15 953 //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15
952 954
955 int monitorCode = _prismHeader ? 1 : 2;
956
953 if ( b ) 957 if ( b )
954 { 958 {
955 _if->setPrivate( "monitor", 1, 2 ); 959 _if->setPrivate( "monitor", 1, monitorCode );
956 } 960 }
957 else 961 else
958 { 962 {
959 _if->setPrivate( "monitor", 1, 0 ); 963 _if->setPrivate( "monitor", 1, 0 );
960 } 964 }
961} 965}
962 966
963 967
964QString OHostAPMonitoringInterface::name() const 968QString OHostAPMonitoringInterface::name() const
965{ 969{
966 return "hostap"; 970 return "hostap";
967} 971}
968 972
969 973
970/*====================================================================================== 974/*======================================================================================
971 * OOrinocoNetworkInterface 975 * OOrinocoNetworkInterface
972 *======================================================================================*/ 976 *======================================================================================*/
973 977
974OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) 978OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
975 :OMonitoringInterface( iface ) 979 :OMonitoringInterface( iface, prismHeader )
976{ 980{
977 iface->setMonitoring( this ); 981 iface->setMonitoring( this );
978} 982}
979 983
980 984
981OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 985OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
982{ 986{
983} 987}
984 988
985 989
986void OOrinocoMonitoringInterface::setChannel( int c ) 990void OOrinocoMonitoringInterface::setChannel( int c )
987{ 991{
988 _if->setPrivate( "monitor", 2, 1, c ); 992 int monitorCode = _prismHeader ? 1 : 2;
993 _if->setPrivate( "monitor", 2, monitorCode, c );
989} 994}
990 995
991 996
992void OOrinocoMonitoringInterface::setEnabled( bool b ) 997void OOrinocoMonitoringInterface::setEnabled( bool b )
993{ 998{
994 if ( b ) 999 if ( b )
995 { 1000 {
996 setChannel( 1 ); 1001 setChannel( 1 );
997 } 1002 }
998 else 1003 else
999 { 1004 {
1000 _if->setPrivate( "monitor", 2, 0, 0 ); 1005 _if->setPrivate( "monitor", 2, 0, 0 );
1001 } 1006 }
1002} 1007}
1003 1008
1004 1009
1005QString OOrinocoMonitoringInterface::name() const 1010QString OOrinocoMonitoringInterface::name() const
1006{ 1011{
1007 return "orinoco"; 1012 return "orinoco";
1008} 1013}
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index 1b38d02..eb9d506 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -263,276 +263,277 @@ class OChannelHopper : public QObject
263 /** 263 /**
264 * Destructor. 264 * Destructor.
265 */ 265 */
266 virtual ~OChannelHopper(); 266 virtual ~OChannelHopper();
267 /** 267 /**
268 * @returns true, if the channel hopper is hopping channels 268 * @returns true, if the channel hopper is hopping channels
269 */ 269 */
270 bool isActive() const; 270 bool isActive() const;
271 /** 271 /**
272 * @returns the last hopped channel 272 * @returns the last hopped channel
273 */ 273 */
274 int channel() const; 274 int channel() const;
275 /** 275 /**
276 * Set the channel hopping @a interval. 276 * Set the channel hopping @a interval.
277 * An interval of 0 deactivates the channel hopper. 277 * An interval of 0 deactivates the channel hopper.
278 */ 278 */
279 void setInterval( int interval ); 279 void setInterval( int interval );
280 /** 280 /**
281 * @returns the channel hopping interval 281 * @returns the channel hopping interval
282 */ 282 */
283 int interval() const; 283 int interval() const;
284 284
285 signals: 285 signals:
286 /** 286 /**
287 * This signal is emitted right after the channel hopper performed a hop 287 * This signal is emitted right after the channel hopper performed a hop
288 */ 288 */
289 void hopped( int ); 289 void hopped( int );
290 290
291 protected: 291 protected:
292 virtual void timerEvent( QTimerEvent* ); 292 virtual void timerEvent( QTimerEvent* );
293 293
294 private: 294 private:
295 OWirelessNetworkInterface* _iface; 295 OWirelessNetworkInterface* _iface;
296 int _interval; 296 int _interval;
297 int _tid; 297 int _tid;
298 QValueList<int> _channels; 298 QValueList<int> _channels;
299 QValueList<int>::Iterator _channel; 299 QValueList<int>::Iterator _channel;
300}; 300};
301 301
302 302
303/*====================================================================================== 303/*======================================================================================
304 * OWirelessNetworkInterface 304 * OWirelessNetworkInterface
305 *======================================================================================*/ 305 *======================================================================================*/
306 306
307/** 307/**
308 * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. 308 * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol.
309 * 309 *
310 * This class provides a high-level encapsulation of the Linux wireless extension API. 310 * This class provides a high-level encapsulation of the Linux wireless extension API.
311 * 311 *
312 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 312 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
313 */ 313 */
314class OWirelessNetworkInterface : public ONetworkInterface 314class OWirelessNetworkInterface : public ONetworkInterface
315{ 315{
316 friend class OMonitoringInterface; 316 friend class OMonitoringInterface;
317 friend class OCiscoMonitoringInterface; 317 friend class OCiscoMonitoringInterface;
318 friend class OWlanNGMonitoringInterface; 318 friend class OWlanNGMonitoringInterface;
319 friend class OHostAPMonitoringInterface; 319 friend class OHostAPMonitoringInterface;
320 friend class OOrinocoMonitoringInterface; 320 friend class OOrinocoMonitoringInterface;
321 321
322 friend class OPrivateIOCTL; 322 friend class OPrivateIOCTL;
323 323
324 public: 324 public:
325 /** 325 /**
326 * Constructor. 326 * Constructor.
327 */ 327 */
328 OWirelessNetworkInterface( QObject* parent, const char* name ); 328 OWirelessNetworkInterface( QObject* parent, const char* name );
329 /** 329 /**
330 * Destructor. 330 * Destructor.
331 */ 331 */
332 virtual ~OWirelessNetworkInterface(); 332 virtual ~OWirelessNetworkInterface();
333 /** 333 /**
334 * Setting the @a channel of the interface changes the radio frequency (RF) 334 * Setting the @a channel of the interface changes the radio frequency (RF)
335 * of the corresponding wireless network device. 335 * of the corresponding wireless network device.
336 */ 336 */
337 virtual void setChannel( int channel ) const; 337 virtual void setChannel( int channel ) const;
338 /** 338 /**
339 * @returns the channel index of the current radio frequency. 339 * @returns the channel index of the current radio frequency.
340 */ 340 */
341 virtual int channel() const; 341 virtual int channel() const;
342 /** 342 /**
343 * @returns the current radio frequency (in MHz). 343 * @returns the current radio frequency (in MHz).
344 */ 344 */
345 virtual double frequency() const; 345 virtual double frequency() const;
346 /** 346 /**
347 * @returns the number of radio frequency channels for the 347 * @returns the number of radio frequency channels for the
348 * corresponding wireless network device. 348 * corresponding wireless network device.
349 * @note European devices usually have 14 channels, while American typically feature 11 channels. 349 * @note European devices usually have 14 channels, while American typically feature 11 channels.
350 */ 350 */
351 virtual int channels() const; 351 virtual int channels() const;
352 /** 352 /**
353 * Set the IEEE 802.11 operation @a mode. 353 * Set the IEEE 802.11 operation @a mode.
354 * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master 354 * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master
355 * @warning Not all drivers support the all modes. 355 * @warning Not all drivers support the all modes.
356 * @note You might have to change the SSID to get the operation mode change into effect. 356 * @note You might have to change the SSID to get the operation mode change into effect.
357 */ 357 */
358 virtual void setMode( const QString& mode ); 358 virtual void setMode( const QString& mode );
359 /** 359 /**
360 * @returns the current IEEE 802.11 operation mode. 360 * @returns the current IEEE 802.11 operation mode.
361 * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown 361 * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown
362 */ 362 */
363 virtual QString mode() const; 363 virtual QString mode() const;
364 /** 364 /**
365 * Setting the monitor mode on a wireless network interface enables 365 * Setting the monitor mode on a wireless network interface enables
366 * listening to IEEE 802.11 data and management frames which normally 366 * listening to IEEE 802.11 data and management frames which normally
367 * are handled by the device firmware. This can be used to detect 367 * are handled by the device firmware. This can be used to detect
368 * other wireless network devices, e.g. Access Points or Ad-hoc stations. 368 * other wireless network devices, e.g. Access Points or Ad-hoc stations.
369 * @warning Standard wireless network drives don't support the monitor mode. 369 * @warning Standard wireless network drives don't support the monitor mode.
370 * @warning You need a patched driver for this to work. 370 * @warning You need a patched driver for this to work.
371 * @note Enabling the monitor mode is highly driver dependent and requires 371 * @note Enabling the monitor mode is highly driver dependent and requires
372 * the proper @ref OMonitoringInterface to be associated with the interface. 372 * the proper @ref OMonitoringInterface to be associated with the interface.
373 * @see OMonitoringInterface 373 * @see OMonitoringInterface
374 */ 374 */
375 virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); 375 virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" );
376 /** 376 /**
377 * @returns true if the device is listening in IEEE 802.11 monitor mode 377 * @returns true if the device is listening in IEEE 802.11 monitor mode
378 */ 378 */
379 virtual bool monitorMode() const; //FIXME: ==> mode() 379 virtual bool monitorMode() const; //FIXME: ==> mode()
380 /** 380 /**
381 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. 381 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping.
382 * @see OChannelHopper 382 * @see OChannelHopper
383 */ 383 */
384 virtual void setChannelHopping( int interval = 0 ); 384 virtual void setChannelHopping( int interval = 0 );
385 /** 385 /**
386 * @returns the channel hopping interval or 0, if channel hopping is disabled. 386 * @returns the channel hopping interval or 0, if channel hopping is disabled.
387 */ 387 */
388 virtual int channelHopping() const; 388 virtual int channelHopping() const;
389 /** 389 /**
390 * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before 390 * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before
391 */ 391 */
392 virtual OChannelHopper* channelHopper() const; 392 virtual OChannelHopper* channelHopper() const;
393 /** 393 /**
394 * Set the station @a nickname. 394 * Set the station @a nickname.
395 */ 395 */
396 virtual void setNickName( const QString& nickname ); 396 virtual void setNickName( const QString& nickname );
397 /** 397 /**
398 * @returns the current station nickname. 398 * @returns the current station nickname.
399 */ 399 */
400 virtual QString nickName() const; 400 virtual QString nickName() const;
401 /** 401 /**
402 * Invoke the private IOCTL @a command with a @number of parameters on the network interface. 402 * Invoke the private IOCTL @a command with a @number of parameters on the network interface.
403 * @see OPrivateIOCTL 403 * @see OPrivateIOCTL
404 */ 404 */
405 virtual void setPrivate( const QString& command, int number, ... ); 405 virtual void setPrivate( const QString& command, int number, ... );
406 /** 406 /**
407 * @returns true if the interface is featuring the private IOCTL @command. 407 * @returns true if the interface is featuring the private IOCTL @command.
408 */ 408 */
409 virtual bool hasPrivate( const QString& command ); 409 virtual bool hasPrivate( const QString& command );
410 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this 410 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this
411 411
412 virtual bool isAssociated() const {}; //FIXME: Implement and document this 412 virtual bool isAssociated() const {}; //FIXME: Implement and document this
413 /** 413 /**
414 * @returns the MAC address of the Access Point if the 414 * @returns the MAC address of the Access Point if the
415 * device is in infrastructure mode. @returns a (more or less random) CELL 415 * device is in infrastructure mode. @returns a (more or less random) CELL
416 * address if the device is in adhoc mode. 416 * address if the device is in adhoc mode.
417 */ 417 */
418 virtual QString associatedAP() const; 418 virtual QString associatedAP() const;
419 /** 419 /**
420 * Set the @a ssid (Service Set ID) string. This is used to decide 420 * Set the @a ssid (Service Set ID) string. This is used to decide
421 * which network to associate with (use "any" to let the driver decide). 421 * which network to associate with (use "any" to let the driver decide).
422 */ 422 */
423 virtual void setSSID( const QString& ssid ); 423 virtual void setSSID( const QString& ssid );
424 /** 424 /**
425 * @returns the current SSID (Service Set ID). 425 * @returns the current SSID (Service Set ID).
426 */ 426 */
427 virtual QString SSID() const; 427 virtual QString SSID() const;
428 428
429 protected: 429 protected:
430 void buildChannelList(); 430 void buildChannelList();
431 void buildPrivateList(); 431 void buildPrivateList();
432 virtual void init(); 432 virtual void init();
433 struct iwreq& iwr() const; 433 struct iwreq& iwr() const;
434 bool wioctl( int call ) const; 434 bool wioctl( int call ) const;
435 bool wioctl( int call, struct iwreq& ) const; 435 bool wioctl( int call, struct iwreq& ) const;
436 436
437 protected: 437 protected:
438 mutable struct iwreq _iwr; 438 mutable struct iwreq _iwr;
439 QMap<int,int> _channels; 439 QMap<int,int> _channels;
440 440
441 private: 441 private:
442 OChannelHopper* _hopper; 442 OChannelHopper* _hopper;
443}; 443};
444 444
445 445
446/*====================================================================================== 446/*======================================================================================
447 * OMonitoringInterface 447 * OMonitoringInterface
448 *======================================================================================*/ 448 *======================================================================================*/
449 449
450 450
451class OMonitoringInterface 451class OMonitoringInterface
452{ 452{
453 public: 453 public:
454 OMonitoringInterface(); 454 OMonitoringInterface();
455 OMonitoringInterface( ONetworkInterface* ); 455 OMonitoringInterface( ONetworkInterface*, bool _prismHeader );
456 virtual ~OMonitoringInterface(); 456 virtual ~OMonitoringInterface();
457 457
458 public: 458 public:
459 virtual void setEnabled( bool ); 459 virtual void setEnabled( bool );
460 virtual bool enabled() const; 460 virtual bool enabled() const;
461 virtual void setChannel( int ); 461 virtual void setChannel( int );
462 462
463 virtual QString name() const = 0; 463 virtual QString name() const = 0;
464 464
465 protected: 465 protected:
466 OWirelessNetworkInterface* _if; 466 OWirelessNetworkInterface* _if;
467 bool _prismHeader;
467 468
468}; 469};
469 470
470 471
471/*====================================================================================== 472/*======================================================================================
472 * OCiscoMonitoring 473 * OCiscoMonitoring
473 *======================================================================================*/ 474 *======================================================================================*/
474 475
475 476
476class OCiscoMonitoringInterface : public OMonitoringInterface 477class OCiscoMonitoringInterface : public OMonitoringInterface
477{ 478{
478 public: 479 public:
479 OCiscoMonitoringInterface( ONetworkInterface* ); 480 OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader );
480 virtual ~OCiscoMonitoringInterface(); 481 virtual ~OCiscoMonitoringInterface();
481 482
482 virtual void setEnabled( bool ); 483 virtual void setEnabled( bool );
483 virtual QString name() const; 484 virtual QString name() const;
484 virtual void setChannel( int ); 485 virtual void setChannel( int );
485 486
486}; 487};
487 488
488/*====================================================================================== 489/*======================================================================================
489 * OWlanNGMonitoringInterface 490 * OWlanNGMonitoringInterface
490 *======================================================================================*/ 491 *======================================================================================*/
491 492
492class OWlanNGMonitoringInterface : public OMonitoringInterface 493class OWlanNGMonitoringInterface : public OMonitoringInterface
493{ 494{
494 public: 495 public:
495 OWlanNGMonitoringInterface( ONetworkInterface* ); 496 OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader );
496 virtual ~OWlanNGMonitoringInterface(); 497 virtual ~OWlanNGMonitoringInterface();
497 498
498 public: 499 public:
499 virtual void setEnabled( bool ); 500 virtual void setEnabled( bool );
500 virtual QString name() const; 501 virtual QString name() const;
501 virtual void setChannel( int ); 502 virtual void setChannel( int );
502 503
503}; 504};
504 505
505/*====================================================================================== 506/*======================================================================================
506 * OHostAPMonitoringInterface 507 * OHostAPMonitoringInterface
507 *======================================================================================*/ 508 *======================================================================================*/
508 509
509class OHostAPMonitoringInterface : public OMonitoringInterface 510class OHostAPMonitoringInterface : public OMonitoringInterface
510{ 511{
511 public: 512 public:
512 OHostAPMonitoringInterface( ONetworkInterface* ); 513 OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader );
513 virtual ~OHostAPMonitoringInterface(); 514 virtual ~OHostAPMonitoringInterface();
514 515
515 public: 516 public:
516 virtual void setEnabled( bool ); 517 virtual void setEnabled( bool );
517 virtual QString name() const; 518 virtual QString name() const;
518 }; 519 };
519 520
520/*====================================================================================== 521/*======================================================================================
521 * OOrinocoMonitoringInterface 522 * OOrinocoMonitoringInterface
522 *======================================================================================*/ 523 *======================================================================================*/
523 524
524class OOrinocoMonitoringInterface : public OMonitoringInterface 525class OOrinocoMonitoringInterface : public OMonitoringInterface
525{ 526{
526 public: 527 public:
527 OOrinocoMonitoringInterface( ONetworkInterface* ); 528 OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader );
528 virtual ~OOrinocoMonitoringInterface(); 529 virtual ~OOrinocoMonitoringInterface();
529 530
530 public: 531 public:
531 virtual void setChannel( int ); 532 virtual void setChannel( int );
532 virtual void setEnabled( bool ); 533 virtual void setEnabled( bool );
533 virtual QString name() const; 534 virtual QString name() const;
534 535
535}; 536};
536 537
537#endif // ONETWORK_H 538#endif // ONETWORK_H
538 539
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index e2ab6d7..f6d05ea 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -1,266 +1,266 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/opcap.h> 36#include <opie2/opcap.h>
37 37
38/* QT */ 38/* QT */
39 39
40#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) 40#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects)
41#include <qsocketnotifier.h> 41#include <qsocketnotifier.h>
42#include <qobjectlist.h> 42#include <qobjectlist.h>
43 43
44/*====================================================================================== 44/*======================================================================================
45 * OPacket 45 * OPacket
46 *======================================================================================*/ 46 *======================================================================================*/
47 47
48OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) 48OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent )
49 :QObject( parent, "Generic" ), _hdr( header ), _data( data ) 49 :QObject( parent, "Generic" ), _hdr( header ), _data( data )
50{ 50{
51 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); 51 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
52 52
53 _end = (unsigned char*) data + header.len; 53 _end = (unsigned char*) data + header.len;
54 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); 54 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end );
55 55
56 switch ( datalink ) 56 switch ( datalink )
57 { 57 {
58 case DLT_EN10MB: 58 case DLT_EN10MB:
59 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); 59 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" );
60 new OEthernetPacket( _end, (const struct ether_header*) data, this ); 60 new OEthernetPacket( _end, (const struct ether_header*) data, this );
61 break; 61 break;
62 62
63 case DLT_IEEE802_11: 63 case DLT_IEEE802_11:
64 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); 64 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" );
65 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); 65 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this );
66 break; 66 break;
67 67
68 case DLT_PRISM_HEADER: 68 case DLT_PRISM_HEADER:
69 qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" ); 69 qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" );
70 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); 70 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this );
71 break; 71 break;
72 72
73 default: 73 default:
74 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink '%s'!", datalink ); 74 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink (type %d)!", datalink );
75 } 75 }
76} 76}
77 77
78 78
79OPacket::~OPacket() 79OPacket::~OPacket()
80{ 80{
81} 81}
82 82
83 83
84timevalstruct OPacket::timeval() const 84timevalstruct OPacket::timeval() const
85{ 85{
86 return _hdr.ts; 86 return _hdr.ts;
87} 87}
88 88
89 89
90int OPacket::caplen() const 90int OPacket::caplen() const
91{ 91{
92 return _hdr.caplen; 92 return _hdr.caplen;
93} 93}
94 94
95 95
96void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) 96void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l )
97{ 97{
98 if (!l) return; 98 if (!l) return;
99 QObject* o = l->first(); 99 QObject* o = l->first();
100 while ( o ) 100 while ( o )
101 { 101 {
102 stats[o->name()]++; 102 stats[o->name()]++;
103 updateStats( stats, const_cast<QObjectList*>( o->children() ) ); 103 updateStats( stats, const_cast<QObjectList*>( o->children() ) );
104 o = l->next(); 104 o = l->next();
105 } 105 }
106} 106}
107 107
108 108
109QString OPacket::dump( int bpl ) const 109QString OPacket::dump( int bpl ) const
110{ 110{
111 static int index = 0; 111 static int index = 0;
112 index++; 112 index++;
113 int len = _hdr.caplen; 113 int len = _hdr.caplen;
114 QString str; 114 QString str;
115 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); 115 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len );
116 str.append( "0000: " ); 116 str.append( "0000: " );
117 QString tmp; 117 QString tmp;
118 QString bytes; 118 QString bytes;
119 QString chars; 119 QString chars;
120 120
121 for ( int i = 0; i < len; ++i ) 121 for ( int i = 0; i < len; ++i )
122 { 122 {
123 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); 123 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp );
124 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); 124 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] );
125 else chars.append( '.' ); 125 else chars.append( '.' );
126 126
127 if ( !((i+1) % bpl) ) 127 if ( !((i+1) % bpl) )
128 { 128 {
129 str.append( bytes ); 129 str.append( bytes );
130 str.append( ' ' ); 130 str.append( ' ' );
131 str.append( chars ); 131 str.append( chars );
132 str.append( '\n' ); 132 str.append( '\n' );
133 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); 133 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp );
134 bytes = ""; 134 bytes = "";
135 chars = ""; 135 chars = "";
136 } 136 }
137 137
138 } 138 }
139 if ( (len % bpl) ) 139 if ( (len % bpl) )
140 { 140 {
141 str.append( bytes.leftJustify( 1 + 3*bpl ) ); 141 str.append( bytes.leftJustify( 1 + 3*bpl ) );
142 str.append( chars ); 142 str.append( chars );
143 } 143 }
144 str.append( '\n' ); 144 str.append( '\n' );
145 return str; 145 return str;
146} 146}
147 147
148 148
149int OPacket::len() const 149int OPacket::len() const
150{ 150{
151 return _hdr.len; 151 return _hdr.len;
152} 152}
153 153
154 154
155/*====================================================================================== 155/*======================================================================================
156 * OEthernetPacket 156 * OEthernetPacket
157 *======================================================================================*/ 157 *======================================================================================*/
158 158
159OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) 159OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
160 :QObject( parent, "Ethernet" ), _ether( data ) 160 :QObject( parent, "Ethernet" ), _ether( data )
161{ 161{
162 162
163 qDebug( "Source = %s", (const char*) sourceAddress().toString() ); 163 qDebug( "Source = %s", (const char*) sourceAddress().toString() );
164 qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); 164 qDebug( "Destination = %s", (const char*) destinationAddress().toString() );
165 165
166 if ( sourceAddress() == OMacAddress::broadcast ) 166 if ( sourceAddress() == OMacAddress::broadcast )
167 qDebug( "Source is broadcast address" ); 167 qDebug( "Source is broadcast address" );
168 if ( destinationAddress() == OMacAddress::broadcast ) 168 if ( destinationAddress() == OMacAddress::broadcast )
169 qDebug( "Destination is broadcast address" ); 169 qDebug( "Destination is broadcast address" );
170 170
171 switch ( type() ) 171 switch ( type() )
172 { 172 {
173 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 173 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
174 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } 174 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; }
175 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } 175 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; }
176 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); 176 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" );
177 } 177 }
178 178
179} 179}
180 180
181 181
182OEthernetPacket::~OEthernetPacket() 182OEthernetPacket::~OEthernetPacket()
183{ 183{
184} 184}
185 185
186 186
187OMacAddress OEthernetPacket::sourceAddress() const 187OMacAddress OEthernetPacket::sourceAddress() const
188{ 188{
189 return OMacAddress( _ether->ether_shost ); 189 return OMacAddress( _ether->ether_shost );
190} 190}
191 191
192 192
193OMacAddress OEthernetPacket::destinationAddress() const 193OMacAddress OEthernetPacket::destinationAddress() const
194{ 194{
195 return OMacAddress( _ether->ether_dhost ); 195 return OMacAddress( _ether->ether_dhost );
196} 196}
197 197
198int OEthernetPacket::type() const 198int OEthernetPacket::type() const
199{ 199{
200 return ntohs( _ether->ether_type ); 200 return ntohs( _ether->ether_type );
201} 201}
202 202
203 203
204/*====================================================================================== 204/*======================================================================================
205 * OIPPacket 205 * OIPPacket
206 *======================================================================================*/ 206 *======================================================================================*/
207 207
208 208
209OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) 209OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent )
210 :QObject( parent, "IP" ), _iphdr( data ) 210 :QObject( parent, "IP" ), _iphdr( data )
211{ 211{
212 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); 212 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." );
213 213
214 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); 214 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) );
215 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); 215 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) );
216 216
217 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); 217 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() );
218 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); 218 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() );
219 219
220 switch ( protocol() ) 220 switch ( protocol() )
221 { 221 {
222 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; 222 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break;
223 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; 223 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break;
224 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); 224 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() );
225 } 225 }
226 226
227} 227}
228 228
229OIPPacket::~OIPPacket() 229OIPPacket::~OIPPacket()
230{ 230{
231} 231}
232 232
233 233
234QHostAddress OIPPacket::fromIPAddress() const 234QHostAddress OIPPacket::fromIPAddress() const
235{ 235{
236 return EXTRACT_32BITS( &_iphdr->saddr ); 236 return EXTRACT_32BITS( &_iphdr->saddr );
237} 237}
238 238
239 239
240QHostAddress OIPPacket::toIPAddress() const 240QHostAddress OIPPacket::toIPAddress() const
241{ 241{
242 return EXTRACT_32BITS( &_iphdr->saddr ); 242 return EXTRACT_32BITS( &_iphdr->saddr );
243} 243}
244 244
245 245
246int OIPPacket::tos() const 246int OIPPacket::tos() const
247{ 247{
248 return _iphdr->tos; 248 return _iphdr->tos;
249} 249}
250 250
251 251
252int OIPPacket::len() const 252int OIPPacket::len() const
253{ 253{
254 return EXTRACT_16BITS( &_iphdr->tot_len ); 254 return EXTRACT_16BITS( &_iphdr->tot_len );
255} 255}
256 256
257 257
258int OIPPacket::id() const 258int OIPPacket::id() const
259{ 259{
260 return EXTRACT_16BITS( &_iphdr->id ); 260 return EXTRACT_16BITS( &_iphdr->id );
261} 261}
262 262
263 263
264int OIPPacket::offset() const 264int OIPPacket::offset() const
265{ 265{
266 return EXTRACT_16BITS( &_iphdr->frag_off ); 266 return EXTRACT_16BITS( &_iphdr->frag_off );