summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-10-09 00:03:06 (UTC)
committer mickeyl <mickeyl>2003-10-09 00:03:06 (UTC)
commitf8d08db59ac05f5bf2f56e6ebf69c28dfbe8b13e (patch) (unidiff)
tree36059d71abfcdb73748c1941fb9458dc75e0d4a8
parent5517443d9ebe96ff9c30d91b2254418964d5c410 (diff)
downloadopie-f8d08db59ac05f5bf2f56e6ebf69c28dfbe8b13e.zip
opie-f8d08db59ac05f5bf2f56e6ebf69c28dfbe8b13e.tar.gz
opie-f8d08db59ac05f5bf2f56e6ebf69c28dfbe8b13e.tar.bz2
- catch up with changed sniffing behaviour in newer wlan-ng *puke* drivers
- new API: OPacketCapturer::next( int time )
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp12
-rw-r--r--libopie2/opienet/opcap.cpp27
-rw-r--r--libopie2/opienet/opcap.h5
3 files changed, 38 insertions, 6 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 1f529d2..45ee4c0 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -910,52 +910,58 @@ OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface
910OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() 910OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
911{ 911{
912} 912}
913 913
914 914
915void OWlanNGMonitoringInterface::setEnabled( bool b ) 915void OWlanNGMonitoringInterface::setEnabled( bool b )
916{ 916{
917 //FIXME: do nothing if its already in the same mode 917 //FIXME: do nothing if its already in the same mode
918 918
919 QString enable = b ? "true" : "false"; 919 QString enable = b ? "true" : "false";
920 QString prism = _prismHeader ? "true" : "false"; 920 QString prism = _prismHeader ? "true" : "false";
921 QString cmd; 921 QString cmd;
922 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", 922 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
923 (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); 923 (const char*) _if->name(), 1, (const char*) enable, (const char*) prism );
924 system( cmd ); 924 system( cmd );
925} 925}
926 926
927 927
928QString OWlanNGMonitoringInterface::name() const 928QString OWlanNGMonitoringInterface::name() const
929{ 929{
930 return "wlan-ng"; 930 return "wlan-ng";
931} 931}
932 932
933 933
934void OWlanNGMonitoringInterface::setChannel( int ) 934void OWlanNGMonitoringInterface::setChannel( int c )
935{ 935{
936 // wlan-ng devices automatically switch channels when in monitor mode 936 //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't.
937 // NOTE: The above note no longer seems to be true for recent driver versions! 937
938 QString enable = "true"; //_if->monitorMode() ? "true" : "false";
939 QString prism = _prismHeader ? "true" : "false";
940 QString cmd;
941 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
942 (const char*) _if->name(), c+1, (const char*) enable, (const char*) prism );
943 system( cmd );
938} 944}
939 945
940 946
941/*====================================================================================== 947/*======================================================================================
942 * OHostAPMonitoringInterface 948 * OHostAPMonitoringInterface
943 *======================================================================================*/ 949 *======================================================================================*/
944 950
945OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 951OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
946 :OMonitoringInterface( iface, prismHeader ) 952 :OMonitoringInterface( iface, prismHeader )
947{ 953{
948 iface->setMonitoring( this ); 954 iface->setMonitoring( this );
949} 955}
950 956
951OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 957OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
952{ 958{
953} 959}
954 960
955void OHostAPMonitoringInterface::setEnabled( bool b ) 961void OHostAPMonitoringInterface::setEnabled( bool b )
956{ 962{
957 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 963 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
958 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 964 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
959 965
960 #if WIRELESS_EXT > 14 966 #if WIRELESS_EXT > 14
961 if ( b ) 967 if ( b )
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 9ed2b83..38ca1a1 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -11,57 +11,61 @@
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
36#include <opie2/opcap.h> 35#include <opie2/opcap.h>
37 36
38/* QT */ 37/* QT */
39
40#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) 38#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects)
41#include <qsocketnotifier.h> 39#include <qsocketnotifier.h>
42#include <qobjectlist.h> 40#include <qobjectlist.h>
43 41
42/* SYSTEM */
43#include <sys/time.h>
44#include <sys/types.h>
45#include <unistd.h>
46
47/* LOCAL */
44#include "udp_ports.h" 48#include "udp_ports.h"
45 49
46/*====================================================================================== 50/*======================================================================================
47 * OPacket 51 * OPacket
48 *======================================================================================*/ 52 *======================================================================================*/
49 53
50OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) 54OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent )
51 :QObject( parent, "Generic" ), _hdr( header ), _data( data ) 55 :QObject( parent, "Generic" ), _hdr( header ), _data( data )
52{ 56{
53 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); 57 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
54 58
55 _end = (unsigned char*) data + header.len; 59 _end = (unsigned char*) data + header.len;
56 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); 60 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end );
57 61
58 switch ( datalink ) 62 switch ( datalink )
59 { 63 {
60 case DLT_EN10MB: 64 case DLT_EN10MB:
61 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); 65 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" );
62 new OEthernetPacket( _end, (const struct ether_header*) data, this ); 66 new OEthernetPacket( _end, (const struct ether_header*) data, this );
63 break; 67 break;
64 68
65 case DLT_IEEE802_11: 69 case DLT_IEEE802_11:
66 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); 70 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" );
67 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); 71 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this );
@@ -175,49 +179,49 @@ int OPacket::len() const
175{ 179{
176 return _hdr.len; 180 return _hdr.len;
177} 181}
178 182
179 183
180/*====================================================================================== 184/*======================================================================================
181 * OEthernetPacket 185 * OEthernetPacket
182 *======================================================================================*/ 186 *======================================================================================*/
183 187
184OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) 188OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
185 :QObject( parent, "Ethernet" ), _ether( data ) 189 :QObject( parent, "Ethernet" ), _ether( data )
186{ 190{
187 191
188 qDebug( "Source = %s", (const char*) sourceAddress().toString() ); 192 qDebug( "Source = %s", (const char*) sourceAddress().toString() );
189 qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); 193 qDebug( "Destination = %s", (const char*) destinationAddress().toString() );
190 194
191 if ( sourceAddress() == OMacAddress::broadcast ) 195 if ( sourceAddress() == OMacAddress::broadcast )
192 qDebug( "Source is broadcast address" ); 196 qDebug( "Source is broadcast address" );
193 if ( destinationAddress() == OMacAddress::broadcast ) 197 if ( destinationAddress() == OMacAddress::broadcast )
194 qDebug( "Destination is broadcast address" ); 198 qDebug( "Destination is broadcast address" );
195 199
196 switch ( type() ) 200 switch ( type() )
197 { 201 {
198 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 202 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
199 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } 203 case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break;
200 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } 204 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; }
201 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); 205 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" );
202 } 206 }
203 207
204} 208}
205 209
206 210
207OEthernetPacket::~OEthernetPacket() 211OEthernetPacket::~OEthernetPacket()
208{ 212{
209} 213}
210 214
211 215
212OMacAddress OEthernetPacket::sourceAddress() const 216OMacAddress OEthernetPacket::sourceAddress() const
213{ 217{
214 return OMacAddress( _ether->ether_shost ); 218 return OMacAddress( _ether->ether_shost );
215} 219}
216 220
217 221
218OMacAddress OEthernetPacket::destinationAddress() const 222OMacAddress OEthernetPacket::destinationAddress() const
219{ 223{
220 return OMacAddress( _ether->ether_dhost ); 224 return OMacAddress( _ether->ether_dhost );
221} 225}
222 226
223int OEthernetPacket::type() const 227int OEthernetPacket::type() const
@@ -1109,48 +1113,65 @@ int OPacketCapturer::dataLink() const
1109 1113
1110void OPacketCapturer::dump( OPacket* p ) 1114void OPacketCapturer::dump( OPacket* p )
1111{ 1115{
1112 if ( !_pcd ) 1116 if ( !_pcd )
1113 { 1117 {
1114 qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" ); 1118 qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" );
1115 return; 1119 return;
1116 } 1120 }
1117 pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data ); 1121 pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data );
1118} 1122}
1119 1123
1120 1124
1121int OPacketCapturer::fileno() const 1125int OPacketCapturer::fileno() const
1122{ 1126{
1123 if ( _open ) 1127 if ( _open )
1124 { 1128 {
1125 return pcap_fileno( _pch ); 1129 return pcap_fileno( _pch );
1126 } 1130 }
1127 else 1131 else
1128 { 1132 {
1129 return -1; 1133 return -1;
1130 } 1134 }
1131} 1135}
1132 1136
1137
1138OPacket* OPacketCapturer::next( int time )
1139{
1140 fd_set fds;
1141 struct timeval tv;
1142 FD_ZERO( &fds );
1143 FD_SET( pcap_fileno( _pch ), &fds );
1144 tv.tv_sec = time / 1000;
1145 tv.tv_usec = time % 1000;
1146 int retval = select( 1, &fds, NULL, NULL, &tv);
1147 if ( retval > 0 ) // clear to read!
1148 return next();
1149 else
1150 return 0;
1151}
1152
1153
1133OPacket* OPacketCapturer::next() 1154OPacket* OPacketCapturer::next()
1134{ 1155{
1135 packetheaderstruct header; 1156 packetheaderstruct header;
1136 qDebug( "==> OPacketCapturer::next()" ); 1157 qDebug( "==> OPacketCapturer::next()" );
1137 const unsigned char* pdata = pcap_next( _pch, &header ); 1158 const unsigned char* pdata = pcap_next( _pch, &header );
1138 qDebug( "<== OPacketCapturer::next()" ); 1159 qDebug( "<== OPacketCapturer::next()" );
1139 1160
1140 if ( pdata && header.len ) 1161 if ( pdata && header.len )
1141 { 1162 {
1142 OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); 1163 OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
1143 // packets shouldn't be inserted in the QObject child-parent hierarchy, 1164 // packets shouldn't be inserted in the QObject child-parent hierarchy,
1144 // because due to memory constraints they will be deleted as soon 1165 // because due to memory constraints they will be deleted as soon
1145 // as possible - that is right after they have been processed 1166 // as possible - that is right after they have been processed
1146 // by emit() [ see below ] 1167 // by emit() [ see below ]
1147 //TODO: make gathering statistics optional, because it takes time 1168 //TODO: make gathering statistics optional, because it takes time
1148 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); 1169 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
1149 #ifndef NODEBUG 1170 #ifndef NODEBUG
1150 p->dumpStructure( const_cast<QObjectList*>( p->children() ) ); 1171 p->dumpStructure( const_cast<QObjectList*>( p->children() ) );
1151 #endif 1172 #endif
1152 return p; 1173 return p;
1153 } 1174 }
1154 else 1175 else
1155 { 1176 {
1156 qWarning( "OPacketCapturer::next() - no packet received!" ); 1177 qWarning( "OPacketCapturer::next() - no packet received!" );
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h
index 51f067a..54b256b 100644
--- a/libopie2/opienet/opcap.h
+++ b/libopie2/opienet/opcap.h
@@ -584,48 +584,53 @@ class OPacketCapturer : public QObject
584 /** 584 /**
585 * Close the output capture file. 585 * Close the output capture file.
586 */ 586 */
587 void closeDumpFile(); 587 void closeDumpFile();
588 /** 588 /**
589 * @returns the data link type. 589 * @returns the data link type.
590 * @see <pcap.h> for possible values. 590 * @see <pcap.h> for possible values.
591 */ 591 */
592 int dataLink() const; 592 int dataLink() const;
593 /** 593 /**
594 * Dump a packet to the output capture file. 594 * Dump a packet to the output capture file.
595 */ 595 */
596 void dump( OPacket* ); 596 void dump( OPacket* );
597 /** 597 /**
598 * @returns the file descriptor of the packet capturer. This is only useful, if 598 * @returns the file descriptor of the packet capturer. This is only useful, if
599 * not using the socket notifier, e.g. without an application object. 599 * not using the socket notifier, e.g. without an application object.
600 */ 600 */
601 int fileno() const; 601 int fileno() const;
602 /** 602 /**
603 * @returns the next @ref OPacket from the packet capturer. 603 * @returns the next @ref OPacket from the packet capturer.
604 * @note If blocking mode is true then this call might block. 604 * @note If blocking mode is true then this call might block.
605 */ 605 */
606 OPacket* next(); 606 OPacket* next();
607 /** 607 /**
608 * @returns the next @ref OPacket from the packet capturer, if
609 * one arrives within @a time milliseconds.
610 */
611 OPacket* next( int time );
612 /**
608 * Open the packet capturer to capture packets in live-mode from @a interface. 613 * Open the packet capturer to capture packets in live-mode from @a interface.
609 */ 614 */
610 bool open( const QString& interface ); 615 bool open( const QString& interface );
611 /** 616 /**
612 * Open the packet capturer to capture packets in offline-mode from @a file. 617 * Open the packet capturer to capture packets in offline-mode from @a file.
613 */ 618 */
614 bool open( const QFile& file ); 619 bool open( const QFile& file );
615 /** 620 /**
616 * Open a prerecorded tcpdump compatible capture file for use with @ref dump() 621 * Open a prerecorded tcpdump compatible capture file for use with @ref dump()
617 */ 622 */
618 bool openDumpFile( const QString& filename ); 623 bool openDumpFile( const QString& filename );
619 /** 624 /**
620 * @returns true if the packet capturer is open 625 * @returns true if the packet capturer is open
621 */ 626 */
622 bool isOpen() const; 627 bool isOpen() const;
623 /** 628 /**
624 * @returns the snapshot length of this packet capturer 629 * @returns the snapshot length of this packet capturer
625 */ 630 */
626 int snapShot() const; 631 int snapShot() const;
627 /** 632 /**
628 * @returns true if the input capture file has a different byte-order 633 * @returns true if the input capture file has a different byte-order
629 * than the byte-order of the running system. 634 * than the byte-order of the running system.
630 */ 635 */
631 bool swapped() const; 636 bool swapped() const;