summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp2
-rw-r--r--libopie2/opienet/opcap.cpp2
2 files changed, 2 insertions, 2 deletions
diff --git a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
index 34d32d2..c49daa0 100644
--- a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
+++ b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
@@ -1,217 +1,217 @@
1#include <qdict.h> 1#include <qdict.h>
2#include <qsocketnotifier.h> 2#include <qsocketnotifier.h>
3#include <qstring.h> 3#include <qstring.h>
4#include <opie2/onetwork.h> 4#include <opie2/onetwork.h>
5#include <qapplication.h> 5#include <qapplication.h>
6#include <opie2/opcap.h> 6#include <opie2/opcap.h>
7#include <cerrno> 7#include <cerrno>
8#include <cstdio> 8#include <cstdio>
9#include <cstdlib> 9#include <cstdlib>
10#include <cstring> 10#include <cstring>
11 11
12//======================== Station help class =============================== 12//======================== Station help class ===============================
13 13
14class Station 14class Station
15{ 15{
16 public: 16 public:
17 Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {}; 17 Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {};
18 ~Station() {}; 18 ~Station() {};
19 19
20 QString type; 20 QString type;
21 int channel; 21 int channel;
22 bool wep; 22 bool wep;
23 int beacons; 23 int beacons;
24}; 24};
25 25
26QDict<Station> stations; 26QDict<Station> stations;
27 27
28//======================== Application class =============================== 28//======================== Application class ===============================
29 29
30class Wellenreiter : public QApplication 30class Wellenreiter : public QApplication
31{ 31{
32Q_OBJECT 32Q_OBJECT
33public: 33public:
34 Wellenreiter( int argc, char** argv ) : QApplication( argc, argv ) 34 Wellenreiter( int argc, char** argv ) : QApplication( argc, argv )
35 { 35 {
36 36
37 ONetwork* net = ONetwork::instance(); 37 ONetwork* net = ONetwork::instance();
38 38
39 if ( argc < 3 ) 39 if ( argc < 3 )
40 { 40 {
41 printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] ); 41 printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] );
42 printf( "\n" ); 42 printf( "\n" );
43 printf( "Valid wireless interfaces (detected) are:\n" ); 43 printf( "Valid wireless interfaces (detected) are:\n" );
44 44
45 ONetwork::InterfaceIterator it = net->iterator(); 45 ONetwork::InterfaceIterator it = net->iterator();
46 while ( it.current() ) 46 while ( it.current() )
47 { 47 {
48 if ( it.current()->isWireless() ) 48 if ( it.current()->isWireless() )
49 { 49 {
50 printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(), 50 printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(),
51 (const char*) it.current()->macAddress().toString(), 51 (const char*) it.current()->macAddress().toString(),
52 (const char*) it.current()->ipV4Address() ); 52 (const char*) it.current()->ipV4Address() );
53 } 53 }
54 ++it; 54 ++it;
55 } 55 }
56 exit( -1 ); 56 exit( -1 );
57 } 57 }
58 58
59 printf( "****************************************************\n" ); 59 printf( "****************************************************\n" );
60 printf( "* Wellenreiter mini edition 1.0 (C) 2003 M-M-M *\n" ); 60 printf( "* Wellenreiter mini edition 1.0 (C) 2003 M-M-M *\n" );
61 printf( "****************************************************\n" ); 61 printf( "****************************************************\n" );
62 printf( "\n\n" ); 62 printf( "\n\n" );
63 63
64 QString interface( argv[1] ); 64 QString interface( argv[1] );
65 QString driver( argv[2] ); 65 QString driver( argv[2] );
66 66
67 printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver ); 67 printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver );
68 68
69 // sanity checks before downcasting 69 // sanity checks before downcasting
70 ONetworkInterface* iface = net->interface( interface ); 70 ONetworkInterface* iface = net->interface( interface );
71 if ( !iface ) 71 if ( !iface )
72 { 72 {
73 printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface ); 73 printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface );
74 exit( -1 ); 74 exit( -1 );
75 } 75 }
76 if ( !iface->isWireless() ) 76 if ( !iface->isWireless() )
77 { 77 {
78 printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface ); 78 printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface );
79 exit( -1 ); 79 exit( -1 );
80 } 80 }
81 81
82 // downcast should be safe now 82 // downcast should be safe now
83 wiface = (OWirelessNetworkInterface*) iface; 83 wiface = (OWirelessNetworkInterface*) iface;
84 printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() ); 84 printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() );
85 85
86 // ifconfig +promisc the interface to receive all packets 86 // ifconfig +promisc the interface to receive all packets
87 if ( !wiface->promiscuousMode() ) 87 if ( !wiface->promiscuousMode() )
88 { 88 {
89 printf( "Interface status is not promisc... switching to promisc... " ); 89 printf( "Interface status is not promisc... switching to promisc... " );
90 wiface->setPromiscuousMode( true ); 90 wiface->setPromiscuousMode( true );
91 if ( !wiface->promiscuousMode() ) 91 if ( !wiface->promiscuousMode() )
92 { 92 {
93 printf( "failed (%s). Exiting.\n", strerror( errno ) ); 93 printf( "failed (%s). Exiting.\n", strerror( errno ) );
94 exit( -1 ); 94 exit( -1 );
95 } 95 }
96 else 96 else
97 { 97 {
98 printf( "ok.\n" ); 98 printf( "ok.\n" );
99 } 99 }
100 } 100 }
101 else 101 else
102 printf( "Interface status is already promisc - good.\n" ); 102 printf( "Interface status is already promisc - good.\n" );
103 103
104 // connect a monitoring strategy to the interface 104 // connect a monitoring strategy to the interface
105 if ( driver == "orinoco" ) 105 if ( driver == "orinoco" )
106 new OOrinocoMonitoringInterface( wiface ); 106 new OOrinocoMonitoringInterface( wiface, false );
107 else 107 else
108 { 108 {
109 printf( "Unknown driver. Exiting\n" ); 109 printf( "Unknown driver. Exiting\n" );
110 exit( -1 ); 110 exit( -1 );
111 } 111 }
112 112
113 // enable monitoring mode 113 // enable monitoring mode
114 printf( "Enabling monitor mode...\n" ); 114 printf( "Enabling monitor mode...\n" );
115 //wiface->setMonitorMode( true ); 115 //wiface->setMonitorMode( true );
116 116
117 // open a packet capturer 117 // open a packet capturer
118 cap = new OPacketCapturer(); 118 cap = new OPacketCapturer();
119 cap->open( interface ); 119 cap->open( interface );
120 if ( !cap->isOpen() ) 120 if ( !cap->isOpen() )
121 { 121 {
122 printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) ); 122 printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) );
123 exit( -1 ); 123 exit( -1 );
124 } 124 }
125 125
126 // set capturer to non-blocking mode 126 // set capturer to non-blocking mode
127 cap->setBlocking( false ); 127 cap->setBlocking( false );
128 128
129 // start channel hopper 129 // start channel hopper
130 //wiface->setChannelHopping( 1000 ); 130 //wiface->setChannelHopping( 1000 );
131 131
132 // connect 132 // connect
133 connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); 133 connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) );
134 134
135 } 135 }
136 136
137 ~Wellenreiter() {}; 137 ~Wellenreiter() {};
138 138
139public slots: 139public slots:
140 void receivePacket(OPacket* p) 140 void receivePacket(OPacket* p)
141 { 141 {
142 if (!p) 142 if (!p)
143 { 143 {
144 printf( "(empty packet received)\n" ); 144 printf( "(empty packet received)\n" );
145 return; 145 return;
146 } 146 }
147 147
148 OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" ); 148 OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" );
149 if ( beacon ) 149 if ( beacon )
150 { 150 {
151 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); 151 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
152 QString essid = ssid ? ssid->ID() : "<unknown>"; 152 QString essid = ssid ? ssid->ID() : "<unknown>";
153 153
154 if ( stations.find( essid ) ) 154 if ( stations.find( essid ) )
155 stations[essid]->beacons++; 155 stations[essid]->beacons++;
156 else 156 else
157 { 157 {
158 printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) essid ); 158 printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) essid );
159 stations.insert( essid, new Station( "unknown", wiface->channel(), 159 stations.insert( essid, new Station( "unknown", wiface->channel(),
160 ((OWaveLanPacket*) beacon->parent())->usesWep() ) ); 160 ((OWaveLanPacket*) beacon->parent())->usesWep() ) );
161 } 161 }
162 return; 162 return;
163 } 163 }
164 164
165 OWaveLanDataPacket* data = (OWaveLanDataPacket*) p->child( "802.11 Data" ); 165 OWaveLanDataPacket* data = (OWaveLanDataPacket*) p->child( "802.11 Data" );
166 if ( data ) 166 if ( data )
167 { 167 {
168 OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" ); 168 OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" );
169 if ( wlan->fromDS() && !wlan->toDS() ) 169 if ( wlan->fromDS() && !wlan->toDS() )
170 { 170 {
171 printf( "FromDS: '%s' -> '%s' via '%s'\n", 171 printf( "FromDS: '%s' -> '%s' via '%s'\n",
172 (const char*) wlan->macAddress3().toString(true), 172 (const char*) wlan->macAddress3().toString(true),
173 (const char*) wlan->macAddress1().toString(true), 173 (const char*) wlan->macAddress1().toString(true),
174 (const char*) wlan->macAddress2().toString(true) ); 174 (const char*) wlan->macAddress2().toString(true) );
175 } 175 }
176 else 176 else
177 if ( !wlan->fromDS() && wlan->toDS() ) 177 if ( !wlan->fromDS() && wlan->toDS() )
178 { 178 {
179 printf( "ToDS: '%s' -> '%s' via '%s'\n", 179 printf( "ToDS: '%s' -> '%s' via '%s'\n",
180 (const char*) wlan->macAddress2().toString(true), 180 (const char*) wlan->macAddress2().toString(true),
181 (const char*) wlan->macAddress3().toString(true), 181 (const char*) wlan->macAddress3().toString(true),
182 (const char*) wlan->macAddress1().toString(true) ); 182 (const char*) wlan->macAddress1().toString(true) );
183 } 183 }
184 else 184 else
185 if ( wlan->fromDS() && wlan->toDS() ) 185 if ( wlan->fromDS() && wlan->toDS() )
186 { 186 {
187 printf( "WSD(bridge): '%s' -> '%s' via '%s' and '%s'\n", 187 printf( "WSD(bridge): '%s' -> '%s' via '%s' and '%s'\n",
188 (const char*) wlan->macAddress4().toString(true), 188 (const char*) wlan->macAddress4().toString(true),
189 (const char*) wlan->macAddress3().toString(true), 189 (const char*) wlan->macAddress3().toString(true),
190 (const char*) wlan->macAddress1().toString(true), 190 (const char*) wlan->macAddress1().toString(true),
191 (const char*) wlan->macAddress2().toString(true) ); 191 (const char*) wlan->macAddress2().toString(true) );
192 } 192 }
193 else 193 else
194 { 194 {
195 printf( "IBSS(AdHoc): '%s' -> '%s' (Cell: '%s')'\n", 195 printf( "IBSS(AdHoc): '%s' -> '%s' (Cell: '%s')'\n",
196 (const char*) wlan->macAddress2().toString(true), 196 (const char*) wlan->macAddress2().toString(true),
197 (const char*) wlan->macAddress1().toString(true), 197 (const char*) wlan->macAddress1().toString(true),
198 (const char*) wlan->macAddress3().toString(true) ); 198 (const char*) wlan->macAddress3().toString(true) );
199 } 199 }
200 return; 200 return;
201 } 201 }
202 } 202 }
203private: 203private:
204 OPacketCapturer* cap; 204 OPacketCapturer* cap;
205 OWirelessNetworkInterface* wiface; 205 OWirelessNetworkInterface* wiface;
206}; 206};
207 207
208 208
209int main( int argc, char** argv ) 209int main( int argc, char** argv )
210{ 210{
211 Wellenreiter w( argc, argv ); 211 Wellenreiter w( argc, argv );
212 w.exec(); 212 w.exec();
213 return 0; 213 return 0;
214} 214}
215 215
216#include "miniwellenreiter.moc" 216#include "miniwellenreiter.moc"
217 217
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index f6d05ea..523be3e 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -617,385 +617,385 @@ bool OWaveLanManagementPacket::canPrivacy() const
617 617
618OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) 618OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent )
619 :QObject( parent, "802.11 SSID" ), _data( data ) 619 :QObject( parent, "802.11 SSID" ), _data( data )
620{ 620{
621 qDebug( "OWaveLanManagementSSID()" ); 621 qDebug( "OWaveLanManagementSSID()" );
622} 622}
623 623
624 624
625OWaveLanManagementSSID::~OWaveLanManagementSSID() 625OWaveLanManagementSSID::~OWaveLanManagementSSID()
626{ 626{
627} 627}
628 628
629 629
630QString OWaveLanManagementSSID::ID() const 630QString OWaveLanManagementSSID::ID() const
631{ 631{
632 int length = _data->length; 632 int length = _data->length;
633 if ( length > 32 ) length = 32; 633 if ( length > 32 ) length = 32;
634 char essid[length+1]; 634 char essid[length+1];
635 memcpy( &essid, &_data->ssid, length ); 635 memcpy( &essid, &_data->ssid, length );
636 essid[length] = 0x0; 636 essid[length] = 0x0;
637 return essid; 637 return essid;
638} 638}
639 639
640 640
641/*====================================================================================== 641/*======================================================================================
642 * OWaveLanManagementRates 642 * OWaveLanManagementRates
643 *======================================================================================*/ 643 *======================================================================================*/
644 644
645OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) 645OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent )
646 :QObject( parent, "802.11 Rates" ), _data( data ) 646 :QObject( parent, "802.11 Rates" ), _data( data )
647{ 647{
648 qDebug( "OWaveLanManagementRates()" ); 648 qDebug( "OWaveLanManagementRates()" );
649} 649}
650 650
651 651
652OWaveLanManagementRates::~OWaveLanManagementRates() 652OWaveLanManagementRates::~OWaveLanManagementRates()
653{ 653{
654} 654}
655 655
656/*====================================================================================== 656/*======================================================================================
657 * OWaveLanManagementCF 657 * OWaveLanManagementCF
658 *======================================================================================*/ 658 *======================================================================================*/
659 659
660OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) 660OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent )
661 :QObject( parent, "802.11 CF" ), _data( data ) 661 :QObject( parent, "802.11 CF" ), _data( data )
662{ 662{
663 qDebug( "OWaveLanManagementCF()" ); 663 qDebug( "OWaveLanManagementCF()" );
664} 664}
665 665
666 666
667OWaveLanManagementCF::~OWaveLanManagementCF() 667OWaveLanManagementCF::~OWaveLanManagementCF()
668{ 668{
669} 669}
670 670
671/*====================================================================================== 671/*======================================================================================
672 * OWaveLanManagementFH 672 * OWaveLanManagementFH
673 *======================================================================================*/ 673 *======================================================================================*/
674 674
675OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) 675OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent )
676 :QObject( parent, "802.11 FH" ), _data( data ) 676 :QObject( parent, "802.11 FH" ), _data( data )
677{ 677{
678 qDebug( "OWaveLanManagementFH()" ); 678 qDebug( "OWaveLanManagementFH()" );
679} 679}
680 680
681 681
682OWaveLanManagementFH::~OWaveLanManagementFH() 682OWaveLanManagementFH::~OWaveLanManagementFH()
683{ 683{
684} 684}
685 685
686/*====================================================================================== 686/*======================================================================================
687 * OWaveLanManagementDS 687 * OWaveLanManagementDS
688 *======================================================================================*/ 688 *======================================================================================*/
689 689
690OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) 690OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent )
691 :QObject( parent, "802.11 DS" ), _data( data ) 691 :QObject( parent, "802.11 DS" ), _data( data )
692{ 692{
693 qDebug( "OWaveLanManagementDS()" ); 693 qDebug( "OWaveLanManagementDS()" );
694} 694}
695 695
696 696
697OWaveLanManagementDS::~OWaveLanManagementDS() 697OWaveLanManagementDS::~OWaveLanManagementDS()
698{ 698{
699} 699}
700 700
701 701
702int OWaveLanManagementDS::channel() const 702int OWaveLanManagementDS::channel() const
703{ 703{
704 return _data->channel; 704 return _data->channel;
705} 705}
706 706
707/*====================================================================================== 707/*======================================================================================
708 * OWaveLanManagementTim 708 * OWaveLanManagementTim
709 *======================================================================================*/ 709 *======================================================================================*/
710 710
711OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) 711OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent )
712 :QObject( parent, "802.11 Tim" ), _data( data ) 712 :QObject( parent, "802.11 Tim" ), _data( data )
713{ 713{
714 qDebug( "OWaveLanManagementTim()" ); 714 qDebug( "OWaveLanManagementTim()" );
715} 715}
716 716
717 717
718OWaveLanManagementTim::~OWaveLanManagementTim() 718OWaveLanManagementTim::~OWaveLanManagementTim()
719{ 719{
720} 720}
721 721
722/*====================================================================================== 722/*======================================================================================
723 * OWaveLanManagementIBSS 723 * OWaveLanManagementIBSS
724 *======================================================================================*/ 724 *======================================================================================*/
725 725
726OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) 726OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent )
727 :QObject( parent, "802.11 IBSS" ), _data( data ) 727 :QObject( parent, "802.11 IBSS" ), _data( data )
728{ 728{
729 qDebug( "OWaveLanManagementIBSS()" ); 729 qDebug( "OWaveLanManagementIBSS()" );
730} 730}
731 731
732 732
733OWaveLanManagementIBSS::~OWaveLanManagementIBSS() 733OWaveLanManagementIBSS::~OWaveLanManagementIBSS()
734{ 734{
735} 735}
736 736
737/*====================================================================================== 737/*======================================================================================
738 * OWaveLanManagementChallenge 738 * OWaveLanManagementChallenge
739 *======================================================================================*/ 739 *======================================================================================*/
740 740
741OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) 741OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent )
742 :QObject( parent, "802.11 Challenge" ), _data( data ) 742 :QObject( parent, "802.11 Challenge" ), _data( data )
743{ 743{
744 qDebug( "OWaveLanManagementChallenge()" ); 744 qDebug( "OWaveLanManagementChallenge()" );
745} 745}
746 746
747 747
748OWaveLanManagementChallenge::~OWaveLanManagementChallenge() 748OWaveLanManagementChallenge::~OWaveLanManagementChallenge()
749{ 749{
750} 750}
751 751
752/*====================================================================================== 752/*======================================================================================
753 * OWaveLanDataPacket 753 * OWaveLanDataPacket
754 *======================================================================================*/ 754 *======================================================================================*/
755 755
756OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) 756OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent )
757 :QObject( parent, "802.11 Data" ), _header( data ) 757 :QObject( parent, "802.11 Data" ), _header( data )
758{ 758{
759 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); 759 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." );
760 760
761 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); 761 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header );
762 762
763 #warning The next line works for most cases, but can not be correct generally! 763 #warning The next line works for most cases, but can not be correct generally!
764 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address 764 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address
765 765
766 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); 766 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this );
767} 767}
768 768
769 769
770OWaveLanDataPacket::~OWaveLanDataPacket() 770OWaveLanDataPacket::~OWaveLanDataPacket()
771{ 771{
772} 772}
773 773
774 774
775/*====================================================================================== 775/*======================================================================================
776 * OLLCPacket 776 * OLLCPacket
777 *======================================================================================*/ 777 *======================================================================================*/
778 778
779OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) 779OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent )
780 :QObject( parent, "802.11 LLC" ), _header( data ) 780 :QObject( parent, "802.11 LLC" ), _header( data )
781{ 781{
782 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); 782 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." );
783 783
784 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) 784 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) )
785 { 785 {
786 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 786 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) );
787 787
788 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h 788 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h
789 { 789 {
790 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 790 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
791 case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; 791 case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break;
792 default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 792 default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) );
793 } 793 }
794 794
795 } 795 }
796} 796}
797 797
798 798
799OLLCPacket::~OLLCPacket() 799OLLCPacket::~OLLCPacket()
800{ 800{
801} 801}
802 802
803 803
804/*====================================================================================== 804/*======================================================================================
805 * OWaveLanControlPacket 805 * OWaveLanControlPacket
806 *======================================================================================*/ 806 *======================================================================================*/
807 807
808OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) 808OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent )
809 :QObject( parent, "802.11 Data" ), _header( data ) 809 :QObject( parent, "802.11 Control" ), _header( data )
810{ 810{
811 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); 811 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." );
812 //TODO: Implement this 812 //TODO: Implement this
813} 813}
814 814
815 815
816OWaveLanControlPacket::~OWaveLanControlPacket() 816OWaveLanControlPacket::~OWaveLanControlPacket()
817{ 817{
818} 818}
819 819
820 820
821/*====================================================================================== 821/*======================================================================================
822 * OPacketCapturer 822 * OPacketCapturer
823 *======================================================================================*/ 823 *======================================================================================*/
824 824
825OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) 825OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
826 :QObject( parent, name ), _name( QString::null ), _open( false ), 826 :QObject( parent, name ), _name( QString::null ), _open( false ),
827 _pch( 0 ), _pcd( 0 ), _sn( 0 ) 827 _pch( 0 ), _pcd( 0 ), _sn( 0 )
828{ 828{
829} 829}
830 830
831 831
832OPacketCapturer::~OPacketCapturer() 832OPacketCapturer::~OPacketCapturer()
833{ 833{
834 if ( _open ) 834 if ( _open )
835 { 835 {
836 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); 836 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." );
837 close(); 837 close();
838 } 838 }
839} 839}
840 840
841 841
842void OPacketCapturer::setBlocking( bool b ) 842void OPacketCapturer::setBlocking( bool b )
843{ 843{
844 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) 844 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
845 { 845 {
846 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); 846 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." );
847 } 847 }
848 else 848 else
849 { 849 {
850 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); 850 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf );
851 } 851 }
852} 852}
853 853
854 854
855bool OPacketCapturer::blocking() const 855bool OPacketCapturer::blocking() const
856{ 856{
857 int b = pcap_getnonblock( _pch, _errbuf ); 857 int b = pcap_getnonblock( _pch, _errbuf );
858 if ( b == -1 ) 858 if ( b == -1 )
859 { 859 {
860 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); 860 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf );
861 return -1; 861 return -1;
862 } 862 }
863 return !b; 863 return !b;
864} 864}
865 865
866 866
867void OPacketCapturer::close() 867void OPacketCapturer::close()
868{ 868{
869 if ( _open ) 869 if ( _open )
870 { 870 {
871 if ( _sn ) 871 if ( _sn )
872 { 872 {
873 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 873 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
874 delete _sn; 874 delete _sn;
875 } 875 }
876 if ( _pcd ) 876 if ( _pcd )
877 { 877 {
878 pcap_dump_close( _pcd ); 878 pcap_dump_close( _pcd );
879 _pcd = 0; 879 _pcd = 0;
880 } 880 }
881 pcap_close( _pch ); 881 pcap_close( _pch );
882 _open = false; 882 _open = false;
883 } 883 }
884 884
885 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); 885 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." );
886 qDebug( "--------------------------------------------------" ); 886 qDebug( "--------------------------------------------------" );
887 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) 887 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it )
888 qDebug( "%s : %d", (const char*) it.key(), it.data() ); 888 qDebug( "%s : %d", (const char*) it.key(), it.data() );
889 qDebug( "--------------------------------------------------" ); 889 qDebug( "--------------------------------------------------" );
890 890
891} 891}
892 892
893 893
894int OPacketCapturer::dataLink() const 894int OPacketCapturer::dataLink() const
895{ 895{
896 return pcap_datalink( _pch ); 896 return pcap_datalink( _pch );
897} 897}
898 898
899 899
900int OPacketCapturer::fileno() const 900int OPacketCapturer::fileno() const
901{ 901{
902 if ( _open ) 902 if ( _open )
903 { 903 {
904 return pcap_fileno( _pch ); 904 return pcap_fileno( _pch );
905 } 905 }
906 else 906 else
907 { 907 {
908 return -1; 908 return -1;
909 } 909 }
910} 910}
911 911
912OPacket* OPacketCapturer::next() 912OPacket* OPacketCapturer::next()
913{ 913{
914 packetheaderstruct header; 914 packetheaderstruct header;
915 qDebug( "==> OPacketCapturer::next()" ); 915 qDebug( "==> OPacketCapturer::next()" );
916 const unsigned char* pdata = pcap_next( _pch, &header ); 916 const unsigned char* pdata = pcap_next( _pch, &header );
917 qDebug( "<== OPacketCapturer::next()" ); 917 qDebug( "<== OPacketCapturer::next()" );
918 if ( _pcd ) 918 if ( _pcd )
919 pcap_dump( (u_char*) _pcd, &header, pdata ); 919 pcap_dump( (u_char*) _pcd, &header, pdata );
920 920
921 if ( pdata && header.len ) 921 if ( pdata && header.len )
922 { 922 {
923 OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); 923 OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
924 // packets shouldn't be inserted in the QObject child-parent hierarchy, 924 // packets shouldn't be inserted in the QObject child-parent hierarchy,
925 // because due to memory constraints they will be deleted as soon 925 // because due to memory constraints they will be deleted as soon
926 // as possible - that is right after they have been processed 926 // as possible - that is right after they have been processed
927 // by emit() [ see below ] 927 // by emit() [ see below ]
928 //TODO: make gathering statistics optional, because it takes time 928 //TODO: make gathering statistics optional, because it takes time
929 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); 929 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
930 930
931 return p; 931 return p;
932 } 932 }
933 else 933 else
934 { 934 {
935 qWarning( "OPacketCapturer::next() - no packet received!" ); 935 qWarning( "OPacketCapturer::next() - no packet received!" );
936 return 0; 936 return 0;
937 } 937 }
938} 938}
939 939
940 940
941bool OPacketCapturer::open( const QString& name, const QString& filename ) 941bool OPacketCapturer::open( const QString& name, const QString& filename )
942{ 942{
943 if ( _open ) 943 if ( _open )
944 { 944 {
945 if ( name == _name ) // ignore opening an already openend device 945 if ( name == _name ) // ignore opening an already openend device
946 { 946 {
947 return true; 947 return true;
948 } 948 }
949 else // close the last opened device 949 else // close the last opened device
950 { 950 {
951 close(); 951 close();
952 } 952 }
953 } 953 }
954 954
955 _name = name; 955 _name = name;
956 956
957 // open libpcap 957 // open libpcap
958 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 958 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
959 959
960 if ( !handle ) 960 if ( !handle )
961 { 961 {
962 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 962 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
963 return false; 963 return false;
964 } 964 }
965 965
966 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); 966 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name );
967 _pch = handle; 967 _pch = handle;
968 _open = true; 968 _open = true;
969 _stats.clear(); 969 _stats.clear();
970 970
971 // in case we have an application object, create a socket notifier 971 // in case we have an application object, create a socket notifier
972 if ( qApp ) //TODO: I don't like this here... 972 if ( qApp ) //TODO: I don't like this here...
973 { 973 {
974 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 974 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
975 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 975 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
976 } 976 }
977 977
978 // if requested, open a dump 978 // if requested, open a dump
979 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); 979 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) );
980 if ( !dump ) 980 if ( !dump )
981 { 981 {
982 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); 982 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf );
983 return false; 983 return false;
984 } 984 }
985 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); 985 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename );
986 _pcd = dump; 986 _pcd = dump;
987 987
988 return true; 988 return true;
989} 989}
990 990
991 991
992bool OPacketCapturer::open( const QFile& file ) 992bool OPacketCapturer::open( const QFile& file )
993{ 993{
994 QString name = file.name(); 994 QString name = file.name();
995 995
996 if ( _open ) 996 if ( _open )
997 { 997 {
998 close(); 998 close();
999 if ( name == _name ) // ignore opening an already openend device 999 if ( name == _name ) // ignore opening an already openend device
1000 { 1000 {
1001 return true; 1001 return true;