summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2003-05-05 14:57:27 (UTC)
committer mickeyl <mickeyl>2003-05-05 14:57:27 (UTC)
commit29f5c6e6bcb8db0f0e26da25dbf34b2685c01526 (patch) (unidiff)
treea05e296ff11d532fd3d5fd092aade07474d1ba95 /libopie2
parenta5818261bec2d0a6d903fef9baeed1a7abc85275 (diff)
downloadopie-29f5c6e6bcb8db0f0e26da25dbf34b2685c01526.zip
opie-29f5c6e6bcb8db0f0e26da25dbf34b2685c01526.tar.gz
opie-29f5c6e6bcb8db0f0e26da25dbf34b2685c01526.tar.bz2
- fix segfault on unknown linktype (thanks groucho)
- make capturing using PRISM headers optional
Diffstat (limited to 'libopie2') (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
@@ -716,293 +716,298 @@ QString OWirelessNetworkInterface::nickName() const
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
@@ -359,180 +359,181 @@ class OWirelessNetworkInterface : public ONetworkInterface
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,170 +1,170 @@
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