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
@@ -838,196 +838,202 @@ void OMonitoringInterface::setChannel( int c )
838 838
839 839
840bool OMonitoringInterface::enabled() const 840bool OMonitoringInterface::enabled() const
841{ 841{
842 return _if->monitorMode(); 842 return _if->monitorMode();
843} 843}
844 844
845 845
846void OMonitoringInterface::setEnabled( bool b ) 846void OMonitoringInterface::setEnabled( bool b )
847{ 847{
848} 848}
849 849
850 850
851/*====================================================================================== 851/*======================================================================================
852 * OCiscoMonitoringInterface 852 * OCiscoMonitoringInterface
853 *======================================================================================*/ 853 *======================================================================================*/
854 854
855OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 855OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
856 :OMonitoringInterface( iface, prismHeader ) 856 :OMonitoringInterface( iface, prismHeader )
857{ 857{
858 iface->setMonitoring( this ); 858 iface->setMonitoring( this );
859} 859}
860 860
861 861
862OCiscoMonitoringInterface::~OCiscoMonitoringInterface() 862OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
863{ 863{
864} 864}
865 865
866 866
867void OCiscoMonitoringInterface::setEnabled( bool b ) 867void OCiscoMonitoringInterface::setEnabled( bool b )
868{ 868{
869 QString fname; 869 QString fname;
870 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); 870 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
871 QFile f( fname ); 871 QFile f( fname );
872 if ( !f.exists() ) return; 872 if ( !f.exists() ) return;
873 873
874 if ( f.open( IO_WriteOnly ) ) 874 if ( f.open( IO_WriteOnly ) )
875 { 875 {
876 QTextStream s( &f ); 876 QTextStream s( &f );
877 s << "Mode: r"; 877 s << "Mode: r";
878 s << "Mode: y"; 878 s << "Mode: y";
879 s << "XmitPower: 1"; 879 s << "XmitPower: 1";
880 } 880 }
881 881
882 // flushing and closing will be done automatically when f goes out of scope 882 // flushing and closing will be done automatically when f goes out of scope
883} 883}
884 884
885 885
886QString OCiscoMonitoringInterface::name() const 886QString OCiscoMonitoringInterface::name() const
887{ 887{
888 return "cisco"; 888 return "cisco";
889} 889}
890 890
891 891
892void OCiscoMonitoringInterface::setChannel( int ) 892void OCiscoMonitoringInterface::setChannel( int )
893{ 893{
894 // cisco devices automatically switch channels when in monitor mode 894 // cisco devices automatically switch channels when in monitor mode
895} 895}
896 896
897 897
898/*====================================================================================== 898/*======================================================================================
899 * OWlanNGMonitoringInterface 899 * OWlanNGMonitoringInterface
900 *======================================================================================*/ 900 *======================================================================================*/
901 901
902 902
903OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 903OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
904 :OMonitoringInterface( iface, prismHeader ) 904 :OMonitoringInterface( iface, prismHeader )
905{ 905{
906 iface->setMonitoring( this ); 906 iface->setMonitoring( this );
907} 907}
908 908
909 909
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 )
962 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header 968 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header
963 else 969 else
964 _if->setMode( "managed" ); 970 _if->setMode( "managed" );
965 #else 971 #else
966 int monitorCode = _prismHeader ? 1 : 2; 972 int monitorCode = _prismHeader ? 1 : 2;
967 if ( b ) 973 if ( b )
968 { 974 {
969 _if->setPrivate( "monitor", 1, monitorCode ); 975 _if->setPrivate( "monitor", 1, monitorCode );
970 } 976 }
971 else 977 else
972 { 978 {
973 _if->setPrivate( "monitor", 1, 0 ); 979 _if->setPrivate( "monitor", 1, 0 );
974 } 980 }
975 #endif 981 #endif
976} 982}
977 983
978 984
979QString OHostAPMonitoringInterface::name() const 985QString OHostAPMonitoringInterface::name() const
980{ 986{
981 return "hostap"; 987 return "hostap";
982} 988}
983 989
984 990
985/*====================================================================================== 991/*======================================================================================
986 * OOrinocoNetworkInterface 992 * OOrinocoNetworkInterface
987 *======================================================================================*/ 993 *======================================================================================*/
988 994
989OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 995OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
990 :OMonitoringInterface( iface, prismHeader ) 996 :OMonitoringInterface( iface, prismHeader )
991{ 997{
992 iface->setMonitoring( this ); 998 iface->setMonitoring( this );
993} 999}
994 1000
995 1001
996OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 1002OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
997{ 1003{
998} 1004}
999 1005
1000 1006
1001void OOrinocoMonitoringInterface::setChannel( int c ) 1007void OOrinocoMonitoringInterface::setChannel( int c )
1002{ 1008{
1003 int monitorCode = _prismHeader ? 1 : 2; 1009 int monitorCode = _prismHeader ? 1 : 2;
1004 _if->setPrivate( "monitor", 2, monitorCode, c ); 1010 _if->setPrivate( "monitor", 2, monitorCode, c );
1005} 1011}
1006 1012
1007 1013
1008void OOrinocoMonitoringInterface::setEnabled( bool b ) 1014void OOrinocoMonitoringInterface::setEnabled( bool b )
1009{ 1015{
1010 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 1016 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
1011 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 1017 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
1012 1018
1013 #if WIRELESS_EXT > 14 1019 #if WIRELESS_EXT > 14
1014 if ( b ) 1020 if ( b )
1015 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header 1021 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header
1016 else 1022 else
1017 _if->setMode( "managed" ); 1023 _if->setMode( "managed" );
1018 #else 1024 #else
1019 if ( b ) 1025 if ( b )
1020 { 1026 {
1021 setChannel( 1 ); 1027 setChannel( 1 );
1022 } 1028 }
1023 else 1029 else
1024 { 1030 {
1025 _if->setPrivate( "monitor", 2, 0, 0 ); 1031 _if->setPrivate( "monitor", 2, 0, 0 );
1026 } 1032 }
1027 #endif 1033 #endif
1028} 1034}
1029 1035
1030 1036
1031QString OOrinocoMonitoringInterface::name() const 1037QString OOrinocoMonitoringInterface::name() const
1032{ 1038{
1033 return "orinoco"; 1039 return "orinoco";
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
@@ -1,295 +1,299 @@
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
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 );
68 break; 72 break;
69 73
70 case DLT_PRISM_HEADER: 74 case DLT_PRISM_HEADER:
71 qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" ); 75 qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" );
72 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); 76 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this );
73 break; 77 break;
74 78
75 default: 79 default:
76 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink (type %d)!", datalink ); 80 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink (type %d)!", datalink );
77 } 81 }
78} 82}
79 83
80 84
81OPacket::~OPacket() 85OPacket::~OPacket()
82{ 86{
83} 87}
84 88
85 89
86timevalstruct OPacket::timeval() const 90timevalstruct OPacket::timeval() const
87{ 91{
88 return _hdr.ts; 92 return _hdr.ts;
89} 93}
90 94
91 95
92int OPacket::caplen() const 96int OPacket::caplen() const
93{ 97{
94 return _hdr.caplen; 98 return _hdr.caplen;
95} 99}
96 100
97 101
98void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) 102void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l )
99{ 103{
100 if (!l) return; 104 if (!l) return;
101 QObject* o = l->first(); 105 QObject* o = l->first();
102 while ( o ) 106 while ( o )
103 { 107 {
104 stats[o->name()]++; 108 stats[o->name()]++;
105 updateStats( stats, const_cast<QObjectList*>( o->children() ) ); 109 updateStats( stats, const_cast<QObjectList*>( o->children() ) );
106 o = l->next(); 110 o = l->next();
107 } 111 }
108} 112}
109 113
110 114
111void OPacket::dumpStructure( QObjectList* l ) 115void OPacket::dumpStructure( QObjectList* l )
112{ 116{
113 QString packetString( "[ |" + _dumpStructure( l ) + " ]" ); 117 QString packetString( "[ |" + _dumpStructure( l ) + " ]" );
114 qDebug( "OPacket::dumpStructure: %s", (const char*) packetString ); 118 qDebug( "OPacket::dumpStructure: %s", (const char*) packetString );
115} 119}
116 120
117 121
118QString OPacket::_dumpStructure( QObjectList* l ) 122QString OPacket::_dumpStructure( QObjectList* l )
119{ 123{
120 if (!l) return QString::null; 124 if (!l) return QString::null;
121 QObject* o = l->first(); 125 QObject* o = l->first();
122 QString str(" "); 126 QString str(" ");
123 127
124 while ( o ) 128 while ( o )
125 { 129 {
126 str.append( o->name() ); 130 str.append( o->name() );
127 str.append( " |" ); 131 str.append( " |" );
128 str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); 132 str += _dumpStructure( const_cast<QObjectList*>( o->children() ) );
129 o = l->next(); 133 o = l->next();
130 } 134 }
131 return str; 135 return str;
132} 136}
133 137
134QString OPacket::dump( int bpl ) const 138QString OPacket::dump( int bpl ) const
135{ 139{
136 static int index = 0; 140 static int index = 0;
137 index++; 141 index++;
138 int len = _hdr.caplen; 142 int len = _hdr.caplen;
139 QString str; 143 QString str;
140 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); 144 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len );
141 str.append( "0000: " ); 145 str.append( "0000: " );
142 QString tmp; 146 QString tmp;
143 QString bytes; 147 QString bytes;
144 QString chars; 148 QString chars;
145 149
146 for ( int i = 0; i < len; ++i ) 150 for ( int i = 0; i < len; ++i )
147 { 151 {
148 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); 152 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp );
149 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); 153 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] );
150 else chars.append( '.' ); 154 else chars.append( '.' );
151 155
152 if ( !((i+1) % bpl) ) 156 if ( !((i+1) % bpl) )
153 { 157 {
154 str.append( bytes ); 158 str.append( bytes );
155 str.append( ' ' ); 159 str.append( ' ' );
156 str.append( chars ); 160 str.append( chars );
157 str.append( '\n' ); 161 str.append( '\n' );
158 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); 162 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp );
159 bytes = ""; 163 bytes = "";
160 chars = ""; 164 chars = "";
161 } 165 }
162 166
163 } 167 }
164 if ( (len % bpl) ) 168 if ( (len % bpl) )
165 { 169 {
166 str.append( bytes.leftJustify( 1 + 3*bpl ) ); 170 str.append( bytes.leftJustify( 1 + 3*bpl ) );
167 str.append( chars ); 171 str.append( chars );
168 } 172 }
169 str.append( '\n' ); 173 str.append( '\n' );
170 return str; 174 return str;
171} 175}
172 176
173 177
174int OPacket::len() const 178int 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
224{ 228{
225 return ntohs( _ether->ether_type ); 229 return ntohs( _ether->ether_type );
226} 230}
227 231
228 232
229/*====================================================================================== 233/*======================================================================================
230 * OIPPacket 234 * OIPPacket
231 *======================================================================================*/ 235 *======================================================================================*/
232 236
233 237
234OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) 238OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent )
235 :QObject( parent, "IP" ), _iphdr( data ) 239 :QObject( parent, "IP" ), _iphdr( data )
236{ 240{
237 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); 241 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." );
238 242
239 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); 243 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) );
240 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); 244 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) );
241 245
242 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); 246 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() );
243 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); 247 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() );
244 248
245 switch ( protocol() ) 249 switch ( protocol() )
246 { 250 {
247 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; 251 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break;
248 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; 252 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break;
249 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); 253 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() );
250 } 254 }
251 255
252} 256}
253 257
254OIPPacket::~OIPPacket() 258OIPPacket::~OIPPacket()
255{ 259{
256} 260}
257 261
258 262
259QHostAddress OIPPacket::fromIPAddress() const 263QHostAddress OIPPacket::fromIPAddress() const
260{ 264{
261 return EXTRACT_32BITS( &_iphdr->saddr ); 265 return EXTRACT_32BITS( &_iphdr->saddr );
262} 266}
263 267
264 268
265QHostAddress OIPPacket::toIPAddress() const 269QHostAddress OIPPacket::toIPAddress() const
266{ 270{
267 return EXTRACT_32BITS( &_iphdr->saddr ); 271 return EXTRACT_32BITS( &_iphdr->saddr );
268} 272}
269 273
270 274
271int OIPPacket::tos() const 275int OIPPacket::tos() const
272{ 276{
273 return _iphdr->tos; 277 return _iphdr->tos;
274} 278}
275 279
276 280
277int OIPPacket::len() const 281int OIPPacket::len() const
278{ 282{
279 return EXTRACT_16BITS( &_iphdr->tot_len ); 283 return EXTRACT_16BITS( &_iphdr->tot_len );
280} 284}
281 285
282 286
283int OIPPacket::id() const 287int OIPPacket::id() const
284{ 288{
285 return EXTRACT_16BITS( &_iphdr->id ); 289 return EXTRACT_16BITS( &_iphdr->id );
286} 290}
287 291
288 292
289int OIPPacket::offset() const 293int OIPPacket::offset() const
290{ 294{
291 return EXTRACT_16BITS( &_iphdr->frag_off ); 295 return EXTRACT_16BITS( &_iphdr->frag_off );
292} 296}
293 297
294 298
295int OIPPacket::ttl() const 299int OIPPacket::ttl() const
@@ -1037,192 +1041,209 @@ OPacketCapturer::~OPacketCapturer()
1037{ 1041{
1038 if ( _open ) 1042 if ( _open )
1039 { 1043 {
1040 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); 1044 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." );
1041 close(); 1045 close();
1042 } 1046 }
1043} 1047}
1044 1048
1045 1049
1046void OPacketCapturer::setBlocking( bool b ) 1050void OPacketCapturer::setBlocking( bool b )
1047{ 1051{
1048 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) 1052 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
1049 { 1053 {
1050 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); 1054 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." );
1051 } 1055 }
1052 else 1056 else
1053 { 1057 {
1054 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); 1058 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf );
1055 } 1059 }
1056} 1060}
1057 1061
1058 1062
1059bool OPacketCapturer::blocking() const 1063bool OPacketCapturer::blocking() const
1060{ 1064{
1061 int b = pcap_getnonblock( _pch, _errbuf ); 1065 int b = pcap_getnonblock( _pch, _errbuf );
1062 if ( b == -1 ) 1066 if ( b == -1 )
1063 { 1067 {
1064 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); 1068 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf );
1065 return -1; 1069 return -1;
1066 } 1070 }
1067 return !b; 1071 return !b;
1068} 1072}
1069 1073
1070 1074
1071void OPacketCapturer::closeDumpFile() 1075void OPacketCapturer::closeDumpFile()
1072{ 1076{
1073 if ( _pcd ) 1077 if ( _pcd )
1074 { 1078 {
1075 pcap_dump_close( _pcd ); 1079 pcap_dump_close( _pcd );
1076 _pcd = 0; 1080 _pcd = 0;
1077 } 1081 }
1078 pcap_close( _pch ); 1082 pcap_close( _pch );
1079} 1083}
1080 1084
1081 1085
1082void OPacketCapturer::close() 1086void OPacketCapturer::close()
1083{ 1087{
1084 if ( _open ) 1088 if ( _open )
1085 { 1089 {
1086 if ( _sn ) 1090 if ( _sn )
1087 { 1091 {
1088 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1092 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1089 delete _sn; 1093 delete _sn;
1090 } 1094 }
1091 closeDumpFile(); 1095 closeDumpFile();
1092 _open = false; 1096 _open = false;
1093 } 1097 }
1094 1098
1095 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); 1099 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." );
1096 qDebug( "--------------------------------------------------" ); 1100 qDebug( "--------------------------------------------------" );
1097 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) 1101 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it )
1098 qDebug( "%s : %d", (const char*) it.key(), it.data() ); 1102 qDebug( "%s : %d", (const char*) it.key(), it.data() );
1099 qDebug( "--------------------------------------------------" ); 1103 qDebug( "--------------------------------------------------" );
1100 1104
1101} 1105}
1102 1106
1103 1107
1104int OPacketCapturer::dataLink() const 1108int OPacketCapturer::dataLink() const
1105{ 1109{
1106 return pcap_datalink( _pch ); 1110 return pcap_datalink( _pch );
1107} 1111}
1108 1112
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!" );
1157 return 0; 1178 return 0;
1158 } 1179 }
1159} 1180}
1160 1181
1161 1182
1162bool OPacketCapturer::open( const QString& name ) 1183bool OPacketCapturer::open( const QString& name )
1163{ 1184{
1164 if ( _open ) 1185 if ( _open )
1165 { 1186 {
1166 if ( name == _name ) // ignore opening an already openend device 1187 if ( name == _name ) // ignore opening an already openend device
1167 { 1188 {
1168 return true; 1189 return true;
1169 } 1190 }
1170 else // close the last opened device 1191 else // close the last opened device
1171 { 1192 {
1172 close(); 1193 close();
1173 } 1194 }
1174 } 1195 }
1175 1196
1176 _name = name; 1197 _name = name;
1177 1198
1178 // open libpcap 1199 // open libpcap
1179 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 1200 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
1180 1201
1181 if ( !handle ) 1202 if ( !handle )
1182 { 1203 {
1183 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 1204 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
1184 return false; 1205 return false;
1185 } 1206 }
1186 1207
1187 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); 1208 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name );
1188 _pch = handle; 1209 _pch = handle;
1189 _open = true; 1210 _open = true;
1190 _stats.clear(); 1211 _stats.clear();
1191 1212
1192 // in case we have an application object, create a socket notifier 1213 // in case we have an application object, create a socket notifier
1193 if ( qApp ) //TODO: I don't like this here... 1214 if ( qApp ) //TODO: I don't like this here...
1194 { 1215 {
1195 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 1216 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
1196 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1217 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1197 } 1218 }
1198 1219
1199 return true; 1220 return true;
1200} 1221}
1201 1222
1202 1223
1203bool OPacketCapturer::openDumpFile( const QString& filename ) 1224bool OPacketCapturer::openDumpFile( const QString& filename )
1204{ 1225{
1205 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); 1226 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) );
1206 if ( !dump ) 1227 if ( !dump )
1207 { 1228 {
1208 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); 1229 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf );
1209 return false; 1230 return false;
1210 } 1231 }
1211 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); 1232 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename );
1212 _pcd = dump; 1233 _pcd = dump;
1213 1234
1214 return true; 1235 return true;
1215} 1236}
1216 1237
1217 1238
1218bool OPacketCapturer::open( const QFile& file ) 1239bool OPacketCapturer::open( const QFile& file )
1219{ 1240{
1220 QString name = file.name(); 1241 QString name = file.name();
1221 1242
1222 if ( _open ) 1243 if ( _open )
1223 { 1244 {
1224 close(); 1245 close();
1225 if ( name == _name ) // ignore opening an already openend device 1246 if ( name == _name ) // ignore opening an already openend device
1226 { 1247 {
1227 return true; 1248 return true;
1228 } 1249 }
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
@@ -512,151 +512,156 @@ class ODHCPPacket : public QObject
512 OMacAddress clientMacAddress() const; 512 OMacAddress clientMacAddress() const;
513 513
514 bool isRequest() const; 514 bool isRequest() const;
515 bool isReply() const; 515 bool isReply() const;
516 QString type() const; 516 QString type() const;
517 517
518 private: 518 private:
519 const struct dhcp_packet* _dhcphdr; 519 const struct dhcp_packet* _dhcphdr;
520 unsigned char _type; 520 unsigned char _type;
521}; 521};
522 522
523/*====================================================================================== 523/*======================================================================================
524 * OTCPPacket 524 * OTCPPacket
525 *======================================================================================*/ 525 *======================================================================================*/
526 526
527class OTCPPacket : public QObject 527class OTCPPacket : public QObject
528{ 528{
529 Q_OBJECT 529 Q_OBJECT
530 530
531 public: 531 public:
532 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); 532 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 );
533 virtual ~OTCPPacket(); 533 virtual ~OTCPPacket();
534 534
535 int fromPort() const; 535 int fromPort() const;
536 int toPort() const; 536 int toPort() const;
537 int seq() const; 537 int seq() const;
538 int ack() const; 538 int ack() const;
539 int window() const; 539 int window() const;
540 int checksum() const; 540 int checksum() const;
541 541
542 private: 542 private:
543 const struct tcphdr* _tcphdr; 543 const struct tcphdr* _tcphdr;
544}; 544};
545 545
546 546
547/*====================================================================================== 547/*======================================================================================
548 * OPacketCapturer 548 * OPacketCapturer
549 *======================================================================================*/ 549 *======================================================================================*/
550 550
551/** 551/**
552 * @brief A class based wrapper for network packet capturing. 552 * @brief A class based wrapper for network packet capturing.
553 * 553 *
554 * This class is the base of a high-level interface to the well known packet capturing 554 * This class is the base of a high-level interface to the well known packet capturing
555 * library libpcap. 555 * library libpcap.
556 * @see http://tcpdump.org 556 * @see http://tcpdump.org
557 */ 557 */
558class OPacketCapturer : public QObject 558class OPacketCapturer : public QObject
559{ 559{
560 Q_OBJECT 560 Q_OBJECT
561 561
562 public: 562 public:
563 /** 563 /**
564 * Constructor. 564 * Constructor.
565 */ 565 */
566 OPacketCapturer( QObject* parent = 0, const char* name = 0 ); 566 OPacketCapturer( QObject* parent = 0, const char* name = 0 );
567 /** 567 /**
568 * Destructor. 568 * Destructor.
569 */ 569 */
570 ~OPacketCapturer(); 570 ~OPacketCapturer();
571 /** 571 /**
572 * Set the packet capturer to use blocking or non-blocking IO. This can be useful when 572 * Set the packet capturer to use blocking or non-blocking IO. This can be useful when
573 * not using the socket notifier, e.g. without an application object. 573 * not using the socket notifier, e.g. without an application object.
574 */ 574 */
575 void setBlocking( bool ); 575 void setBlocking( bool );
576 /** 576 /**
577 * @returns true if the packet capturer uses blocking IO calls. 577 * @returns true if the packet capturer uses blocking IO calls.
578 */ 578 */
579 bool blocking() const; 579 bool blocking() const;
580 /** 580 /**
581 * Close the packet capturer. This is automatically done in the destructor. 581 * Close the packet capturer. This is automatically done in the destructor.
582 */ 582 */
583 void close(); 583 void close();
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;
632 /** 637 /**
633 * @returns the libpcap version string used to write the input capture file. 638 * @returns the libpcap version string used to write the input capture file.
634 */ 639 */
635 QString version() const; 640 QString version() const;
636 /** 641 /**
637 * @returns the packet statistic database. 642 * @returns the packet statistic database.
638 * @see QMap 643 * @see QMap
639 */ 644 */
640 const QMap<QString,int>& statistics() const; 645 const QMap<QString,int>& statistics() const;
641 646
642 signals: 647 signals:
643 /** 648 /**
644 * This signal is emitted, when a packet has been received. 649 * This signal is emitted, when a packet has been received.
645 */ 650 */
646 void receivedPacket( OPacket* ); 651 void receivedPacket( OPacket* );
647 652
648 protected slots: 653 protected slots:
649 void readyToReceive(); 654 void readyToReceive();
650 655
651 protected: 656 protected:
652 QString _name; // devicename 657 QString _name; // devicename
653 bool _open; // check this before doing pcap calls 658 bool _open; // check this before doing pcap calls
654 pcap_t* _pch; // pcap library handle 659 pcap_t* _pch; // pcap library handle
655 pcap_dumper_t* _pcd; // pcap dumper handle 660 pcap_dumper_t* _pcd; // pcap dumper handle
656 QSocketNotifier* _sn; // socket notifier for main loop 661 QSocketNotifier* _sn; // socket notifier for main loop
657 mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap 662 mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap
658 QMap<QString, int> _stats; // statistics; 663 QMap<QString, int> _stats; // statistics;
659}; 664};
660 665
661#endif // OPCAP_H 666#endif // OPCAP_H
662 667