-rw-r--r-- | libopie2/opienet/onetwork.cpp | 31 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 11 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 2 |
3 files changed, 25 insertions, 19 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 2dfff1d..6cef5cf 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -1,1008 +1,1013 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 by the Wellenreiter team: | 3 | Copyright (C) 2003 by the Wellenreiter team: |
4 | Martin J. Muench <mjm@remote-exploit.org> | 4 | Martin J. Muench <mjm@remote-exploit.org> |
5 | Max Moser <mmo@remote-exploit.org | 5 | Max Moser <mmo@remote-exploit.org |
6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | 35 | ||
36 | #include <opie2/onetwork.h> | 36 | #include <opie2/onetwork.h> |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | 39 | ||
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | 42 | ||
43 | /* UNIX */ | 43 | /* UNIX */ |
44 | 44 | ||
45 | #include <assert.h> | 45 | #include <assert.h> |
46 | #include <arpa/inet.h> | 46 | #include <arpa/inet.h> |
47 | #include <cerrno> | 47 | #include <cerrno> |
48 | #include <cstring> | 48 | #include <cstring> |
49 | #include <cstdlib> | 49 | #include <cstdlib> |
50 | #include <math.h> | 50 | #include <math.h> |
51 | #include <sys/ioctl.h> | 51 | #include <sys/ioctl.h> |
52 | #include <sys/socket.h> | 52 | #include <sys/socket.h> |
53 | #include <sys/types.h> | 53 | #include <sys/types.h> |
54 | #include <unistd.h> | 54 | #include <unistd.h> |
55 | #include <linux/sockios.h> | 55 | #include <linux/sockios.h> |
56 | #include <net/if_arp.h> | 56 | #include <net/if_arp.h> |
57 | #include <stdarg.h> | 57 | #include <stdarg.h> |
58 | 58 | ||
59 | using namespace std; | 59 | using namespace std; |
60 | 60 | ||
61 | /*====================================================================================== | 61 | /*====================================================================================== |
62 | * ONetwork | 62 | * ONetwork |
63 | *======================================================================================*/ | 63 | *======================================================================================*/ |
64 | 64 | ||
65 | ONetwork* ONetwork::_instance = 0; | 65 | ONetwork* ONetwork::_instance = 0; |
66 | 66 | ||
67 | ONetwork::ONetwork() | 67 | ONetwork::ONetwork() |
68 | { | 68 | { |
69 | qDebug( "ONetwork::ONetwork()" ); | 69 | qDebug( "ONetwork::ONetwork()" ); |
70 | synchronize(); | 70 | synchronize(); |
71 | } | 71 | } |
72 | 72 | ||
73 | void ONetwork::synchronize() | 73 | void ONetwork::synchronize() |
74 | { | 74 | { |
75 | // gather available interfaces by inspecting /proc/net/dev | 75 | // gather available interfaces by inspecting /proc/net/dev |
76 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 76 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
77 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | 77 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices |
78 | 78 | ||
79 | _interfaces.clear(); | 79 | _interfaces.clear(); |
80 | QString str; | 80 | QString str; |
81 | QFile f( "/proc/net/dev" ); | 81 | QFile f( "/proc/net/dev" ); |
82 | bool hasFile = f.open( IO_ReadOnly ); | 82 | bool hasFile = f.open( IO_ReadOnly ); |
83 | if ( !hasFile ) | 83 | if ( !hasFile ) |
84 | { | 84 | { |
85 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); | 85 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); |
86 | return; | 86 | return; |
87 | } | 87 | } |
88 | QTextStream s( &f ); | 88 | QTextStream s( &f ); |
89 | s.readLine(); | 89 | s.readLine(); |
90 | s.readLine(); | 90 | s.readLine(); |
91 | while ( !s.atEnd() ) | 91 | while ( !s.atEnd() ) |
92 | { | 92 | { |
93 | s >> str; | 93 | s >> str; |
94 | str.truncate( str.find( ':' ) ); | 94 | str.truncate( str.find( ':' ) ); |
95 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); | 95 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); |
96 | ONetworkInterface* iface; | 96 | ONetworkInterface* iface; |
97 | if ( isWirelessInterface( str ) ) | 97 | if ( isWirelessInterface( str ) ) |
98 | { | 98 | { |
99 | iface = new OWirelessNetworkInterface( this, (const char*) str ); | 99 | iface = new OWirelessNetworkInterface( this, (const char*) str ); |
100 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); | 100 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); |
101 | } | 101 | } |
102 | else | 102 | else |
103 | { | 103 | { |
104 | iface = new ONetworkInterface( this, (const char*) str ); | 104 | iface = new ONetworkInterface( this, (const char*) str ); |
105 | } | 105 | } |
106 | _interfaces.insert( str, iface ); | 106 | _interfaces.insert( str, iface ); |
107 | s.readLine(); | 107 | s.readLine(); |
108 | } | 108 | } |
109 | } | 109 | } |
110 | 110 | ||
111 | 111 | ||
112 | int ONetwork::count() const | 112 | int ONetwork::count() const |
113 | { | 113 | { |
114 | return _interfaces.count(); | 114 | return _interfaces.count(); |
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
118 | ONetworkInterface* ONetwork::interface( const QString& iface ) const | 118 | ONetworkInterface* ONetwork::interface( const QString& iface ) const |
119 | { | 119 | { |
120 | return _interfaces[iface]; | 120 | return _interfaces[iface]; |
121 | } | 121 | } |
122 | 122 | ||
123 | 123 | ||
124 | ONetwork* ONetwork::instance() | 124 | ONetwork* ONetwork::instance() |
125 | { | 125 | { |
126 | if ( !_instance ) _instance = new ONetwork(); | 126 | if ( !_instance ) _instance = new ONetwork(); |
127 | return _instance; | 127 | return _instance; |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
131 | ONetwork::InterfaceIterator ONetwork::iterator() const | 131 | ONetwork::InterfaceIterator ONetwork::iterator() const |
132 | { | 132 | { |
133 | return ONetwork::InterfaceIterator( _interfaces ); | 133 | return ONetwork::InterfaceIterator( _interfaces ); |
134 | } | 134 | } |
135 | 135 | ||
136 | 136 | ||
137 | bool ONetwork::isWirelessInterface( const char* name ) const | 137 | bool ONetwork::isWirelessInterface( const char* name ) const |
138 | { | 138 | { |
139 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 139 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
140 | struct iwreq iwr; | 140 | struct iwreq iwr; |
141 | memset( &iwr, 0, sizeof( struct iwreq ) ); | 141 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
142 | strcpy( (char*) &iwr.ifr_name, name ); | 142 | strcpy( (char*) &iwr.ifr_name, name ); |
143 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 143 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
144 | return result != -1; | 144 | return result != -1; |
145 | } | 145 | } |
146 | 146 | ||
147 | /*====================================================================================== | 147 | /*====================================================================================== |
148 | * ONetworkInterface | 148 | * ONetworkInterface |
149 | *======================================================================================*/ | 149 | *======================================================================================*/ |
150 | 150 | ||
151 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | 151 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
152 | :QObject( parent, name ), | 152 | :QObject( parent, name ), |
153 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 153 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
154 | { | 154 | { |
155 | qDebug( "ONetworkInterface::ONetworkInterface()" ); | 155 | qDebug( "ONetworkInterface::ONetworkInterface()" ); |
156 | init(); | 156 | init(); |
157 | } | 157 | } |
158 | 158 | ||
159 | 159 | ||
160 | struct ifreq& ONetworkInterface::ifr() const | 160 | struct ifreq& ONetworkInterface::ifr() const |
161 | { | 161 | { |
162 | return _ifr; | 162 | return _ifr; |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
166 | void ONetworkInterface::init() | 166 | void ONetworkInterface::init() |
167 | { | 167 | { |
168 | qDebug( "ONetworkInterface::init()" ); | 168 | qDebug( "ONetworkInterface::init()" ); |
169 | 169 | ||
170 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 170 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
171 | 171 | ||
172 | if ( _sfd == -1 ) | 172 | if ( _sfd == -1 ) |
173 | { | 173 | { |
174 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); | 174 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); |
175 | return; | 175 | return; |
176 | } | 176 | } |
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | 180 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
181 | { | 181 | { |
182 | int result = ::ioctl( _sfd, call, &ifreq ); | 182 | int result = ::ioctl( _sfd, call, &ifreq ); |
183 | if ( result == -1 ) | 183 | if ( result == -1 ) |
184 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); | 184 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); |
185 | else | 185 | else |
186 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); | 186 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); |
187 | return ( result != -1 ); | 187 | return ( result != -1 ); |
188 | } | 188 | } |
189 | 189 | ||
190 | 190 | ||
191 | bool ONetworkInterface::ioctl( int call ) const | 191 | bool ONetworkInterface::ioctl( int call ) const |
192 | { | 192 | { |
193 | strcpy( _ifr.ifr_name, name() ); | 193 | strcpy( _ifr.ifr_name, name() ); |
194 | return ioctl( call, _ifr ); | 194 | return ioctl( call, _ifr ); |
195 | } | 195 | } |
196 | 196 | ||
197 | 197 | ||
198 | bool ONetworkInterface::isLoopback() const | 198 | bool ONetworkInterface::isLoopback() const |
199 | { | 199 | { |
200 | ioctl( SIOCGIFFLAGS ); | 200 | ioctl( SIOCGIFFLAGS ); |
201 | return _ifr.ifr_flags & IFF_LOOPBACK; | 201 | return _ifr.ifr_flags & IFF_LOOPBACK; |
202 | } | 202 | } |
203 | 203 | ||
204 | 204 | ||
205 | bool ONetworkInterface::setUp( bool b ) | 205 | bool ONetworkInterface::setUp( bool b ) |
206 | { | 206 | { |
207 | ioctl( SIOCGIFFLAGS ); | 207 | ioctl( SIOCGIFFLAGS ); |
208 | if ( b ) _ifr.ifr_flags |= IFF_UP; | 208 | if ( b ) _ifr.ifr_flags |= IFF_UP; |
209 | else _ifr.ifr_flags &= (~IFF_UP); | 209 | else _ifr.ifr_flags &= (~IFF_UP); |
210 | return ioctl( SIOCSIFFLAGS ); | 210 | return ioctl( SIOCSIFFLAGS ); |
211 | } | 211 | } |
212 | 212 | ||
213 | 213 | ||
214 | bool ONetworkInterface::isUp() const | 214 | bool ONetworkInterface::isUp() const |
215 | { | 215 | { |
216 | ioctl( SIOCGIFFLAGS ); | 216 | ioctl( SIOCGIFFLAGS ); |
217 | return _ifr.ifr_flags & IFF_UP; | 217 | return _ifr.ifr_flags & IFF_UP; |
218 | } | 218 | } |
219 | 219 | ||
220 | 220 | ||
221 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) | 221 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) |
222 | { | 222 | { |
223 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 223 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
224 | sa->sin_family = AF_INET; | 224 | sa->sin_family = AF_INET; |
225 | sa->sin_port = 0; | 225 | sa->sin_port = 0; |
226 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 226 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
227 | ioctl( SIOCSIFADDR ); | 227 | ioctl( SIOCSIFADDR ); |
228 | } | 228 | } |
229 | 229 | ||
230 | 230 | ||
231 | QString ONetworkInterface::ipV4Address() const | 231 | QString ONetworkInterface::ipV4Address() const |
232 | { | 232 | { |
233 | if ( ioctl( SIOCGIFADDR ) ) | 233 | if ( ioctl( SIOCGIFADDR ) ) |
234 | { | 234 | { |
235 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 235 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
236 | //FIXME: Use QHostAddress here | 236 | //FIXME: Use QHostAddress here |
237 | return QString( inet_ntoa( sa->sin_addr ) ); | 237 | return QString( inet_ntoa( sa->sin_addr ) ); |
238 | } | 238 | } |
239 | else | 239 | else |
240 | return "<unknown>"; | 240 | return "<unknown>"; |
241 | } | 241 | } |
242 | 242 | ||
243 | 243 | ||
244 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) | 244 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) |
245 | { | 245 | { |
246 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; | 246 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
247 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); | 247 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); |
248 | ioctl( SIOCSIFHWADDR ); | 248 | ioctl( SIOCSIFHWADDR ); |
249 | } | 249 | } |
250 | 250 | ||
251 | 251 | ||
252 | OMacAddress ONetworkInterface::macAddress() const | 252 | OMacAddress ONetworkInterface::macAddress() const |
253 | { | 253 | { |
254 | if ( ioctl( SIOCGIFHWADDR ) ) | 254 | if ( ioctl( SIOCGIFHWADDR ) ) |
255 | { | 255 | { |
256 | return OMacAddress( _ifr ); | 256 | return OMacAddress( _ifr ); |
257 | } | 257 | } |
258 | else | 258 | else |
259 | { | 259 | { |
260 | return OMacAddress::unknown; | 260 | return OMacAddress::unknown; |
261 | } | 261 | } |
262 | } | 262 | } |
263 | 263 | ||
264 | 264 | ||
265 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) | 265 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) |
266 | { | 266 | { |
267 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 267 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
268 | sa->sin_family = AF_INET; | 268 | sa->sin_family = AF_INET; |
269 | sa->sin_port = 0; | 269 | sa->sin_port = 0; |
270 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 270 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
271 | ioctl( SIOCSIFNETMASK ); | 271 | ioctl( SIOCSIFNETMASK ); |
272 | } | 272 | } |
273 | 273 | ||
274 | 274 | ||
275 | QString ONetworkInterface::ipV4Netmask() const | 275 | QString ONetworkInterface::ipV4Netmask() const |
276 | { | 276 | { |
277 | if ( ioctl( SIOCGIFNETMASK ) ) | 277 | if ( ioctl( SIOCGIFNETMASK ) ) |
278 | { | 278 | { |
279 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 279 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
280 | //FIXME: Use QHostAddress here | 280 | //FIXME: Use QHostAddress here |
281 | return QString( inet_ntoa( sa->sin_addr ) ); | 281 | return QString( inet_ntoa( sa->sin_addr ) ); |
282 | } | 282 | } |
283 | else | 283 | else |
284 | return "<unknown>"; | 284 | return "<unknown>"; |
285 | } | 285 | } |
286 | 286 | ||
287 | 287 | ||
288 | int ONetworkInterface::dataLinkType() const | 288 | int ONetworkInterface::dataLinkType() const |
289 | { | 289 | { |
290 | if ( ioctl( SIOCGIFHWADDR ) ) | 290 | if ( ioctl( SIOCGIFHWADDR ) ) |
291 | { | 291 | { |
292 | return _ifr.ifr_hwaddr.sa_family; | 292 | return _ifr.ifr_hwaddr.sa_family; |
293 | } | 293 | } |
294 | else | 294 | else |
295 | { | 295 | { |
296 | return -1; | 296 | return -1; |
297 | } | 297 | } |
298 | } | 298 | } |
299 | 299 | ||
300 | 300 | ||
301 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 301 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
302 | { | 302 | { |
303 | _mon = m; | 303 | _mon = m; |
304 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); | 304 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); |
305 | } | 305 | } |
306 | 306 | ||
307 | 307 | ||
308 | OMonitoringInterface* ONetworkInterface::monitoring() const | 308 | OMonitoringInterface* ONetworkInterface::monitoring() const |
309 | { | 309 | { |
310 | return _mon; | 310 | return _mon; |
311 | } | 311 | } |
312 | 312 | ||
313 | 313 | ||
314 | ONetworkInterface::~ONetworkInterface() | 314 | ONetworkInterface::~ONetworkInterface() |
315 | { | 315 | { |
316 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); | 316 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); |
317 | if ( _sfd != -1 ) ::close( _sfd ); | 317 | if ( _sfd != -1 ) ::close( _sfd ); |
318 | } | 318 | } |
319 | 319 | ||
320 | 320 | ||
321 | bool ONetworkInterface::setPromiscuousMode( bool b ) | 321 | bool ONetworkInterface::setPromiscuousMode( bool b ) |
322 | { | 322 | { |
323 | ioctl( SIOCGIFFLAGS ); | 323 | ioctl( SIOCGIFFLAGS ); |
324 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; | 324 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; |
325 | else _ifr.ifr_flags &= (~IFF_PROMISC); | 325 | else _ifr.ifr_flags &= (~IFF_PROMISC); |
326 | return ioctl( SIOCSIFFLAGS ); | 326 | return ioctl( SIOCSIFFLAGS ); |
327 | } | 327 | } |
328 | 328 | ||
329 | 329 | ||
330 | bool ONetworkInterface::promiscuousMode() const | 330 | bool ONetworkInterface::promiscuousMode() const |
331 | { | 331 | { |
332 | ioctl( SIOCGIFFLAGS ); | 332 | ioctl( SIOCGIFFLAGS ); |
333 | return _ifr.ifr_flags & IFF_PROMISC; | 333 | return _ifr.ifr_flags & IFF_PROMISC; |
334 | } | 334 | } |
335 | 335 | ||
336 | 336 | ||
337 | bool ONetworkInterface::isWireless() const | 337 | bool ONetworkInterface::isWireless() const |
338 | { | 338 | { |
339 | return ioctl( SIOCGIWNAME ); | 339 | return ioctl( SIOCGIWNAME ); |
340 | } | 340 | } |
341 | 341 | ||
342 | 342 | ||
343 | /*====================================================================================== | 343 | /*====================================================================================== |
344 | * OChannelHopper | 344 | * OChannelHopper |
345 | *======================================================================================*/ | 345 | *======================================================================================*/ |
346 | 346 | ||
347 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 347 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
348 | :QObject( 0, "Mickey's funky hopper" ), | 348 | :QObject( 0, "Mickey's funky hopper" ), |
349 | _iface( iface ), _interval( 0 ), _tid( 0 ) | 349 | _iface( iface ), _interval( 0 ), _tid( 0 ) |
350 | { | 350 | { |
351 | int _maxChannel = iface->channels()+1; | 351 | int _maxChannel = iface->channels()+1; |
352 | // generate fancy hopping sequence honoring the device capabilities | 352 | // generate fancy hopping sequence honoring the device capabilities |
353 | if ( _maxChannel >= 1 ) _channels.append( 1 ); | 353 | if ( _maxChannel >= 1 ) _channels.append( 1 ); |
354 | if ( _maxChannel >= 7 ) _channels.append( 7 ); | 354 | if ( _maxChannel >= 7 ) _channels.append( 7 ); |
355 | if ( _maxChannel >= 13 ) _channels.append( 13 ); | 355 | if ( _maxChannel >= 13 ) _channels.append( 13 ); |
356 | if ( _maxChannel >= 2 ) _channels.append( 2 ); | 356 | if ( _maxChannel >= 2 ) _channels.append( 2 ); |
357 | if ( _maxChannel >= 8 ) _channels.append( 8 ); | 357 | if ( _maxChannel >= 8 ) _channels.append( 8 ); |
358 | if ( _maxChannel >= 3 ) _channels.append( 3 ); | 358 | if ( _maxChannel >= 3 ) _channels.append( 3 ); |
359 | if ( _maxChannel >= 14 ) _channels.append( 14 ); | 359 | if ( _maxChannel >= 14 ) _channels.append( 14 ); |
360 | if ( _maxChannel >= 9 ) _channels.append( 9 ); | 360 | if ( _maxChannel >= 9 ) _channels.append( 9 ); |
361 | if ( _maxChannel >= 4 ) _channels.append( 4 ); | 361 | if ( _maxChannel >= 4 ) _channels.append( 4 ); |
362 | if ( _maxChannel >= 10 ) _channels.append( 10 ); | 362 | if ( _maxChannel >= 10 ) _channels.append( 10 ); |
363 | if ( _maxChannel >= 5 ) _channels.append( 5 ); | 363 | if ( _maxChannel >= 5 ) _channels.append( 5 ); |
364 | if ( _maxChannel >= 11 ) _channels.append( 11 ); | 364 | if ( _maxChannel >= 11 ) _channels.append( 11 ); |
365 | if ( _maxChannel >= 6 ) _channels.append( 6 ); | 365 | if ( _maxChannel >= 6 ) _channels.append( 6 ); |
366 | if ( _maxChannel >= 12 ) _channels.append( 12 ); | 366 | if ( _maxChannel >= 12 ) _channels.append( 12 ); |
367 | _channel = _channels.begin(); | 367 | _channel = _channels.begin(); |
368 | 368 | ||
369 | } | 369 | } |
370 | 370 | ||
371 | 371 | ||
372 | OChannelHopper::~OChannelHopper() | 372 | OChannelHopper::~OChannelHopper() |
373 | { | 373 | { |
374 | } | 374 | } |
375 | 375 | ||
376 | 376 | ||
377 | bool OChannelHopper::isActive() const | 377 | bool OChannelHopper::isActive() const |
378 | { | 378 | { |
379 | return _tid; | 379 | return _tid; |
380 | } | 380 | } |
381 | 381 | ||
382 | 382 | ||
383 | int OChannelHopper::channel() const | 383 | int OChannelHopper::channel() const |
384 | { | 384 | { |
385 | return *_channel; | 385 | return *_channel; |
386 | } | 386 | } |
387 | 387 | ||
388 | 388 | ||
389 | void OChannelHopper::timerEvent( QTimerEvent* ) | 389 | void OChannelHopper::timerEvent( QTimerEvent* ) |
390 | { | 390 | { |
391 | _iface->setChannel( *_channel ); | 391 | _iface->setChannel( *_channel ); |
392 | emit( hopped( *_channel ) ); | 392 | emit( hopped( *_channel ) ); |
393 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", | 393 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", |
394 | *_channel, (const char*) _iface->name() ); | 394 | *_channel, (const char*) _iface->name() ); |
395 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); | 395 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); |
396 | } | 396 | } |
397 | 397 | ||
398 | 398 | ||
399 | void OChannelHopper::setInterval( int interval ) | 399 | void OChannelHopper::setInterval( int interval ) |
400 | { | 400 | { |
401 | if ( interval == _interval ) | 401 | if ( interval == _interval ) |
402 | return; | 402 | return; |
403 | 403 | ||
404 | if ( _interval ) | 404 | if ( _interval ) |
405 | killTimer( _tid ); | 405 | killTimer( _tid ); |
406 | 406 | ||
407 | _tid = 0; | 407 | _tid = 0; |
408 | _interval = interval; | 408 | _interval = interval; |
409 | 409 | ||
410 | if ( _interval ) | 410 | if ( _interval ) |
411 | { | 411 | { |
412 | _tid = startTimer( interval ); | 412 | _tid = startTimer( interval ); |
413 | } | 413 | } |
414 | } | 414 | } |
415 | 415 | ||
416 | 416 | ||
417 | int OChannelHopper::interval() const | 417 | int OChannelHopper::interval() const |
418 | { | 418 | { |
419 | return _interval; | 419 | return _interval; |
420 | } | 420 | } |
421 | 421 | ||
422 | 422 | ||
423 | /*====================================================================================== | 423 | /*====================================================================================== |
424 | * OWirelessNetworkInterface | 424 | * OWirelessNetworkInterface |
425 | *======================================================================================*/ | 425 | *======================================================================================*/ |
426 | 426 | ||
427 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) | 427 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) |
428 | :ONetworkInterface( parent, name ), _hopper( 0 ) | 428 | :ONetworkInterface( parent, name ), _hopper( 0 ) |
429 | { | 429 | { |
430 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); | 430 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); |
431 | init(); | 431 | init(); |
432 | } | 432 | } |
433 | 433 | ||
434 | 434 | ||
435 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 435 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
436 | { | 436 | { |
437 | } | 437 | } |
438 | 438 | ||
439 | 439 | ||
440 | struct iwreq& OWirelessNetworkInterface::iwr() const | 440 | struct iwreq& OWirelessNetworkInterface::iwr() const |
441 | { | 441 | { |
442 | return _iwr; | 442 | return _iwr; |
443 | } | 443 | } |
444 | 444 | ||
445 | 445 | ||
446 | void OWirelessNetworkInterface::init() | 446 | void OWirelessNetworkInterface::init() |
447 | { | 447 | { |
448 | qDebug( "OWirelessNetworkInterface::init()" ); | 448 | qDebug( "OWirelessNetworkInterface::init()" ); |
449 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 449 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
450 | buildChannelList(); | 450 | buildChannelList(); |
451 | buildPrivateList(); | 451 | buildPrivateList(); |
452 | } | 452 | } |
453 | 453 | ||
454 | 454 | ||
455 | QString OWirelessNetworkInterface::associatedAP() const | 455 | QString OWirelessNetworkInterface::associatedAP() const |
456 | { | 456 | { |
457 | //FIXME: use OMacAddress | 457 | //FIXME: use OMacAddress |
458 | QString mac; | 458 | QString mac; |
459 | 459 | ||
460 | if ( ioctl( SIOCGIWAP ) ) | 460 | if ( ioctl( SIOCGIWAP ) ) |
461 | { | 461 | { |
462 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 462 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
463 | _ifr.ifr_hwaddr.sa_data[0]&0xff, | 463 | _ifr.ifr_hwaddr.sa_data[0]&0xff, |
464 | _ifr.ifr_hwaddr.sa_data[1]&0xff, | 464 | _ifr.ifr_hwaddr.sa_data[1]&0xff, |
465 | _ifr.ifr_hwaddr.sa_data[2]&0xff, | 465 | _ifr.ifr_hwaddr.sa_data[2]&0xff, |
466 | _ifr.ifr_hwaddr.sa_data[3]&0xff, | 466 | _ifr.ifr_hwaddr.sa_data[3]&0xff, |
467 | _ifr.ifr_hwaddr.sa_data[4]&0xff, | 467 | _ifr.ifr_hwaddr.sa_data[4]&0xff, |
468 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); | 468 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); |
469 | } | 469 | } |
470 | else | 470 | else |
471 | { | 471 | { |
472 | mac = "<Unknown>"; | 472 | mac = "<Unknown>"; |
473 | } | 473 | } |
474 | return mac; | 474 | return mac; |
475 | } | 475 | } |
476 | 476 | ||
477 | 477 | ||
478 | void OWirelessNetworkInterface::buildChannelList() | 478 | void OWirelessNetworkInterface::buildChannelList() |
479 | { | 479 | { |
480 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | 480 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck |
481 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete | 481 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete |
482 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". | 482 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". |
483 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate | 483 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate |
484 | //ML: _too much_ space. This is damn shitty crap *sigh* | 484 | //ML: _too much_ space. This is damn shitty crap *sigh* |
485 | //ML: We allocate a large memory region in RAM and check whether the | 485 | //ML: We allocate a large memory region in RAM and check whether the |
486 | //ML: driver pollutes this extra space. The complaint will be made on stdout, | 486 | //ML: driver pollutes this extra space. The complaint will be made on stdout, |
487 | //ML: so please forward this... | 487 | //ML: so please forward this... |
488 | 488 | ||
489 | struct iwreq wrq; | 489 | struct iwreq wrq; |
490 | int len = sizeof( struct iw_range )*2; | 490 | int len = sizeof( struct iw_range )*2; |
491 | char *buffer = (char*) malloc( len ); | 491 | char *buffer = (char*) malloc( len ); |
492 | //FIXME: Validate if we actually got the memory block | 492 | //FIXME: Validate if we actually got the memory block |
493 | memset( buffer, 0, len ); | 493 | memset( buffer, 0, len ); |
494 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); | 494 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); |
495 | wrq.u.data.pointer = (caddr_t) buffer; | 495 | wrq.u.data.pointer = (caddr_t) buffer; |
496 | wrq.u.data.length = sizeof( struct iw_range ); | 496 | wrq.u.data.length = sizeof( struct iw_range ); |
497 | wrq.u.data.flags = 0; | 497 | wrq.u.data.flags = 0; |
498 | 498 | ||
499 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) | 499 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) |
500 | { | 500 | { |
501 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); | 501 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); |
502 | _channels.insert( 2412, 1 ); // 2.412 GHz | 502 | _channels.insert( 2412, 1 ); // 2.412 GHz |
503 | _channels.insert( 2417, 2 ); // 2.417 GHz | 503 | _channels.insert( 2417, 2 ); // 2.417 GHz |
504 | _channels.insert( 2422, 3 ); // 2.422 GHz | 504 | _channels.insert( 2422, 3 ); // 2.422 GHz |
505 | _channels.insert( 2427, 4 ); // 2.427 GHz | 505 | _channels.insert( 2427, 4 ); // 2.427 GHz |
506 | _channels.insert( 2432, 5 ); // 2.432 GHz | 506 | _channels.insert( 2432, 5 ); // 2.432 GHz |
507 | _channels.insert( 2437, 6 ); // 2.437 GHz | 507 | _channels.insert( 2437, 6 ); // 2.437 GHz |
508 | _channels.insert( 2442, 7 ); // 2.442 GHz | 508 | _channels.insert( 2442, 7 ); // 2.442 GHz |
509 | _channels.insert( 2447, 8 ); // 2.447 GHz | 509 | _channels.insert( 2447, 8 ); // 2.447 GHz |
510 | _channels.insert( 2452, 9 ); // 2.452 GHz | 510 | _channels.insert( 2452, 9 ); // 2.452 GHz |
511 | _channels.insert( 2457, 10 ); // 2.457 GHz | 511 | _channels.insert( 2457, 10 ); // 2.457 GHz |
512 | _channels.insert( 2462, 11 ); // 2.462 GHz | 512 | _channels.insert( 2462, 11 ); // 2.462 GHz |
513 | } | 513 | } |
514 | else | 514 | else |
515 | { | 515 | { |
516 | // <check if the driver overwrites stuff> | 516 | // <check if the driver overwrites stuff> |
517 | int max = 0; | 517 | int max = 0; |
518 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) | 518 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) |
519 | if (buffer[r] != 0) | 519 | if (buffer[r] != 0) |
520 | max = r; | 520 | max = r; |
521 | if (max > 0) | 521 | if (max > 0) |
522 | { | 522 | { |
523 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" | 523 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" |
524 | "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); | 524 | "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); |
525 | } | 525 | } |
526 | // </check if the driver overwrites stuff> | 526 | // </check if the driver overwrites stuff> |
527 | 527 | ||
528 | struct iw_range range; | 528 | struct iw_range range; |
529 | memcpy( &range, buffer, sizeof range ); | 529 | memcpy( &range, buffer, sizeof range ); |
530 | 530 | ||
531 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); | 531 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); |
532 | for ( int i = 0; i < range.num_frequency; ++i ) | 532 | for ( int i = 0; i < range.num_frequency; ++i ) |
533 | { | 533 | { |
534 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | 534 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); |
535 | _channels.insert( freq, i+1 ); | 535 | _channels.insert( freq, i+1 ); |
536 | } | 536 | } |
537 | } | 537 | } |
538 | 538 | ||
539 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); | 539 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); |
540 | free(buffer); | 540 | free(buffer); |
541 | } | 541 | } |
542 | 542 | ||
543 | 543 | ||
544 | void OWirelessNetworkInterface::buildPrivateList() | 544 | void OWirelessNetworkInterface::buildPrivateList() |
545 | { | 545 | { |
546 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); | 546 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); |
547 | 547 | ||
548 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | 548 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; |
549 | 549 | ||
550 | _iwr.u.data.pointer = (char*) &priv; | 550 | _iwr.u.data.pointer = (char*) &priv; |
551 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself | 551 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself |
552 | _iwr.u.data.flags = 0; | 552 | _iwr.u.data.flags = 0; |
553 | 553 | ||
554 | if ( !wioctl( SIOCGIWPRIV ) ) | 554 | if ( !wioctl( SIOCGIWPRIV ) ) |
555 | { | 555 | { |
556 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); | 556 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); |
557 | return; | 557 | return; |
558 | } | 558 | } |
559 | 559 | ||
560 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | 560 | for ( int i = 0; i < _iwr.u.data.length; ++i ) |
561 | { | 561 | { |
562 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); | 562 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); |
563 | } | 563 | } |
564 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); | 564 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); |
565 | } | 565 | } |
566 | 566 | ||
567 | 567 | ||
568 | int OWirelessNetworkInterface::channel() const | 568 | int OWirelessNetworkInterface::channel() const |
569 | { | 569 | { |
570 | //FIXME: When monitoring enabled, then use it | 570 | //FIXME: When monitoring enabled, then use it |
571 | //FIXME: to gather the current RF channel | 571 | //FIXME: to gather the current RF channel |
572 | //FIXME: Until then, get active channel from hopper. | 572 | //FIXME: Until then, get active channel from hopper. |
573 | if ( _hopper && _hopper->isActive() ) | 573 | if ( _hopper && _hopper->isActive() ) |
574 | return _hopper->channel(); | 574 | return _hopper->channel(); |
575 | 575 | ||
576 | if ( !wioctl( SIOCGIWFREQ ) ) | 576 | if ( !wioctl( SIOCGIWFREQ ) ) |
577 | { | 577 | { |
578 | return -1; | 578 | return -1; |
579 | } | 579 | } |
580 | else | 580 | else |
581 | { | 581 | { |
582 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; | 582 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; |
583 | } | 583 | } |
584 | } | 584 | } |
585 | 585 | ||
586 | 586 | ||
587 | void OWirelessNetworkInterface::setChannel( int c ) const | 587 | void OWirelessNetworkInterface::setChannel( int c ) const |
588 | { | 588 | { |
589 | if ( !_mon ) | 589 | if ( !_mon ) |
590 | { | 590 | { |
591 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 591 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
592 | _iwr.u.freq.m = c; | 592 | _iwr.u.freq.m = c; |
593 | _iwr.u.freq.e = 0; | 593 | _iwr.u.freq.e = 0; |
594 | wioctl( SIOCSIWFREQ ); | 594 | wioctl( SIOCSIWFREQ ); |
595 | } | 595 | } |
596 | else | 596 | else |
597 | { | 597 | { |
598 | _mon->setChannel( c ); | 598 | _mon->setChannel( c ); |
599 | } | 599 | } |
600 | } | 600 | } |
601 | 601 | ||
602 | 602 | ||
603 | double OWirelessNetworkInterface::frequency() const | 603 | double OWirelessNetworkInterface::frequency() const |
604 | { | 604 | { |
605 | if ( !wioctl( SIOCGIWFREQ ) ) | 605 | if ( !wioctl( SIOCGIWFREQ ) ) |
606 | { | 606 | { |
607 | return -1.0; | 607 | return -1.0; |
608 | } | 608 | } |
609 | else | 609 | else |
610 | { | 610 | { |
611 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; | 611 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; |
612 | } | 612 | } |
613 | } | 613 | } |
614 | 614 | ||
615 | 615 | ||
616 | int OWirelessNetworkInterface::channels() const | 616 | int OWirelessNetworkInterface::channels() const |
617 | { | 617 | { |
618 | return _channels.count(); | 618 | return _channels.count(); |
619 | } | 619 | } |
620 | 620 | ||
621 | 621 | ||
622 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 622 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
623 | { | 623 | { |
624 | if ( !_hopper ) _hopper = new OChannelHopper( this ); | 624 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
625 | _hopper->setInterval( interval ); | 625 | _hopper->setInterval( interval ); |
626 | //FIXME: When and by whom will the channel hopper be deleted? | 626 | //FIXME: When and by whom will the channel hopper be deleted? |
627 | //TODO: rely on QObject hierarchy | 627 | //TODO: rely on QObject hierarchy |
628 | } | 628 | } |
629 | 629 | ||
630 | 630 | ||
631 | int OWirelessNetworkInterface::channelHopping() const | 631 | int OWirelessNetworkInterface::channelHopping() const |
632 | { | 632 | { |
633 | return _hopper->interval(); | 633 | return _hopper->interval(); |
634 | } | 634 | } |
635 | 635 | ||
636 | 636 | ||
637 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const | 637 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const |
638 | { | 638 | { |
639 | return _hopper; | 639 | return _hopper; |
640 | } | 640 | } |
641 | 641 | ||
642 | 642 | ||
643 | void OWirelessNetworkInterface::setMode( const QString& mode ) | 643 | void OWirelessNetworkInterface::setMode( const QString& mode ) |
644 | { | 644 | { |
645 | if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; | 645 | if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; |
646 | else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; | 646 | else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; |
647 | else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; | 647 | else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; |
648 | else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; | 648 | else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; |
649 | else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; | 649 | else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; |
650 | else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; | 650 | else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; |
651 | #if WIRELESS_EXT > 14 | 651 | #if WIRELESS_EXT > 14 |
652 | else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; | 652 | else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; |
653 | #endif | 653 | #endif |
654 | else | 654 | else |
655 | { | 655 | { |
656 | qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); | 656 | qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); |
657 | return; | 657 | return; |
658 | } | 658 | } |
659 | wioctl( SIOCSIWMODE ); | 659 | wioctl( SIOCSIWMODE ); |
660 | } | 660 | } |
661 | 661 | ||
662 | 662 | ||
663 | QString OWirelessNetworkInterface::mode() const | 663 | QString OWirelessNetworkInterface::mode() const |
664 | { | 664 | { |
665 | if ( !wioctl( SIOCGIWMODE ) ) | 665 | if ( !wioctl( SIOCGIWMODE ) ) |
666 | { | 666 | { |
667 | return "<unknown>"; | 667 | return "<unknown>"; |
668 | } | 668 | } |
669 | switch ( _iwr.u.mode ) | 669 | switch ( _iwr.u.mode ) |
670 | { | 670 | { |
671 | case IW_MODE_AUTO: return "auto"; | 671 | case IW_MODE_AUTO: return "auto"; |
672 | case IW_MODE_ADHOC: return "adhoc"; | 672 | case IW_MODE_ADHOC: return "adhoc"; |
673 | case IW_MODE_INFRA: return "managed"; | 673 | case IW_MODE_INFRA: return "managed"; |
674 | case IW_MODE_MASTER: return "master"; | 674 | case IW_MODE_MASTER: return "master"; |
675 | case IW_MODE_REPEAT: return "repeater"; | 675 | case IW_MODE_REPEAT: return "repeater"; |
676 | case IW_MODE_SECOND: return "secondary"; | 676 | case IW_MODE_SECOND: return "secondary"; |
677 | #if WIRELESS_EXT > 14 | 677 | #if WIRELESS_EXT > 14 |
678 | case IW_MODE_MONITOR: return "monitor"; | 678 | case IW_MODE_MONITOR: return "monitor"; |
679 | #endif | 679 | #endif |
680 | default: assert( 0 ); // shouldn't happen | 680 | default: assert( 0 ); // shouldn't happen |
681 | } | 681 | } |
682 | } | 682 | } |
683 | 683 | ||
684 | 684 | ||
685 | void OWirelessNetworkInterface::setMonitorMode( bool b ) | 685 | void OWirelessNetworkInterface::setMonitorMode( bool b ) |
686 | { | 686 | { |
687 | if ( _mon ) | 687 | if ( _mon ) |
688 | _mon->setEnabled( b ); | 688 | _mon->setEnabled( b ); |
689 | else | 689 | else |
690 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 690 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); |
691 | } | 691 | } |
692 | 692 | ||
693 | 693 | ||
694 | bool OWirelessNetworkInterface::monitorMode() const | 694 | bool OWirelessNetworkInterface::monitorMode() const |
695 | { | 695 | { |
696 | qDebug( "dataLinkType = %d", dataLinkType() ); | 696 | qDebug( "dataLinkType = %d", dataLinkType() ); |
697 | return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); | 697 | return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); |
698 | // 802 is the header type for PRISM - Linux support for this is pending... | 698 | // 802 is the header type for PRISM - Linux support for this is pending... |
699 | } | 699 | } |
700 | 700 | ||
701 | 701 | ||
702 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) | 702 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) |
703 | { | 703 | { |
704 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); | 704 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); |
705 | _iwr.u.essid.length = nickname.length(); | 705 | _iwr.u.essid.length = nickname.length(); |
706 | wioctl( SIOCSIWNICKN ); | 706 | wioctl( SIOCSIWNICKN ); |
707 | } | 707 | } |
708 | 708 | ||
709 | 709 | ||
710 | QString OWirelessNetworkInterface::nickName() const | 710 | QString OWirelessNetworkInterface::nickName() const |
711 | { | 711 | { |
712 | char str[IW_ESSID_MAX_SIZE]; | 712 | char str[IW_ESSID_MAX_SIZE]; |
713 | _iwr.u.data.pointer = &str[0]; | 713 | _iwr.u.data.pointer = &str[0]; |
714 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; | 714 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; |
715 | if ( !wioctl( SIOCGIWNICKN ) ) | 715 | if ( !wioctl( SIOCGIWNICKN ) ) |
716 | { | 716 | { |
717 | return "<unknown>"; | 717 | return "<unknown>"; |
718 | } | 718 | } |
719 | else | 719 | else |
720 | { | 720 | { |
721 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string | 721 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string |
722 | return str; | 722 | return str; |
723 | } | 723 | } |
724 | } | 724 | } |
725 | 725 | ||
726 | 726 | ||
727 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) | 727 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) |
728 | { | 728 | { |
729 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); | 729 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); |
730 | if ( !priv ) | 730 | if ( !priv ) |
731 | { | 731 | { |
732 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); | 732 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); |
733 | return; | 733 | return; |
734 | } | 734 | } |
735 | if ( priv->numberSetArgs() != numargs ) | 735 | if ( priv->numberSetArgs() != numargs ) |
736 | { | 736 | { |
737 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); | 737 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); |
738 | return; | 738 | return; |
739 | } | 739 | } |
740 | 740 | ||
741 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); | 741 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); |
742 | memset( &_iwr, 0, sizeof _iwr ); | 742 | memset( &_iwr, 0, sizeof _iwr ); |
743 | va_list argp; | 743 | va_list argp; |
744 | va_start( argp, numargs ); | 744 | va_start( argp, numargs ); |
745 | for ( int i = 0; i < numargs; ++i ) | 745 | for ( int i = 0; i < numargs; ++i ) |
746 | { | 746 | { |
747 | priv->setParameter( i, va_arg( argp, int ) ); | 747 | priv->setParameter( i, va_arg( argp, int ) ); |
748 | } | 748 | } |
749 | va_end( argp ); | 749 | va_end( argp ); |
750 | priv->invoke(); | 750 | priv->invoke(); |
751 | } | 751 | } |
752 | 752 | ||
753 | 753 | ||
754 | void OWirelessNetworkInterface::getPrivate( const QString& call ) | 754 | void OWirelessNetworkInterface::getPrivate( const QString& call ) |
755 | { | 755 | { |
756 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); | 756 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); |
757 | } | 757 | } |
758 | 758 | ||
759 | 759 | ||
760 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) | 760 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) |
761 | { | 761 | { |
762 | return child( (const char*) call ); | 762 | return child( (const char*) call ); |
763 | } | 763 | } |
764 | 764 | ||
765 | 765 | ||
766 | QString OWirelessNetworkInterface::SSID() const | 766 | QString OWirelessNetworkInterface::SSID() const |
767 | { | 767 | { |
768 | char str[IW_ESSID_MAX_SIZE]; | 768 | char str[IW_ESSID_MAX_SIZE]; |
769 | _iwr.u.essid.pointer = &str[0]; | 769 | _iwr.u.essid.pointer = &str[0]; |
770 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 770 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
771 | if ( !wioctl( SIOCGIWESSID ) ) | 771 | if ( !wioctl( SIOCGIWESSID ) ) |
772 | { | 772 | { |
773 | return "<unknown>"; | 773 | return "<unknown>"; |
774 | } | 774 | } |
775 | else | 775 | else |
776 | { | 776 | { |
777 | return str; | 777 | return str; |
778 | } | 778 | } |
779 | } | 779 | } |
780 | 780 | ||
781 | 781 | ||
782 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) | 782 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) |
783 | { | 783 | { |
784 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | 784 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); |
785 | _iwr.u.essid.length = ssid.length(); | 785 | _iwr.u.essid.length = ssid.length(); |
786 | wioctl( SIOCSIWESSID ); | 786 | wioctl( SIOCSIWESSID ); |
787 | } | 787 | } |
788 | 788 | ||
789 | 789 | ||
790 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 790 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
791 | { | 791 | { |
792 | int result = ::ioctl( _sfd, call, &iwreq ); | 792 | int result = ::ioctl( _sfd, call, &iwreq ); |
793 | if ( result == -1 ) | 793 | if ( result == -1 ) |
794 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); | 794 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); |
795 | else | 795 | else |
796 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); | 796 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); |
797 | return ( result != -1 ); | 797 | return ( result != -1 ); |
798 | } | 798 | } |
799 | 799 | ||
800 | 800 | ||
801 | bool OWirelessNetworkInterface::wioctl( int call ) const | 801 | bool OWirelessNetworkInterface::wioctl( int call ) const |
802 | { | 802 | { |
803 | strcpy( _iwr.ifr_name, name() ); | 803 | strcpy( _iwr.ifr_name, name() ); |
804 | return wioctl( call, _iwr ); | 804 | return wioctl( call, _iwr ); |
805 | } | 805 | } |
806 | 806 | ||
807 | 807 | ||
808 | /*====================================================================================== | 808 | /*====================================================================================== |
809 | * OMonitoringInterface | 809 | * OMonitoringInterface |
810 | *======================================================================================*/ | 810 | *======================================================================================*/ |
811 | 811 | ||
812 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) | 812 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
813 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ) | 813 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) |
814 | { | 814 | { |
815 | } | 815 | } |
816 | 816 | ||
817 | 817 | ||
818 | OMonitoringInterface::~OMonitoringInterface() | 818 | OMonitoringInterface::~OMonitoringInterface() |
819 | { | 819 | { |
820 | } | 820 | } |
821 | 821 | ||
822 | 822 | ||
823 | void OMonitoringInterface::setChannel( int c ) | 823 | void OMonitoringInterface::setChannel( int c ) |
824 | { | 824 | { |
825 | // use standard WE channel switching protocol | 825 | // use standard WE channel switching protocol |
826 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); | 826 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
827 | _if->_iwr.u.freq.m = c; | 827 | _if->_iwr.u.freq.m = c; |
828 | _if->_iwr.u.freq.e = 0; | 828 | _if->_iwr.u.freq.e = 0; |
829 | _if->wioctl( SIOCSIWFREQ ); | 829 | _if->wioctl( SIOCSIWFREQ ); |
830 | } | 830 | } |
831 | 831 | ||
832 | 832 | ||
833 | bool OMonitoringInterface::enabled() const | 833 | bool OMonitoringInterface::enabled() const |
834 | { | 834 | { |
835 | return _if->monitorMode(); | 835 | return _if->monitorMode(); |
836 | } | 836 | } |
837 | 837 | ||
838 | 838 | ||
839 | void OMonitoringInterface::setEnabled( bool b ) | 839 | void OMonitoringInterface::setEnabled( bool b ) |
840 | { | 840 | { |
841 | } | 841 | } |
842 | 842 | ||
843 | 843 | ||
844 | /*====================================================================================== | 844 | /*====================================================================================== |
845 | * OCiscoMonitoringInterface | 845 | * OCiscoMonitoringInterface |
846 | *======================================================================================*/ | 846 | *======================================================================================*/ |
847 | 847 | ||
848 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) | 848 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
849 | :OMonitoringInterface( iface ) | 849 | :OMonitoringInterface( iface, prismHeader ) |
850 | { | 850 | { |
851 | iface->setMonitoring( this ); | 851 | iface->setMonitoring( this ); |
852 | } | 852 | } |
853 | 853 | ||
854 | 854 | ||
855 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | 855 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() |
856 | { | 856 | { |
857 | } | 857 | } |
858 | 858 | ||
859 | 859 | ||
860 | void OCiscoMonitoringInterface::setEnabled( bool b ) | 860 | void OCiscoMonitoringInterface::setEnabled( bool b ) |
861 | { | 861 | { |
862 | QString fname; | 862 | QString fname; |
863 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); | 863 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); |
864 | QFile f( fname ); | 864 | QFile f( fname ); |
865 | if ( !f.exists() ) return; | 865 | if ( !f.exists() ) return; |
866 | 866 | ||
867 | if ( f.open( IO_WriteOnly ) ) | 867 | if ( f.open( IO_WriteOnly ) ) |
868 | { | 868 | { |
869 | QTextStream s( &f ); | 869 | QTextStream s( &f ); |
870 | s << "Mode: r"; | 870 | s << "Mode: r"; |
871 | s << "Mode: y"; | 871 | s << "Mode: y"; |
872 | s << "XmitPower: 1"; | 872 | s << "XmitPower: 1"; |
873 | } | 873 | } |
874 | 874 | ||
875 | // flushing and closing will be done automatically when f goes out of scope | 875 | // flushing and closing will be done automatically when f goes out of scope |
876 | } | 876 | } |
877 | 877 | ||
878 | 878 | ||
879 | QString OCiscoMonitoringInterface::name() const | 879 | QString OCiscoMonitoringInterface::name() const |
880 | { | 880 | { |
881 | return "cisco"; | 881 | return "cisco"; |
882 | } | 882 | } |
883 | 883 | ||
884 | 884 | ||
885 | void OCiscoMonitoringInterface::setChannel( int ) | 885 | void OCiscoMonitoringInterface::setChannel( int ) |
886 | { | 886 | { |
887 | // cisco devices automatically switch channels when in monitor mode | 887 | // cisco devices automatically switch channels when in monitor mode |
888 | } | 888 | } |
889 | 889 | ||
890 | 890 | ||
891 | /*====================================================================================== | 891 | /*====================================================================================== |
892 | * OWlanNGMonitoringInterface | 892 | * OWlanNGMonitoringInterface |
893 | *======================================================================================*/ | 893 | *======================================================================================*/ |
894 | 894 | ||
895 | 895 | ||
896 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) | 896 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
897 | :OMonitoringInterface( iface ) | 897 | :OMonitoringInterface( iface, prismHeader ) |
898 | { | 898 | { |
899 | iface->setMonitoring( this ); | 899 | iface->setMonitoring( this ); |
900 | } | 900 | } |
901 | 901 | ||
902 | 902 | ||
903 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() | 903 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() |
904 | { | 904 | { |
905 | } | 905 | } |
906 | 906 | ||
907 | 907 | ||
908 | void OWlanNGMonitoringInterface::setEnabled( bool b ) | 908 | void OWlanNGMonitoringInterface::setEnabled( bool b ) |
909 | { | 909 | { |
910 | //FIXME: do nothing if its already in the same mode | 910 | //FIXME: do nothing if its already in the same mode |
911 | 911 | ||
912 | QString enable = b ? "true" : "false"; | 912 | QString enable = b ? "true" : "false"; |
913 | QString prism = _prismHeader ? "true" : "false"; | ||
913 | QString cmd; | 914 | QString cmd; |
914 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); | 915 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
916 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); | ||
915 | system( cmd ); | 917 | system( cmd ); |
916 | } | 918 | } |
917 | 919 | ||
918 | 920 | ||
919 | QString OWlanNGMonitoringInterface::name() const | 921 | QString OWlanNGMonitoringInterface::name() const |
920 | { | 922 | { |
921 | return "wlan-ng"; | 923 | return "wlan-ng"; |
922 | } | 924 | } |
923 | 925 | ||
924 | 926 | ||
925 | void OWlanNGMonitoringInterface::setChannel( int ) | 927 | void OWlanNGMonitoringInterface::setChannel( int ) |
926 | { | 928 | { |
927 | // wlan-ng devices automatically switch channels when in monitor mode | 929 | // wlan-ng devices automatically switch channels when in monitor mode |
928 | } | 930 | } |
929 | 931 | ||
930 | 932 | ||
931 | /*====================================================================================== | 933 | /*====================================================================================== |
932 | * OHostAPMonitoringInterface | 934 | * OHostAPMonitoringInterface |
933 | *======================================================================================*/ | 935 | *======================================================================================*/ |
934 | 936 | ||
935 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) | 937 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
936 | :OMonitoringInterface( iface ) | 938 | :OMonitoringInterface( iface, prismHeader ) |
937 | { | 939 | { |
938 | iface->setMonitoring( this ); | 940 | iface->setMonitoring( this ); |
939 | } | 941 | } |
940 | 942 | ||
941 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() | 943 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() |
942 | { | 944 | { |
943 | } | 945 | } |
944 | 946 | ||
945 | void OHostAPMonitoringInterface::setEnabled( bool b ) | 947 | void OHostAPMonitoringInterface::setEnabled( bool b ) |
946 | { | 948 | { |
947 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | 949 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 |
948 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | 950 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring |
949 | 951 | ||
950 | //TODO: check wireless extensions version on runtime and use | 952 | //TODO: check wireless extensions version on runtime and use |
951 | //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15 | 953 | //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15 |
952 | 954 | ||
955 | int monitorCode = _prismHeader ? 1 : 2; | ||
956 | |||
953 | if ( b ) | 957 | if ( b ) |
954 | { | 958 | { |
955 | _if->setPrivate( "monitor", 1, 2 ); | 959 | _if->setPrivate( "monitor", 1, monitorCode ); |
956 | } | 960 | } |
957 | else | 961 | else |
958 | { | 962 | { |
959 | _if->setPrivate( "monitor", 1, 0 ); | 963 | _if->setPrivate( "monitor", 1, 0 ); |
960 | } | 964 | } |
961 | } | 965 | } |
962 | 966 | ||
963 | 967 | ||
964 | QString OHostAPMonitoringInterface::name() const | 968 | QString OHostAPMonitoringInterface::name() const |
965 | { | 969 | { |
966 | return "hostap"; | 970 | return "hostap"; |
967 | } | 971 | } |
968 | 972 | ||
969 | 973 | ||
970 | /*====================================================================================== | 974 | /*====================================================================================== |
971 | * OOrinocoNetworkInterface | 975 | * OOrinocoNetworkInterface |
972 | *======================================================================================*/ | 976 | *======================================================================================*/ |
973 | 977 | ||
974 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) | 978 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
975 | :OMonitoringInterface( iface ) | 979 | :OMonitoringInterface( iface, prismHeader ) |
976 | { | 980 | { |
977 | iface->setMonitoring( this ); | 981 | iface->setMonitoring( this ); |
978 | } | 982 | } |
979 | 983 | ||
980 | 984 | ||
981 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() | 985 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() |
982 | { | 986 | { |
983 | } | 987 | } |
984 | 988 | ||
985 | 989 | ||
986 | void OOrinocoMonitoringInterface::setChannel( int c ) | 990 | void OOrinocoMonitoringInterface::setChannel( int c ) |
987 | { | 991 | { |
988 | _if->setPrivate( "monitor", 2, 1, c ); | 992 | int monitorCode = _prismHeader ? 1 : 2; |
993 | _if->setPrivate( "monitor", 2, monitorCode, c ); | ||
989 | } | 994 | } |
990 | 995 | ||
991 | 996 | ||
992 | void OOrinocoMonitoringInterface::setEnabled( bool b ) | 997 | void OOrinocoMonitoringInterface::setEnabled( bool b ) |
993 | { | 998 | { |
994 | if ( b ) | 999 | if ( b ) |
995 | { | 1000 | { |
996 | setChannel( 1 ); | 1001 | setChannel( 1 ); |
997 | } | 1002 | } |
998 | else | 1003 | else |
999 | { | 1004 | { |
1000 | _if->setPrivate( "monitor", 2, 0, 0 ); | 1005 | _if->setPrivate( "monitor", 2, 0, 0 ); |
1001 | } | 1006 | } |
1002 | } | 1007 | } |
1003 | 1008 | ||
1004 | 1009 | ||
1005 | QString OOrinocoMonitoringInterface::name() const | 1010 | QString OOrinocoMonitoringInterface::name() const |
1006 | { | 1011 | { |
1007 | return "orinoco"; | 1012 | return "orinoco"; |
1008 | } | 1013 | } |
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index 1b38d02..eb9d506 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -1,538 +1,539 @@ | |||
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 | #ifndef ONETWORK_H | 34 | #ifndef ONETWORK_H |
35 | #define ONETWORK_H | 35 | #define ONETWORK_H |
36 | 36 | ||
37 | /* OPIE */ | 37 | /* OPIE */ |
38 | 38 | ||
39 | #include <opie2/onetutils.h> | 39 | #include <opie2/onetutils.h> |
40 | 40 | ||
41 | /* QT */ | 41 | /* QT */ |
42 | 42 | ||
43 | #include <qvaluelist.h> | 43 | #include <qvaluelist.h> |
44 | #include <qdict.h> | 44 | #include <qdict.h> |
45 | #include <qmap.h> | 45 | #include <qmap.h> |
46 | #include <qobject.h> | 46 | #include <qobject.h> |
47 | #include <qhostaddress.h> | 47 | #include <qhostaddress.h> |
48 | 48 | ||
49 | #ifndef IFNAMSIZ | 49 | #ifndef IFNAMSIZ |
50 | #define IFNAMSIZ 16 | 50 | #define IFNAMSIZ 16 |
51 | #endif | 51 | #endif |
52 | #ifndef IW_MAX_PRIV_DEF | 52 | #ifndef IW_MAX_PRIV_DEF |
53 | #define IW_MAX_PRIV_DEF 128 | 53 | #define IW_MAX_PRIV_DEF 128 |
54 | #endif | 54 | #endif |
55 | 55 | ||
56 | // ML: Yeah, I hate to include kernel headers, but it's necessary here | 56 | // ML: Yeah, I hate to include kernel headers, but it's necessary here |
57 | // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> | 57 | // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> |
58 | // ML: which conflicts with the user header <net/if.h> | 58 | // ML: which conflicts with the user header <net/if.h> |
59 | // ML: We really need a user header for the Wireless Extensions, something like <net/wireless.h> | 59 | // ML: We really need a user header for the Wireless Extensions, something like <net/wireless.h> |
60 | // ML: I will drop Jean a mail on that subject | 60 | // ML: I will drop Jean a mail on that subject |
61 | 61 | ||
62 | #include <net/if.h> | 62 | #include <net/if.h> |
63 | #define _LINUX_IF_H | 63 | #define _LINUX_IF_H |
64 | #include <linux/wireless.h> | 64 | #include <linux/wireless.h> |
65 | 65 | ||
66 | class ONetworkInterface; | 66 | class ONetworkInterface; |
67 | class OWirelessNetworkInterface; | 67 | class OWirelessNetworkInterface; |
68 | class OChannelHopper; | 68 | class OChannelHopper; |
69 | class OMonitoringInterface; | 69 | class OMonitoringInterface; |
70 | 70 | ||
71 | /*====================================================================================== | 71 | /*====================================================================================== |
72 | * ONetwork | 72 | * ONetwork |
73 | *======================================================================================*/ | 73 | *======================================================================================*/ |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * @brief A container class for all network interfaces | 76 | * @brief A container class for all network interfaces |
77 | * | 77 | * |
78 | * This class provides access to all available network interfaces of your computer. | 78 | * This class provides access to all available network interfaces of your computer. |
79 | * | 79 | * |
80 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 80 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
81 | */ | 81 | */ |
82 | class ONetwork : public QObject | 82 | class ONetwork : public QObject |
83 | { | 83 | { |
84 | Q_OBJECT | 84 | Q_OBJECT |
85 | 85 | ||
86 | public: | 86 | public: |
87 | typedef QDict<ONetworkInterface> InterfaceMap; | 87 | typedef QDict<ONetworkInterface> InterfaceMap; |
88 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; | 88 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; |
89 | 89 | ||
90 | public: | 90 | public: |
91 | /** | 91 | /** |
92 | * @returns the number of available interfaces | 92 | * @returns the number of available interfaces |
93 | */ | 93 | */ |
94 | int count() const; | 94 | int count() const; |
95 | /** | 95 | /** |
96 | * @returns a pointer to the (one and only) @ref ONetwork instance. | 96 | * @returns a pointer to the (one and only) @ref ONetwork instance. |
97 | */ | 97 | */ |
98 | static ONetwork* instance(); | 98 | static ONetwork* instance(); |
99 | /** | 99 | /** |
100 | * @returns an iterator usable for iterating through all network interfaces. | 100 | * @returns an iterator usable for iterating through all network interfaces. |
101 | */ | 101 | */ |
102 | InterfaceIterator iterator() const; | 102 | InterfaceIterator iterator() const; |
103 | /** | 103 | /** |
104 | * @returns true, if the @a interface supports the wireless extension protocol. | 104 | * @returns true, if the @a interface supports the wireless extension protocol. |
105 | */ | 105 | */ |
106 | // FIXME QString? -zecke | 106 | // FIXME QString? -zecke |
107 | bool isWirelessInterface( const char* interface ) const; | 107 | bool isWirelessInterface( const char* interface ) const; |
108 | /** | 108 | /** |
109 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found | 109 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found |
110 | * @see ONetworkInterface | 110 | * @see ONetworkInterface |
111 | */ | 111 | */ |
112 | // FIXME: const QString& is prefered over QString!!! -zecke | 112 | // FIXME: const QString& is prefered over QString!!! -zecke |
113 | ONetworkInterface* interface( const QString& interface ) const; | 113 | ONetworkInterface* interface( const QString& interface ) const; |
114 | /** | 114 | /** |
115 | * @internal Rebuild the internal interface database | 115 | * @internal Rebuild the internal interface database |
116 | * @note Sometimes it might be useful to call this from client code, | 116 | * @note Sometimes it might be useful to call this from client code, |
117 | * e.g. after issuing a cardctl insert | 117 | * e.g. after issuing a cardctl insert |
118 | */ | 118 | */ |
119 | void synchronize(); | 119 | void synchronize(); |
120 | 120 | ||
121 | protected: | 121 | protected: |
122 | ONetwork(); | 122 | ONetwork(); |
123 | 123 | ||
124 | private: | 124 | private: |
125 | static ONetwork* _instance; | 125 | static ONetwork* _instance; |
126 | InterfaceMap _interfaces; | 126 | InterfaceMap _interfaces; |
127 | }; | 127 | }; |
128 | 128 | ||
129 | 129 | ||
130 | /*====================================================================================== | 130 | /*====================================================================================== |
131 | * ONetworkInterface | 131 | * ONetworkInterface |
132 | *======================================================================================*/ | 132 | *======================================================================================*/ |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * @brief A network interface wrapper. | 135 | * @brief A network interface wrapper. |
136 | * | 136 | * |
137 | * This class provides a wrapper for a network interface. All the cumbersume details of | 137 | * This class provides a wrapper for a network interface. All the cumbersume details of |
138 | * Linux ioctls are hidden under a convenient high-level interface. | 138 | * Linux ioctls are hidden under a convenient high-level interface. |
139 | * @warning Most of the setting methods contained in this class require the appropriate | 139 | * @warning Most of the setting methods contained in this class require the appropriate |
140 | * process permissions to work. | 140 | * process permissions to work. |
141 | * | 141 | * |
142 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 142 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
143 | */ | 143 | */ |
144 | class ONetworkInterface : public QObject | 144 | class ONetworkInterface : public QObject |
145 | { | 145 | { |
146 | friend class OMonitoringInterface; | 146 | friend class OMonitoringInterface; |
147 | friend class OCiscoMonitoringInterface; | 147 | friend class OCiscoMonitoringInterface; |
148 | friend class OWlanNGMonitoringInterface; | 148 | friend class OWlanNGMonitoringInterface; |
149 | friend class OHostAPMonitoringInterface; | 149 | friend class OHostAPMonitoringInterface; |
150 | friend class OOrinocoMonitoringInterface; | 150 | friend class OOrinocoMonitoringInterface; |
151 | 151 | ||
152 | public: | 152 | public: |
153 | /** | 153 | /** |
154 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, | 154 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, |
155 | * but access them via @ref ONetwork::interface(). | 155 | * but access them via @ref ONetwork::interface(). |
156 | */ | 156 | */ |
157 | ONetworkInterface( QObject* parent, const char* name ); | 157 | ONetworkInterface( QObject* parent, const char* name ); |
158 | /** | 158 | /** |
159 | * Destructor. | 159 | * Destructor. |
160 | */ | 160 | */ |
161 | virtual ~ONetworkInterface(); | 161 | virtual ~ONetworkInterface(); |
162 | /** | 162 | /** |
163 | * Associates a @a monitoring interface with this network interface. | 163 | * Associates a @a monitoring interface with this network interface. |
164 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. | 164 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. |
165 | */ | 165 | */ |
166 | void setMonitoring( OMonitoringInterface* monitoring ); | 166 | void setMonitoring( OMonitoringInterface* monitoring ); |
167 | /** | 167 | /** |
168 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. | 168 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. |
169 | */ | 169 | */ |
170 | OMonitoringInterface* monitoring() const; | 170 | OMonitoringInterface* monitoring() const; |
171 | /** | 171 | /** |
172 | * Setting an interface to promiscuous mode enables the device to receive | 172 | * Setting an interface to promiscuous mode enables the device to receive |
173 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. | 173 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. |
174 | */ | 174 | */ |
175 | bool setPromiscuousMode( bool ); | 175 | bool setPromiscuousMode( bool ); |
176 | /** | 176 | /** |
177 | * @returns true if the interface is set to promiscuous mode. | 177 | * @returns true if the interface is set to promiscuous mode. |
178 | */ | 178 | */ |
179 | bool promiscuousMode() const; | 179 | bool promiscuousMode() const; |
180 | /** | 180 | /** |
181 | * Setting an interface to up enables it to receive packets. | 181 | * Setting an interface to up enables it to receive packets. |
182 | */ | 182 | */ |
183 | bool setUp( bool ); | 183 | bool setUp( bool ); |
184 | /** | 184 | /** |
185 | * @returns true if the interface is up. | 185 | * @returns true if the interface is up. |
186 | */ | 186 | */ |
187 | bool isUp() const; | 187 | bool isUp() const; |
188 | /** | 188 | /** |
189 | * @returns true if the interface is a loopback interface. | 189 | * @returns true if the interface is a loopback interface. |
190 | */ | 190 | */ |
191 | bool isLoopback() const; | 191 | bool isLoopback() const; |
192 | /** | 192 | /** |
193 | * @returns true if the interface is featuring supports the wireless extension protocol. | 193 | * @returns true if the interface is featuring supports the wireless extension protocol. |
194 | */ | 194 | */ |
195 | bool isWireless() const; | 195 | bool isWireless() const; |
196 | /** | 196 | /** |
197 | * Associate the IP address @ addr with the interface. | 197 | * Associate the IP address @ addr with the interface. |
198 | */ | 198 | */ |
199 | void setIPV4Address( const QHostAddress& addr ); | 199 | void setIPV4Address( const QHostAddress& addr ); |
200 | /** | 200 | /** |
201 | * @returns the IPv4 address associated with the interface. | 201 | * @returns the IPv4 address associated with the interface. |
202 | */ | 202 | */ |
203 | QString ipV4Address() const; //TODO: make this return an OHostAddress | 203 | QString ipV4Address() const; //TODO: make this return an OHostAddress |
204 | /** | 204 | /** |
205 | * Associate the MAC address @a addr with the interface. | 205 | * Associate the MAC address @a addr with the interface. |
206 | * @note It can be necessary to shut down the interface prior to calling this method. | 206 | * @note It can be necessary to shut down the interface prior to calling this method. |
207 | * @warning This is not supported by all drivers. | 207 | * @warning This is not supported by all drivers. |
208 | */ | 208 | */ |
209 | void setMacAddress( const OMacAddress& addr ); | 209 | void setMacAddress( const OMacAddress& addr ); |
210 | /** | 210 | /** |
211 | * @returns the MAC address associated with the interface. | 211 | * @returns the MAC address associated with the interface. |
212 | */ | 212 | */ |
213 | OMacAddress macAddress() const; | 213 | OMacAddress macAddress() const; |
214 | /** | 214 | /** |
215 | * Associate the IPv4 @a netmask with the interface. | 215 | * Associate the IPv4 @a netmask with the interface. |
216 | */ | 216 | */ |
217 | void setIPV4Netmask( const QHostAddress& netmask ); | 217 | void setIPV4Netmask( const QHostAddress& netmask ); |
218 | /** | 218 | /** |
219 | * @returns the IPv4 netmask associated with the interface. | 219 | * @returns the IPv4 netmask associated with the interface. |
220 | */ | 220 | */ |
221 | QString ipV4Netmask() const; //TODO: make this return an OHostAddress | 221 | QString ipV4Netmask() const; //TODO: make this return an OHostAddress |
222 | /** | 222 | /** |
223 | * @returns the data link type currently associated with the interface. | 223 | * @returns the data link type currently associated with the interface. |
224 | * @see #include <net/if_arp.h> for possible values. | 224 | * @see #include <net/if_arp.h> for possible values. |
225 | */ | 225 | */ |
226 | int dataLinkType() const; | 226 | int dataLinkType() const; |
227 | 227 | ||
228 | protected: | 228 | protected: |
229 | const int _sfd; | 229 | const int _sfd; |
230 | mutable ifreq _ifr; | 230 | mutable ifreq _ifr; |
231 | OMonitoringInterface* _mon; | 231 | OMonitoringInterface* _mon; |
232 | 232 | ||
233 | protected: | 233 | protected: |
234 | struct ifreq& ifr() const; | 234 | struct ifreq& ifr() const; |
235 | virtual void init(); | 235 | virtual void init(); |
236 | bool ioctl( int call ) const; | 236 | bool ioctl( int call ) const; |
237 | bool ioctl( int call, struct ifreq& ) const; | 237 | bool ioctl( int call, struct ifreq& ) const; |
238 | }; | 238 | }; |
239 | 239 | ||
240 | /*====================================================================================== | 240 | /*====================================================================================== |
241 | * OChannelHopper | 241 | * OChannelHopper |
242 | *======================================================================================*/ | 242 | *======================================================================================*/ |
243 | 243 | ||
244 | /** | 244 | /** |
245 | * @brief A radio frequency channel hopper. | 245 | * @brief A radio frequency channel hopper. |
246 | * | 246 | * |
247 | * This class provides a channel hopper for radio frequencies. A channel hopper frequently | 247 | * This class provides a channel hopper for radio frequencies. A channel hopper frequently |
248 | * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. | 248 | * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. |
249 | * This is necessary when in monitoring mode and scanning for other devices, because | 249 | * This is necessary when in monitoring mode and scanning for other devices, because |
250 | * the radio frequency hardware can only detect packets sent on the same frequency. | 250 | * the radio frequency hardware can only detect packets sent on the same frequency. |
251 | * | 251 | * |
252 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 252 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
253 | */ | 253 | */ |
254 | class OChannelHopper : public QObject | 254 | class OChannelHopper : public QObject |
255 | { | 255 | { |
256 | Q_OBJECT | 256 | Q_OBJECT |
257 | 257 | ||
258 | public: | 258 | public: |
259 | /** | 259 | /** |
260 | * Constructor. | 260 | * Constructor. |
261 | */ | 261 | */ |
262 | OChannelHopper( OWirelessNetworkInterface* ); | 262 | OChannelHopper( OWirelessNetworkInterface* ); |
263 | /** | 263 | /** |
264 | * Destructor. | 264 | * Destructor. |
265 | */ | 265 | */ |
266 | virtual ~OChannelHopper(); | 266 | virtual ~OChannelHopper(); |
267 | /** | 267 | /** |
268 | * @returns true, if the channel hopper is hopping channels | 268 | * @returns true, if the channel hopper is hopping channels |
269 | */ | 269 | */ |
270 | bool isActive() const; | 270 | bool isActive() const; |
271 | /** | 271 | /** |
272 | * @returns the last hopped channel | 272 | * @returns the last hopped channel |
273 | */ | 273 | */ |
274 | int channel() const; | 274 | int channel() const; |
275 | /** | 275 | /** |
276 | * Set the channel hopping @a interval. | 276 | * Set the channel hopping @a interval. |
277 | * An interval of 0 deactivates the channel hopper. | 277 | * An interval of 0 deactivates the channel hopper. |
278 | */ | 278 | */ |
279 | void setInterval( int interval ); | 279 | void setInterval( int interval ); |
280 | /** | 280 | /** |
281 | * @returns the channel hopping interval | 281 | * @returns the channel hopping interval |
282 | */ | 282 | */ |
283 | int interval() const; | 283 | int interval() const; |
284 | 284 | ||
285 | signals: | 285 | signals: |
286 | /** | 286 | /** |
287 | * This signal is emitted right after the channel hopper performed a hop | 287 | * This signal is emitted right after the channel hopper performed a hop |
288 | */ | 288 | */ |
289 | void hopped( int ); | 289 | void hopped( int ); |
290 | 290 | ||
291 | protected: | 291 | protected: |
292 | virtual void timerEvent( QTimerEvent* ); | 292 | virtual void timerEvent( QTimerEvent* ); |
293 | 293 | ||
294 | private: | 294 | private: |
295 | OWirelessNetworkInterface* _iface; | 295 | OWirelessNetworkInterface* _iface; |
296 | int _interval; | 296 | int _interval; |
297 | int _tid; | 297 | int _tid; |
298 | QValueList<int> _channels; | 298 | QValueList<int> _channels; |
299 | QValueList<int>::Iterator _channel; | 299 | QValueList<int>::Iterator _channel; |
300 | }; | 300 | }; |
301 | 301 | ||
302 | 302 | ||
303 | /*====================================================================================== | 303 | /*====================================================================================== |
304 | * OWirelessNetworkInterface | 304 | * OWirelessNetworkInterface |
305 | *======================================================================================*/ | 305 | *======================================================================================*/ |
306 | 306 | ||
307 | /** | 307 | /** |
308 | * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. | 308 | * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. |
309 | * | 309 | * |
310 | * This class provides a high-level encapsulation of the Linux wireless extension API. | 310 | * This class provides a high-level encapsulation of the Linux wireless extension API. |
311 | * | 311 | * |
312 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 312 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
313 | */ | 313 | */ |
314 | class OWirelessNetworkInterface : public ONetworkInterface | 314 | class OWirelessNetworkInterface : public ONetworkInterface |
315 | { | 315 | { |
316 | friend class OMonitoringInterface; | 316 | friend class OMonitoringInterface; |
317 | friend class OCiscoMonitoringInterface; | 317 | friend class OCiscoMonitoringInterface; |
318 | friend class OWlanNGMonitoringInterface; | 318 | friend class OWlanNGMonitoringInterface; |
319 | friend class OHostAPMonitoringInterface; | 319 | friend class OHostAPMonitoringInterface; |
320 | friend class OOrinocoMonitoringInterface; | 320 | friend class OOrinocoMonitoringInterface; |
321 | 321 | ||
322 | friend class OPrivateIOCTL; | 322 | friend class OPrivateIOCTL; |
323 | 323 | ||
324 | public: | 324 | public: |
325 | /** | 325 | /** |
326 | * Constructor. | 326 | * Constructor. |
327 | */ | 327 | */ |
328 | OWirelessNetworkInterface( QObject* parent, const char* name ); | 328 | OWirelessNetworkInterface( QObject* parent, const char* name ); |
329 | /** | 329 | /** |
330 | * Destructor. | 330 | * Destructor. |
331 | */ | 331 | */ |
332 | virtual ~OWirelessNetworkInterface(); | 332 | virtual ~OWirelessNetworkInterface(); |
333 | /** | 333 | /** |
334 | * Setting the @a channel of the interface changes the radio frequency (RF) | 334 | * Setting the @a channel of the interface changes the radio frequency (RF) |
335 | * of the corresponding wireless network device. | 335 | * of the corresponding wireless network device. |
336 | */ | 336 | */ |
337 | virtual void setChannel( int channel ) const; | 337 | virtual void setChannel( int channel ) const; |
338 | /** | 338 | /** |
339 | * @returns the channel index of the current radio frequency. | 339 | * @returns the channel index of the current radio frequency. |
340 | */ | 340 | */ |
341 | virtual int channel() const; | 341 | virtual int channel() const; |
342 | /** | 342 | /** |
343 | * @returns the current radio frequency (in MHz). | 343 | * @returns the current radio frequency (in MHz). |
344 | */ | 344 | */ |
345 | virtual double frequency() const; | 345 | virtual double frequency() const; |
346 | /** | 346 | /** |
347 | * @returns the number of radio frequency channels for the | 347 | * @returns the number of radio frequency channels for the |
348 | * corresponding wireless network device. | 348 | * corresponding wireless network device. |
349 | * @note European devices usually have 14 channels, while American typically feature 11 channels. | 349 | * @note European devices usually have 14 channels, while American typically feature 11 channels. |
350 | */ | 350 | */ |
351 | virtual int channels() const; | 351 | virtual int channels() const; |
352 | /** | 352 | /** |
353 | * Set the IEEE 802.11 operation @a mode. | 353 | * Set the IEEE 802.11 operation @a mode. |
354 | * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master | 354 | * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master |
355 | * @warning Not all drivers support the all modes. | 355 | * @warning Not all drivers support the all modes. |
356 | * @note You might have to change the SSID to get the operation mode change into effect. | 356 | * @note You might have to change the SSID to get the operation mode change into effect. |
357 | */ | 357 | */ |
358 | virtual void setMode( const QString& mode ); | 358 | virtual void setMode( const QString& mode ); |
359 | /** | 359 | /** |
360 | * @returns the current IEEE 802.11 operation mode. | 360 | * @returns the current IEEE 802.11 operation mode. |
361 | * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown | 361 | * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown |
362 | */ | 362 | */ |
363 | virtual QString mode() const; | 363 | virtual QString mode() const; |
364 | /** | 364 | /** |
365 | * Setting the monitor mode on a wireless network interface enables | 365 | * Setting the monitor mode on a wireless network interface enables |
366 | * listening to IEEE 802.11 data and management frames which normally | 366 | * listening to IEEE 802.11 data and management frames which normally |
367 | * are handled by the device firmware. This can be used to detect | 367 | * are handled by the device firmware. This can be used to detect |
368 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. | 368 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. |
369 | * @warning Standard wireless network drives don't support the monitor mode. | 369 | * @warning Standard wireless network drives don't support the monitor mode. |
370 | * @warning You need a patched driver for this to work. | 370 | * @warning You need a patched driver for this to work. |
371 | * @note Enabling the monitor mode is highly driver dependent and requires | 371 | * @note Enabling the monitor mode is highly driver dependent and requires |
372 | * the proper @ref OMonitoringInterface to be associated with the interface. | 372 | * the proper @ref OMonitoringInterface to be associated with the interface. |
373 | * @see OMonitoringInterface | 373 | * @see OMonitoringInterface |
374 | */ | 374 | */ |
375 | virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); | 375 | virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); |
376 | /** | 376 | /** |
377 | * @returns true if the device is listening in IEEE 802.11 monitor mode | 377 | * @returns true if the device is listening in IEEE 802.11 monitor mode |
378 | */ | 378 | */ |
379 | virtual bool monitorMode() const; //FIXME: ==> mode() | 379 | virtual bool monitorMode() const; //FIXME: ==> mode() |
380 | /** | 380 | /** |
381 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. | 381 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. |
382 | * @see OChannelHopper | 382 | * @see OChannelHopper |
383 | */ | 383 | */ |
384 | virtual void setChannelHopping( int interval = 0 ); | 384 | virtual void setChannelHopping( int interval = 0 ); |
385 | /** | 385 | /** |
386 | * @returns the channel hopping interval or 0, if channel hopping is disabled. | 386 | * @returns the channel hopping interval or 0, if channel hopping is disabled. |
387 | */ | 387 | */ |
388 | virtual int channelHopping() const; | 388 | virtual int channelHopping() const; |
389 | /** | 389 | /** |
390 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before | 390 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before |
391 | */ | 391 | */ |
392 | virtual OChannelHopper* channelHopper() const; | 392 | virtual OChannelHopper* channelHopper() const; |
393 | /** | 393 | /** |
394 | * Set the station @a nickname. | 394 | * Set the station @a nickname. |
395 | */ | 395 | */ |
396 | virtual void setNickName( const QString& nickname ); | 396 | virtual void setNickName( const QString& nickname ); |
397 | /** | 397 | /** |
398 | * @returns the current station nickname. | 398 | * @returns the current station nickname. |
399 | */ | 399 | */ |
400 | virtual QString nickName() const; | 400 | virtual QString nickName() const; |
401 | /** | 401 | /** |
402 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. | 402 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. |
403 | * @see OPrivateIOCTL | 403 | * @see OPrivateIOCTL |
404 | */ | 404 | */ |
405 | virtual void setPrivate( const QString& command, int number, ... ); | 405 | virtual void setPrivate( const QString& command, int number, ... ); |
406 | /** | 406 | /** |
407 | * @returns true if the interface is featuring the private IOCTL @command. | 407 | * @returns true if the interface is featuring the private IOCTL @command. |
408 | */ | 408 | */ |
409 | virtual bool hasPrivate( const QString& command ); | 409 | virtual bool hasPrivate( const QString& command ); |
410 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this | 410 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this |
411 | 411 | ||
412 | virtual bool isAssociated() const {}; //FIXME: Implement and document this | 412 | virtual bool isAssociated() const {}; //FIXME: Implement and document this |
413 | /** | 413 | /** |
414 | * @returns the MAC address of the Access Point if the | 414 | * @returns the MAC address of the Access Point if the |
415 | * device is in infrastructure mode. @returns a (more or less random) CELL | 415 | * device is in infrastructure mode. @returns a (more or less random) CELL |
416 | * address if the device is in adhoc mode. | 416 | * address if the device is in adhoc mode. |
417 | */ | 417 | */ |
418 | virtual QString associatedAP() const; | 418 | virtual QString associatedAP() const; |
419 | /** | 419 | /** |
420 | * Set the @a ssid (Service Set ID) string. This is used to decide | 420 | * Set the @a ssid (Service Set ID) string. This is used to decide |
421 | * which network to associate with (use "any" to let the driver decide). | 421 | * which network to associate with (use "any" to let the driver decide). |
422 | */ | 422 | */ |
423 | virtual void setSSID( const QString& ssid ); | 423 | virtual void setSSID( const QString& ssid ); |
424 | /** | 424 | /** |
425 | * @returns the current SSID (Service Set ID). | 425 | * @returns the current SSID (Service Set ID). |
426 | */ | 426 | */ |
427 | virtual QString SSID() const; | 427 | virtual QString SSID() const; |
428 | 428 | ||
429 | protected: | 429 | protected: |
430 | void buildChannelList(); | 430 | void buildChannelList(); |
431 | void buildPrivateList(); | 431 | void buildPrivateList(); |
432 | virtual void init(); | 432 | virtual void init(); |
433 | struct iwreq& iwr() const; | 433 | struct iwreq& iwr() const; |
434 | bool wioctl( int call ) const; | 434 | bool wioctl( int call ) const; |
435 | bool wioctl( int call, struct iwreq& ) const; | 435 | bool wioctl( int call, struct iwreq& ) const; |
436 | 436 | ||
437 | protected: | 437 | protected: |
438 | mutable struct iwreq _iwr; | 438 | mutable struct iwreq _iwr; |
439 | QMap<int,int> _channels; | 439 | QMap<int,int> _channels; |
440 | 440 | ||
441 | private: | 441 | private: |
442 | OChannelHopper* _hopper; | 442 | OChannelHopper* _hopper; |
443 | }; | 443 | }; |
444 | 444 | ||
445 | 445 | ||
446 | /*====================================================================================== | 446 | /*====================================================================================== |
447 | * OMonitoringInterface | 447 | * OMonitoringInterface |
448 | *======================================================================================*/ | 448 | *======================================================================================*/ |
449 | 449 | ||
450 | 450 | ||
451 | class OMonitoringInterface | 451 | class OMonitoringInterface |
452 | { | 452 | { |
453 | public: | 453 | public: |
454 | OMonitoringInterface(); | 454 | OMonitoringInterface(); |
455 | OMonitoringInterface( ONetworkInterface* ); | 455 | OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
456 | virtual ~OMonitoringInterface(); | 456 | virtual ~OMonitoringInterface(); |
457 | 457 | ||
458 | public: | 458 | public: |
459 | virtual void setEnabled( bool ); | 459 | virtual void setEnabled( bool ); |
460 | virtual bool enabled() const; | 460 | virtual bool enabled() const; |
461 | virtual void setChannel( int ); | 461 | virtual void setChannel( int ); |
462 | 462 | ||
463 | virtual QString name() const = 0; | 463 | virtual QString name() const = 0; |
464 | 464 | ||
465 | protected: | 465 | protected: |
466 | OWirelessNetworkInterface* _if; | 466 | OWirelessNetworkInterface* _if; |
467 | bool _prismHeader; | ||
467 | 468 | ||
468 | }; | 469 | }; |
469 | 470 | ||
470 | 471 | ||
471 | /*====================================================================================== | 472 | /*====================================================================================== |
472 | * OCiscoMonitoring | 473 | * OCiscoMonitoring |
473 | *======================================================================================*/ | 474 | *======================================================================================*/ |
474 | 475 | ||
475 | 476 | ||
476 | class OCiscoMonitoringInterface : public OMonitoringInterface | 477 | class OCiscoMonitoringInterface : public OMonitoringInterface |
477 | { | 478 | { |
478 | public: | 479 | public: |
479 | OCiscoMonitoringInterface( ONetworkInterface* ); | 480 | OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
480 | virtual ~OCiscoMonitoringInterface(); | 481 | virtual ~OCiscoMonitoringInterface(); |
481 | 482 | ||
482 | virtual void setEnabled( bool ); | 483 | virtual void setEnabled( bool ); |
483 | virtual QString name() const; | 484 | virtual QString name() const; |
484 | virtual void setChannel( int ); | 485 | virtual void setChannel( int ); |
485 | 486 | ||
486 | }; | 487 | }; |
487 | 488 | ||
488 | /*====================================================================================== | 489 | /*====================================================================================== |
489 | * OWlanNGMonitoringInterface | 490 | * OWlanNGMonitoringInterface |
490 | *======================================================================================*/ | 491 | *======================================================================================*/ |
491 | 492 | ||
492 | class OWlanNGMonitoringInterface : public OMonitoringInterface | 493 | class OWlanNGMonitoringInterface : public OMonitoringInterface |
493 | { | 494 | { |
494 | public: | 495 | public: |
495 | OWlanNGMonitoringInterface( ONetworkInterface* ); | 496 | OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
496 | virtual ~OWlanNGMonitoringInterface(); | 497 | virtual ~OWlanNGMonitoringInterface(); |
497 | 498 | ||
498 | public: | 499 | public: |
499 | virtual void setEnabled( bool ); | 500 | virtual void setEnabled( bool ); |
500 | virtual QString name() const; | 501 | virtual QString name() const; |
501 | virtual void setChannel( int ); | 502 | virtual void setChannel( int ); |
502 | 503 | ||
503 | }; | 504 | }; |
504 | 505 | ||
505 | /*====================================================================================== | 506 | /*====================================================================================== |
506 | * OHostAPMonitoringInterface | 507 | * OHostAPMonitoringInterface |
507 | *======================================================================================*/ | 508 | *======================================================================================*/ |
508 | 509 | ||
509 | class OHostAPMonitoringInterface : public OMonitoringInterface | 510 | class OHostAPMonitoringInterface : public OMonitoringInterface |
510 | { | 511 | { |
511 | public: | 512 | public: |
512 | OHostAPMonitoringInterface( ONetworkInterface* ); | 513 | OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
513 | virtual ~OHostAPMonitoringInterface(); | 514 | virtual ~OHostAPMonitoringInterface(); |
514 | 515 | ||
515 | public: | 516 | public: |
516 | virtual void setEnabled( bool ); | 517 | virtual void setEnabled( bool ); |
517 | virtual QString name() const; | 518 | virtual QString name() const; |
518 | }; | 519 | }; |
519 | 520 | ||
520 | /*====================================================================================== | 521 | /*====================================================================================== |
521 | * OOrinocoMonitoringInterface | 522 | * OOrinocoMonitoringInterface |
522 | *======================================================================================*/ | 523 | *======================================================================================*/ |
523 | 524 | ||
524 | class OOrinocoMonitoringInterface : public OMonitoringInterface | 525 | class OOrinocoMonitoringInterface : public OMonitoringInterface |
525 | { | 526 | { |
526 | public: | 527 | public: |
527 | OOrinocoMonitoringInterface( ONetworkInterface* ); | 528 | OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
528 | virtual ~OOrinocoMonitoringInterface(); | 529 | virtual ~OOrinocoMonitoringInterface(); |
529 | 530 | ||
530 | public: | 531 | public: |
531 | virtual void setChannel( int ); | 532 | virtual void setChannel( int ); |
532 | virtual void setEnabled( bool ); | 533 | virtual void setEnabled( bool ); |
533 | virtual QString name() const; | 534 | virtual QString name() const; |
534 | 535 | ||
535 | }; | 536 | }; |
536 | 537 | ||
537 | #endif // ONETWORK_H | 538 | #endif // ONETWORK_H |
538 | 539 | ||
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index e2ab6d7..f6d05ea 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -1,1057 +1,1057 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 by the Wellenreiter team: | 3 | Copyright (C) 2003 by the Wellenreiter team: |
4 | Martin J. Muench <mjm@remote-exploit.org> | 4 | Martin J. Muench <mjm@remote-exploit.org> |
5 | Max Moser <mmo@remote-exploit.org | 5 | Max Moser <mmo@remote-exploit.org |
6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | 35 | ||
36 | #include <opie2/opcap.h> | 36 | #include <opie2/opcap.h> |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | 39 | ||
40 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) | 40 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) |
41 | #include <qsocketnotifier.h> | 41 | #include <qsocketnotifier.h> |
42 | #include <qobjectlist.h> | 42 | #include <qobjectlist.h> |
43 | 43 | ||
44 | /*====================================================================================== | 44 | /*====================================================================================== |
45 | * OPacket | 45 | * OPacket |
46 | *======================================================================================*/ | 46 | *======================================================================================*/ |
47 | 47 | ||
48 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) | 48 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) |
49 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) | 49 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) |
50 | { | 50 | { |
51 | //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); | 51 | //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); |
52 | 52 | ||
53 | _end = (unsigned char*) data + header.len; | 53 | _end = (unsigned char*) data + header.len; |
54 | //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); | 54 | //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); |
55 | 55 | ||
56 | switch ( datalink ) | 56 | switch ( datalink ) |
57 | { | 57 | { |
58 | case DLT_EN10MB: | 58 | case DLT_EN10MB: |
59 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); | 59 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); |
60 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); | 60 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); |
61 | break; | 61 | break; |
62 | 62 | ||
63 | case DLT_IEEE802_11: | 63 | case DLT_IEEE802_11: |
64 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); | 64 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); |
65 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); | 65 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); |
66 | break; | 66 | break; |
67 | 67 | ||
68 | case DLT_PRISM_HEADER: | 68 | case DLT_PRISM_HEADER: |
69 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" ); | 69 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" ); |
70 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); | 70 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); |
71 | break; | 71 | break; |
72 | 72 | ||
73 | default: | 73 | default: |
74 | qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink '%s'!", datalink ); | 74 | qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink (type %d)!", datalink ); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | OPacket::~OPacket() | 79 | OPacket::~OPacket() |
80 | { | 80 | { |
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
84 | timevalstruct OPacket::timeval() const | 84 | timevalstruct OPacket::timeval() const |
85 | { | 85 | { |
86 | return _hdr.ts; | 86 | return _hdr.ts; |
87 | } | 87 | } |
88 | 88 | ||
89 | 89 | ||
90 | int OPacket::caplen() const | 90 | int OPacket::caplen() const |
91 | { | 91 | { |
92 | return _hdr.caplen; | 92 | return _hdr.caplen; |
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) | 96 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) |
97 | { | 97 | { |
98 | if (!l) return; | 98 | if (!l) return; |
99 | QObject* o = l->first(); | 99 | QObject* o = l->first(); |
100 | while ( o ) | 100 | while ( o ) |
101 | { | 101 | { |
102 | stats[o->name()]++; | 102 | stats[o->name()]++; |
103 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); | 103 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); |
104 | o = l->next(); | 104 | o = l->next(); |
105 | } | 105 | } |
106 | } | 106 | } |
107 | 107 | ||
108 | 108 | ||
109 | QString OPacket::dump( int bpl ) const | 109 | QString OPacket::dump( int bpl ) const |
110 | { | 110 | { |
111 | static int index = 0; | 111 | static int index = 0; |
112 | index++; | 112 | index++; |
113 | int len = _hdr.caplen; | 113 | int len = _hdr.caplen; |
114 | QString str; | 114 | QString str; |
115 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); | 115 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); |
116 | str.append( "0000: " ); | 116 | str.append( "0000: " ); |
117 | QString tmp; | 117 | QString tmp; |
118 | QString bytes; | 118 | QString bytes; |
119 | QString chars; | 119 | QString chars; |
120 | 120 | ||
121 | for ( int i = 0; i < len; ++i ) | 121 | for ( int i = 0; i < len; ++i ) |
122 | { | 122 | { |
123 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); | 123 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); |
124 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); | 124 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); |
125 | else chars.append( '.' ); | 125 | else chars.append( '.' ); |
126 | 126 | ||
127 | if ( !((i+1) % bpl) ) | 127 | if ( !((i+1) % bpl) ) |
128 | { | 128 | { |
129 | str.append( bytes ); | 129 | str.append( bytes ); |
130 | str.append( ' ' ); | 130 | str.append( ' ' ); |
131 | str.append( chars ); | 131 | str.append( chars ); |
132 | str.append( '\n' ); | 132 | str.append( '\n' ); |
133 | tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); | 133 | tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); |
134 | bytes = ""; | 134 | bytes = ""; |
135 | chars = ""; | 135 | chars = ""; |
136 | } | 136 | } |
137 | 137 | ||
138 | } | 138 | } |
139 | if ( (len % bpl) ) | 139 | if ( (len % bpl) ) |
140 | { | 140 | { |
141 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); | 141 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); |
142 | str.append( chars ); | 142 | str.append( chars ); |
143 | } | 143 | } |
144 | str.append( '\n' ); | 144 | str.append( '\n' ); |
145 | return str; | 145 | return str; |
146 | } | 146 | } |
147 | 147 | ||
148 | 148 | ||
149 | int OPacket::len() const | 149 | int OPacket::len() const |
150 | { | 150 | { |
151 | return _hdr.len; | 151 | return _hdr.len; |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | /*====================================================================================== | 155 | /*====================================================================================== |
156 | * OEthernetPacket | 156 | * OEthernetPacket |
157 | *======================================================================================*/ | 157 | *======================================================================================*/ |
158 | 158 | ||
159 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) | 159 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
160 | :QObject( parent, "Ethernet" ), _ether( data ) | 160 | :QObject( parent, "Ethernet" ), _ether( data ) |
161 | { | 161 | { |
162 | 162 | ||
163 | qDebug( "Source = %s", (const char*) sourceAddress().toString() ); | 163 | qDebug( "Source = %s", (const char*) sourceAddress().toString() ); |
164 | qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); | 164 | qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); |
165 | 165 | ||
166 | if ( sourceAddress() == OMacAddress::broadcast ) | 166 | if ( sourceAddress() == OMacAddress::broadcast ) |
167 | qDebug( "Source is broadcast address" ); | 167 | qDebug( "Source is broadcast address" ); |
168 | if ( destinationAddress() == OMacAddress::broadcast ) | 168 | if ( destinationAddress() == OMacAddress::broadcast ) |
169 | qDebug( "Destination is broadcast address" ); | 169 | qDebug( "Destination is broadcast address" ); |
170 | 170 | ||
171 | switch ( type() ) | 171 | switch ( type() ) |
172 | { | 172 | { |
173 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 173 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
174 | case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } | 174 | case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } |
175 | case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } | 175 | case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } |
176 | default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); | 176 | default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); |
177 | } | 177 | } |
178 | 178 | ||
179 | } | 179 | } |
180 | 180 | ||
181 | 181 | ||
182 | OEthernetPacket::~OEthernetPacket() | 182 | OEthernetPacket::~OEthernetPacket() |
183 | { | 183 | { |
184 | } | 184 | } |
185 | 185 | ||
186 | 186 | ||
187 | OMacAddress OEthernetPacket::sourceAddress() const | 187 | OMacAddress OEthernetPacket::sourceAddress() const |
188 | { | 188 | { |
189 | return OMacAddress( _ether->ether_shost ); | 189 | return OMacAddress( _ether->ether_shost ); |
190 | } | 190 | } |
191 | 191 | ||
192 | 192 | ||
193 | OMacAddress OEthernetPacket::destinationAddress() const | 193 | OMacAddress OEthernetPacket::destinationAddress() const |
194 | { | 194 | { |
195 | return OMacAddress( _ether->ether_dhost ); | 195 | return OMacAddress( _ether->ether_dhost ); |
196 | } | 196 | } |
197 | 197 | ||
198 | int OEthernetPacket::type() const | 198 | int OEthernetPacket::type() const |
199 | { | 199 | { |
200 | return ntohs( _ether->ether_type ); | 200 | return ntohs( _ether->ether_type ); |
201 | } | 201 | } |
202 | 202 | ||
203 | 203 | ||
204 | /*====================================================================================== | 204 | /*====================================================================================== |
205 | * OIPPacket | 205 | * OIPPacket |
206 | *======================================================================================*/ | 206 | *======================================================================================*/ |
207 | 207 | ||
208 | 208 | ||
209 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) | 209 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) |
210 | :QObject( parent, "IP" ), _iphdr( data ) | 210 | :QObject( parent, "IP" ), _iphdr( data ) |
211 | { | 211 | { |
212 | qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); | 212 | qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); |
213 | 213 | ||
214 | //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); | 214 | //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); |
215 | //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); | 215 | //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); |
216 | 216 | ||
217 | qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); | 217 | qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); |
218 | qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); | 218 | qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); |
219 | 219 | ||
220 | switch ( protocol() ) | 220 | switch ( protocol() ) |
221 | { | 221 | { |
222 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; | 222 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
223 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; | 223 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
224 | default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); | 224 | default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); |
225 | } | 225 | } |
226 | 226 | ||
227 | } | 227 | } |
228 | 228 | ||
229 | OIPPacket::~OIPPacket() | 229 | OIPPacket::~OIPPacket() |
230 | { | 230 | { |
231 | } | 231 | } |
232 | 232 | ||
233 | 233 | ||
234 | QHostAddress OIPPacket::fromIPAddress() const | 234 | QHostAddress OIPPacket::fromIPAddress() const |
235 | { | 235 | { |
236 | return EXTRACT_32BITS( &_iphdr->saddr ); | 236 | return EXTRACT_32BITS( &_iphdr->saddr ); |
237 | } | 237 | } |
238 | 238 | ||
239 | 239 | ||
240 | QHostAddress OIPPacket::toIPAddress() const | 240 | QHostAddress OIPPacket::toIPAddress() const |
241 | { | 241 | { |
242 | return EXTRACT_32BITS( &_iphdr->saddr ); | 242 | return EXTRACT_32BITS( &_iphdr->saddr ); |
243 | } | 243 | } |
244 | 244 | ||
245 | 245 | ||
246 | int OIPPacket::tos() const | 246 | int OIPPacket::tos() const |
247 | { | 247 | { |
248 | return _iphdr->tos; | 248 | return _iphdr->tos; |
249 | } | 249 | } |
250 | 250 | ||
251 | 251 | ||
252 | int OIPPacket::len() const | 252 | int OIPPacket::len() const |
253 | { | 253 | { |
254 | return EXTRACT_16BITS( &_iphdr->tot_len ); | 254 | return EXTRACT_16BITS( &_iphdr->tot_len ); |
255 | } | 255 | } |
256 | 256 | ||
257 | 257 | ||
258 | int OIPPacket::id() const | 258 | int OIPPacket::id() const |
259 | { | 259 | { |
260 | return EXTRACT_16BITS( &_iphdr->id ); | 260 | return EXTRACT_16BITS( &_iphdr->id ); |
261 | } | 261 | } |
262 | 262 | ||
263 | 263 | ||
264 | int OIPPacket::offset() const | 264 | int OIPPacket::offset() const |
265 | { | 265 | { |
266 | return EXTRACT_16BITS( &_iphdr->frag_off ); | 266 | return EXTRACT_16BITS( &_iphdr->frag_off ); |
267 | } | 267 | } |
268 | 268 | ||
269 | 269 | ||
270 | int OIPPacket::ttl() const | 270 | int OIPPacket::ttl() const |
271 | { | 271 | { |
272 | return _iphdr->ttl; | 272 | return _iphdr->ttl; |
273 | } | 273 | } |
274 | 274 | ||
275 | 275 | ||
276 | int OIPPacket::protocol() const | 276 | int OIPPacket::protocol() const |
277 | { | 277 | { |
278 | return _iphdr->protocol; | 278 | return _iphdr->protocol; |
279 | } | 279 | } |
280 | 280 | ||
281 | 281 | ||
282 | int OIPPacket::checksum() const | 282 | int OIPPacket::checksum() const |
283 | { | 283 | { |
284 | return EXTRACT_16BITS( &_iphdr->check ); | 284 | return EXTRACT_16BITS( &_iphdr->check ); |
285 | } | 285 | } |
286 | 286 | ||
287 | /*====================================================================================== | 287 | /*====================================================================================== |
288 | * OARPPacket | 288 | * OARPPacket |
289 | *======================================================================================*/ | 289 | *======================================================================================*/ |
290 | 290 | ||
291 | 291 | ||
292 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) | 292 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) |
293 | :QObject( parent, "ARP" ), _arphdr( data ) | 293 | :QObject( parent, "ARP" ), _arphdr( data ) |
294 | { | 294 | { |
295 | qDebug( "OARPPacket::OARPPacket(): decoding ARP header..." ); | 295 | qDebug( "OARPPacket::OARPPacket(): decoding ARP header..." ); |
296 | qDebug( "ARP type seems to be %02d - '%s'", EXTRACT_16BITS( &_arphdr->ar_op ), (const char*) type() ); | 296 | qDebug( "ARP type seems to be %02d - '%s'", EXTRACT_16BITS( &_arphdr->ar_op ), (const char*) type() ); |
297 | qDebug( "Sender: MAC %s = IP %s", (const char*) senderMacAddress().toString(), (const char*) senderIPV4Address().toString() ); | 297 | qDebug( "Sender: MAC %s = IP %s", (const char*) senderMacAddress().toString(), (const char*) senderIPV4Address().toString() ); |
298 | qDebug( "Target: MAC %s = IP %s", (const char*) targetMacAddress().toString(), (const char*) targetIPV4Address().toString() ); | 298 | qDebug( "Target: MAC %s = IP %s", (const char*) targetMacAddress().toString(), (const char*) targetIPV4Address().toString() ); |
299 | } | 299 | } |
300 | 300 | ||
301 | 301 | ||
302 | OARPPacket::~OARPPacket() | 302 | OARPPacket::~OARPPacket() |
303 | { | 303 | { |
304 | } | 304 | } |
305 | 305 | ||
306 | 306 | ||
307 | QString OARPPacket::type() const | 307 | QString OARPPacket::type() const |
308 | { | 308 | { |
309 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) | 309 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) |
310 | { | 310 | { |
311 | case 1: return "REQUEST"; | 311 | case 1: return "REQUEST"; |
312 | case 2: return "REPLY"; | 312 | case 2: return "REPLY"; |
313 | case 3: return "RREQUEST"; | 313 | case 3: return "RREQUEST"; |
314 | case 4: return "RREPLY"; | 314 | case 4: return "RREPLY"; |
315 | case 8: return "InREQUEST"; | 315 | case 8: return "InREQUEST"; |
316 | case 9: return "InREPLY"; | 316 | case 9: return "InREPLY"; |
317 | case 10: return "NAK"; | 317 | case 10: return "NAK"; |
318 | default: qWarning( "OARPPacket::type(): invalid ARP type!" ); return "<unknown>"; | 318 | default: qWarning( "OARPPacket::type(): invalid ARP type!" ); return "<unknown>"; |
319 | } | 319 | } |
320 | } | 320 | } |
321 | 321 | ||
322 | 322 | ||
323 | QHostAddress OARPPacket::senderIPV4Address() const | 323 | QHostAddress OARPPacket::senderIPV4Address() const |
324 | { | 324 | { |
325 | return EXTRACT_32BITS( &_arphdr->ar_sip ); | 325 | return EXTRACT_32BITS( &_arphdr->ar_sip ); |
326 | } | 326 | } |
327 | 327 | ||
328 | 328 | ||
329 | QHostAddress OARPPacket::targetIPV4Address() const | 329 | QHostAddress OARPPacket::targetIPV4Address() const |
330 | { | 330 | { |
331 | return EXTRACT_32BITS( &_arphdr->ar_tip ); | 331 | return EXTRACT_32BITS( &_arphdr->ar_tip ); |
332 | } | 332 | } |
333 | 333 | ||
334 | 334 | ||
335 | OMacAddress OARPPacket::senderMacAddress() const | 335 | OMacAddress OARPPacket::senderMacAddress() const |
336 | { | 336 | { |
337 | return OMacAddress( _arphdr->ar_sha ); | 337 | return OMacAddress( _arphdr->ar_sha ); |
338 | } | 338 | } |
339 | 339 | ||
340 | 340 | ||
341 | OMacAddress OARPPacket::targetMacAddress() const | 341 | OMacAddress OARPPacket::targetMacAddress() const |
342 | { | 342 | { |
343 | return OMacAddress( _arphdr->ar_tha ); | 343 | return OMacAddress( _arphdr->ar_tha ); |
344 | } | 344 | } |
345 | 345 | ||
346 | 346 | ||
347 | /*====================================================================================== | 347 | /*====================================================================================== |
348 | * OUDPPacket | 348 | * OUDPPacket |
349 | *======================================================================================*/ | 349 | *======================================================================================*/ |
350 | 350 | ||
351 | 351 | ||
352 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) | 352 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) |
353 | :QObject( parent, "UDP" ), _udphdr( data ) | 353 | :QObject( parent, "UDP" ), _udphdr( data ) |
354 | 354 | ||
355 | { | 355 | { |
356 | qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); | 356 | qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); |
357 | } | 357 | } |
358 | 358 | ||
359 | OUDPPacket::~OUDPPacket() | 359 | OUDPPacket::~OUDPPacket() |
360 | { | 360 | { |
361 | } | 361 | } |
362 | 362 | ||
363 | 363 | ||
364 | /*====================================================================================== | 364 | /*====================================================================================== |
365 | * OTCPPacket | 365 | * OTCPPacket |
366 | *======================================================================================*/ | 366 | *======================================================================================*/ |
367 | 367 | ||
368 | 368 | ||
369 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) | 369 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) |
370 | :QObject( parent, "TCP" ), _tcphdr( data ) | 370 | :QObject( parent, "TCP" ), _tcphdr( data ) |
371 | 371 | ||
372 | { | 372 | { |
373 | qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); | 373 | qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); |
374 | } | 374 | } |
375 | 375 | ||
376 | OTCPPacket::~OTCPPacket() | 376 | OTCPPacket::~OTCPPacket() |
377 | { | 377 | { |
378 | } | 378 | } |
379 | 379 | ||
380 | 380 | ||
381 | /*====================================================================================== | 381 | /*====================================================================================== |
382 | * OPrismHeaderPacket | 382 | * OPrismHeaderPacket |
383 | *======================================================================================*/ | 383 | *======================================================================================*/ |
384 | 384 | ||
385 | 385 | ||
386 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) | 386 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) |
387 | :QObject( parent, "Prism" ), _header( data ) | 387 | :QObject( parent, "Prism" ), _header( data ) |
388 | 388 | ||
389 | { | 389 | { |
390 | qDebug( "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." ); | 390 | qDebug( "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." ); |
391 | 391 | ||
392 | qDebug( "Signal Strength = %d", data->signal.data ); | 392 | qDebug( "Signal Strength = %d", data->signal.data ); |
393 | 393 | ||
394 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); | 394 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); |
395 | } | 395 | } |
396 | 396 | ||
397 | OPrismHeaderPacket::~OPrismHeaderPacket() | 397 | OPrismHeaderPacket::~OPrismHeaderPacket() |
398 | { | 398 | { |
399 | } | 399 | } |
400 | 400 | ||
401 | 401 | ||
402 | unsigned int OPrismHeaderPacket::signalStrength() const | 402 | unsigned int OPrismHeaderPacket::signalStrength() const |
403 | { | 403 | { |
404 | return _header->signal.data; | 404 | return _header->signal.data; |
405 | } | 405 | } |
406 | 406 | ||
407 | /*====================================================================================== | 407 | /*====================================================================================== |
408 | * OWaveLanPacket | 408 | * OWaveLanPacket |
409 | *======================================================================================*/ | 409 | *======================================================================================*/ |
410 | 410 | ||
411 | 411 | ||
412 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) | 412 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) |
413 | :QObject( parent, "802.11" ), _wlanhdr( data ) | 413 | :QObject( parent, "802.11" ), _wlanhdr( data ) |
414 | 414 | ||
415 | { | 415 | { |
416 | qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); | 416 | qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); |
417 | qDebug( "type: %0X", type() ); | 417 | qDebug( "type: %0X", type() ); |
418 | qDebug( "subType: %0X", subType() ); | 418 | qDebug( "subType: %0X", subType() ); |
419 | qDebug( "duration: %d", duration() ); | 419 | qDebug( "duration: %d", duration() ); |
420 | qDebug( "powermanagement: %d", usesPowerManagement() ); | 420 | qDebug( "powermanagement: %d", usesPowerManagement() ); |
421 | qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); | 421 | qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); |
422 | qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); | 422 | qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); |
423 | qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); | 423 | qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); |
424 | qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); | 424 | qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); |
425 | qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); | 425 | qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); |
426 | 426 | ||
427 | switch ( type() ) | 427 | switch ( type() ) |
428 | { | 428 | { |
429 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; | 429 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
430 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; | 430 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
431 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; | 431 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; |
432 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); | 432 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); |
433 | } | 433 | } |
434 | } | 434 | } |
435 | 435 | ||
436 | OWaveLanPacket::~OWaveLanPacket() | 436 | OWaveLanPacket::~OWaveLanPacket() |
437 | { | 437 | { |
438 | } | 438 | } |
439 | 439 | ||
440 | 440 | ||
441 | int OWaveLanPacket::duration() const | 441 | int OWaveLanPacket::duration() const |
442 | { | 442 | { |
443 | return _wlanhdr->duration; | 443 | return _wlanhdr->duration; |
444 | } | 444 | } |
445 | 445 | ||
446 | 446 | ||
447 | OMacAddress OWaveLanPacket::macAddress1() const | 447 | OMacAddress OWaveLanPacket::macAddress1() const |
448 | { | 448 | { |
449 | return OMacAddress( _wlanhdr->mac1 ); | 449 | return OMacAddress( _wlanhdr->mac1 ); |
450 | } | 450 | } |
451 | 451 | ||
452 | 452 | ||
453 | OMacAddress OWaveLanPacket::macAddress2() const | 453 | OMacAddress OWaveLanPacket::macAddress2() const |
454 | { | 454 | { |
455 | return OMacAddress( _wlanhdr->mac2 ); | 455 | return OMacAddress( _wlanhdr->mac2 ); |
456 | } | 456 | } |
457 | 457 | ||
458 | 458 | ||
459 | OMacAddress OWaveLanPacket::macAddress3() const | 459 | OMacAddress OWaveLanPacket::macAddress3() const |
460 | { | 460 | { |
461 | return OMacAddress( _wlanhdr->mac3 ); | 461 | return OMacAddress( _wlanhdr->mac3 ); |
462 | } | 462 | } |
463 | 463 | ||
464 | 464 | ||
465 | OMacAddress OWaveLanPacket::macAddress4() const | 465 | OMacAddress OWaveLanPacket::macAddress4() const |
466 | { | 466 | { |
467 | return OMacAddress( _wlanhdr->mac4 ); | 467 | return OMacAddress( _wlanhdr->mac4 ); |
468 | } | 468 | } |
469 | 469 | ||
470 | 470 | ||
471 | int OWaveLanPacket::subType() const | 471 | int OWaveLanPacket::subType() const |
472 | { | 472 | { |
473 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 473 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
474 | } | 474 | } |
475 | 475 | ||
476 | 476 | ||
477 | int OWaveLanPacket::type() const | 477 | int OWaveLanPacket::type() const |
478 | { | 478 | { |
479 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 479 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
480 | } | 480 | } |
481 | 481 | ||
482 | 482 | ||
483 | int OWaveLanPacket::version() const | 483 | int OWaveLanPacket::version() const |
484 | { | 484 | { |
485 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 485 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
486 | } | 486 | } |
487 | 487 | ||
488 | 488 | ||
489 | bool OWaveLanPacket::fromDS() const | 489 | bool OWaveLanPacket::fromDS() const |
490 | { | 490 | { |
491 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 491 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
492 | } | 492 | } |
493 | 493 | ||
494 | 494 | ||
495 | bool OWaveLanPacket::toDS() const | 495 | bool OWaveLanPacket::toDS() const |
496 | { | 496 | { |
497 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 497 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
498 | } | 498 | } |
499 | 499 | ||
500 | 500 | ||
501 | bool OWaveLanPacket::usesPowerManagement() const | 501 | bool OWaveLanPacket::usesPowerManagement() const |
502 | { | 502 | { |
503 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 503 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
504 | } | 504 | } |
505 | 505 | ||
506 | 506 | ||
507 | bool OWaveLanPacket::usesWep() const | 507 | bool OWaveLanPacket::usesWep() const |
508 | { | 508 | { |
509 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 509 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
510 | } | 510 | } |
511 | 511 | ||
512 | 512 | ||
513 | /*====================================================================================== | 513 | /*====================================================================================== |
514 | * OWaveLanManagementPacket | 514 | * OWaveLanManagementPacket |
515 | *======================================================================================*/ | 515 | *======================================================================================*/ |
516 | 516 | ||
517 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) | 517 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) |
518 | :QObject( parent, "802.11 Management" ), _header( data ), | 518 | :QObject( parent, "802.11 Management" ), _header( data ), |
519 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) | 519 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) |
520 | { | 520 | { |
521 | qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); | 521 | qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); |
522 | qDebug( "Detected subtype is '%s'", (const char*) managementType() ); | 522 | qDebug( "Detected subtype is '%s'", (const char*) managementType() ); |
523 | 523 | ||
524 | // grab tagged values | 524 | // grab tagged values |
525 | const unsigned char* ptr = (const unsigned char*) (_body+1); | 525 | const unsigned char* ptr = (const unsigned char*) (_body+1); |
526 | while (ptr < end) | 526 | while (ptr < end) |
527 | { | 527 | { |
528 | switch ( *ptr ) | 528 | switch ( *ptr ) |
529 | { | 529 | { |
530 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; | 530 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; |
531 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; | 531 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; |
532 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; | 532 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; |
533 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; | 533 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; |
534 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; | 534 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; |
535 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; | 535 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; |
536 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; | 536 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; |
537 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; | 537 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; |
538 | } | 538 | } |
539 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value | 539 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value |
540 | ptr+= 2; // skip tag ID and length | 540 | ptr+= 2; // skip tag ID and length |
541 | } | 541 | } |
542 | } | 542 | } |
543 | 543 | ||
544 | 544 | ||
545 | OWaveLanManagementPacket::~OWaveLanManagementPacket() | 545 | OWaveLanManagementPacket::~OWaveLanManagementPacket() |
546 | { | 546 | { |
547 | } | 547 | } |
548 | 548 | ||
549 | 549 | ||
550 | QString OWaveLanManagementPacket::managementType() const | 550 | QString OWaveLanManagementPacket::managementType() const |
551 | { | 551 | { |
552 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) | 552 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) |
553 | { | 553 | { |
554 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; | 554 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; |
555 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; | 555 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; |
556 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; | 556 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; |
557 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; | 557 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; |
558 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; | 558 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; |
559 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; | 559 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; |
560 | case ST_BEACON: return "Beacon"; break; | 560 | case ST_BEACON: return "Beacon"; break; |
561 | case ST_ATIM: return "Atim"; break; | 561 | case ST_ATIM: return "Atim"; break; |
562 | case ST_DISASSOC: return "Disassociation"; break; | 562 | case ST_DISASSOC: return "Disassociation"; break; |
563 | case ST_AUTH: return "Authentication"; break; | 563 | case ST_AUTH: return "Authentication"; break; |
564 | case ST_DEAUTH: return "Deathentication"; break; | 564 | case ST_DEAUTH: return "Deathentication"; break; |
565 | default: | 565 | default: |
566 | qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); | 566 | qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); |
567 | return "Unknown"; | 567 | return "Unknown"; |
568 | } | 568 | } |
569 | } | 569 | } |
570 | 570 | ||
571 | 571 | ||
572 | int OWaveLanManagementPacket::beaconInterval() const | 572 | int OWaveLanManagementPacket::beaconInterval() const |
573 | { | 573 | { |
574 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); | 574 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); |
575 | } | 575 | } |
576 | 576 | ||
577 | 577 | ||
578 | int OWaveLanManagementPacket::capabilities() const | 578 | int OWaveLanManagementPacket::capabilities() const |
579 | { | 579 | { |
580 | return EXTRACT_LE_16BITS( &_body->capability_info ); | 580 | return EXTRACT_LE_16BITS( &_body->capability_info ); |
581 | } | 581 | } |
582 | 582 | ||
583 | 583 | ||
584 | bool OWaveLanManagementPacket::canESS() const | 584 | bool OWaveLanManagementPacket::canESS() const |
585 | { | 585 | { |
586 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 586 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
587 | } | 587 | } |
588 | 588 | ||
589 | 589 | ||
590 | bool OWaveLanManagementPacket::canIBSS() const | 590 | bool OWaveLanManagementPacket::canIBSS() const |
591 | { | 591 | { |
592 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 592 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
593 | } | 593 | } |
594 | 594 | ||
595 | 595 | ||
596 | bool OWaveLanManagementPacket::canCFP() const | 596 | bool OWaveLanManagementPacket::canCFP() const |
597 | { | 597 | { |
598 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 598 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
599 | } | 599 | } |
600 | 600 | ||
601 | 601 | ||
602 | bool OWaveLanManagementPacket::canCFP_REQ() const | 602 | bool OWaveLanManagementPacket::canCFP_REQ() const |
603 | { | 603 | { |
604 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 604 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
605 | } | 605 | } |
606 | 606 | ||
607 | 607 | ||
608 | bool OWaveLanManagementPacket::canPrivacy() const | 608 | bool OWaveLanManagementPacket::canPrivacy() const |
609 | { | 609 | { |
610 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 610 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
611 | } | 611 | } |
612 | 612 | ||
613 | 613 | ||
614 | /*====================================================================================== | 614 | /*====================================================================================== |
615 | * OWaveLanManagementSSID | 615 | * OWaveLanManagementSSID |
616 | *======================================================================================*/ | 616 | *======================================================================================*/ |
617 | 617 | ||
618 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) | 618 | OWaveLanManagementSSID::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 | ||
625 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | 625 | OWaveLanManagementSSID::~OWaveLanManagementSSID() |
626 | { | 626 | { |
627 | } | 627 | } |
628 | 628 | ||
629 | 629 | ||
630 | QString OWaveLanManagementSSID::ID() const | 630 | QString 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 | ||
645 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) | 645 | OWaveLanManagementRates::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 | ||
652 | OWaveLanManagementRates::~OWaveLanManagementRates() | 652 | OWaveLanManagementRates::~OWaveLanManagementRates() |
653 | { | 653 | { |
654 | } | 654 | } |
655 | 655 | ||
656 | /*====================================================================================== | 656 | /*====================================================================================== |
657 | * OWaveLanManagementCF | 657 | * OWaveLanManagementCF |
658 | *======================================================================================*/ | 658 | *======================================================================================*/ |
659 | 659 | ||
660 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) | 660 | OWaveLanManagementCF::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 | ||
667 | OWaveLanManagementCF::~OWaveLanManagementCF() | 667 | OWaveLanManagementCF::~OWaveLanManagementCF() |
668 | { | 668 | { |
669 | } | 669 | } |
670 | 670 | ||
671 | /*====================================================================================== | 671 | /*====================================================================================== |
672 | * OWaveLanManagementFH | 672 | * OWaveLanManagementFH |
673 | *======================================================================================*/ | 673 | *======================================================================================*/ |
674 | 674 | ||
675 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) | 675 | OWaveLanManagementFH::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 | ||
682 | OWaveLanManagementFH::~OWaveLanManagementFH() | 682 | OWaveLanManagementFH::~OWaveLanManagementFH() |
683 | { | 683 | { |
684 | } | 684 | } |
685 | 685 | ||
686 | /*====================================================================================== | 686 | /*====================================================================================== |
687 | * OWaveLanManagementDS | 687 | * OWaveLanManagementDS |
688 | *======================================================================================*/ | 688 | *======================================================================================*/ |
689 | 689 | ||
690 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) | 690 | OWaveLanManagementDS::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 | ||
697 | OWaveLanManagementDS::~OWaveLanManagementDS() | 697 | OWaveLanManagementDS::~OWaveLanManagementDS() |
698 | { | 698 | { |
699 | } | 699 | } |
700 | 700 | ||
701 | 701 | ||
702 | int OWaveLanManagementDS::channel() const | 702 | int 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 | ||
711 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) | 711 | OWaveLanManagementTim::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 | ||
718 | OWaveLanManagementTim::~OWaveLanManagementTim() | 718 | OWaveLanManagementTim::~OWaveLanManagementTim() |
719 | { | 719 | { |
720 | } | 720 | } |
721 | 721 | ||
722 | /*====================================================================================== | 722 | /*====================================================================================== |
723 | * OWaveLanManagementIBSS | 723 | * OWaveLanManagementIBSS |
724 | *======================================================================================*/ | 724 | *======================================================================================*/ |
725 | 725 | ||
726 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) | 726 | OWaveLanManagementIBSS::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 | ||
733 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | 733 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() |
734 | { | 734 | { |
735 | } | 735 | } |
736 | 736 | ||
737 | /*====================================================================================== | 737 | /*====================================================================================== |
738 | * OWaveLanManagementChallenge | 738 | * OWaveLanManagementChallenge |
739 | *======================================================================================*/ | 739 | *======================================================================================*/ |
740 | 740 | ||
741 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) | 741 | OWaveLanManagementChallenge::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 | ||
748 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | 748 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() |
749 | { | 749 | { |
750 | } | 750 | } |
751 | 751 | ||
752 | /*====================================================================================== | 752 | /*====================================================================================== |
753 | * OWaveLanDataPacket | 753 | * OWaveLanDataPacket |
754 | *======================================================================================*/ | 754 | *======================================================================================*/ |
755 | 755 | ||
756 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) | 756 | OWaveLanDataPacket::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 | ||
770 | OWaveLanDataPacket::~OWaveLanDataPacket() | 770 | OWaveLanDataPacket::~OWaveLanDataPacket() |
771 | { | 771 | { |
772 | } | 772 | } |
773 | 773 | ||
774 | 774 | ||
775 | /*====================================================================================== | 775 | /*====================================================================================== |
776 | * OLLCPacket | 776 | * OLLCPacket |
777 | *======================================================================================*/ | 777 | *======================================================================================*/ |
778 | 778 | ||
779 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) | 779 | OLLCPacket::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 | ||
799 | OLLCPacket::~OLLCPacket() | 799 | OLLCPacket::~OLLCPacket() |
800 | { | 800 | { |
801 | } | 801 | } |
802 | 802 | ||
803 | 803 | ||
804 | /*====================================================================================== | 804 | /*====================================================================================== |
805 | * OWaveLanControlPacket | 805 | * OWaveLanControlPacket |
806 | *======================================================================================*/ | 806 | *======================================================================================*/ |
807 | 807 | ||
808 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) | 808 | OWaveLanControlPacket::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 Data" ), _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 | ||
816 | OWaveLanControlPacket::~OWaveLanControlPacket() | 816 | OWaveLanControlPacket::~OWaveLanControlPacket() |
817 | { | 817 | { |
818 | } | 818 | } |
819 | 819 | ||
820 | 820 | ||
821 | /*====================================================================================== | 821 | /*====================================================================================== |
822 | * OPacketCapturer | 822 | * OPacketCapturer |
823 | *======================================================================================*/ | 823 | *======================================================================================*/ |
824 | 824 | ||
825 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | 825 | OPacketCapturer::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 | ||
832 | OPacketCapturer::~OPacketCapturer() | 832 | OPacketCapturer::~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 | ||
842 | void OPacketCapturer::setBlocking( bool b ) | 842 | void 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 | ||
855 | bool OPacketCapturer::blocking() const | 855 | bool 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 | ||
867 | void OPacketCapturer::close() | 867 | void 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 | ||
894 | int OPacketCapturer::dataLink() const | 894 | int OPacketCapturer::dataLink() const |
895 | { | 895 | { |
896 | return pcap_datalink( _pch ); | 896 | return pcap_datalink( _pch ); |
897 | } | 897 | } |
898 | 898 | ||
899 | 899 | ||
900 | int OPacketCapturer::fileno() const | 900 | int 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 | ||
912 | OPacket* OPacketCapturer::next() | 912 | OPacket* 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 | ||
941 | bool OPacketCapturer::open( const QString& name, const QString& filename ) | 941 | bool 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 | ||
992 | bool OPacketCapturer::open( const QFile& file ) | 992 | bool 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; |
1002 | } | 1002 | } |
1003 | else // close the last opened device | 1003 | else // close the last opened device |
1004 | { | 1004 | { |
1005 | close(); | 1005 | close(); |
1006 | } | 1006 | } |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | _name = name; | 1009 | _name = name; |
1010 | 1010 | ||
1011 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); | 1011 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); |
1012 | 1012 | ||
1013 | if ( handle ) | 1013 | if ( handle ) |
1014 | { | 1014 | { |
1015 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); | 1015 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); |
1016 | _pch = handle; | 1016 | _pch = handle; |
1017 | _open = true; | 1017 | _open = true; |
1018 | 1018 | ||
1019 | // in case we have an application object, create a socket notifier | 1019 | // in case we have an application object, create a socket notifier |
1020 | if ( qApp ) | 1020 | if ( qApp ) |
1021 | { | 1021 | { |
1022 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 1022 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
1023 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1023 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1024 | } | 1024 | } |
1025 | 1025 | ||
1026 | return true; | 1026 | return true; |
1027 | } | 1027 | } |
1028 | else | 1028 | else |
1029 | { | 1029 | { |
1030 | qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); | 1030 | qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); |
1031 | return false; | 1031 | return false; |
1032 | } | 1032 | } |
1033 | 1033 | ||
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | 1036 | ||
1037 | bool OPacketCapturer::isOpen() const | 1037 | bool OPacketCapturer::isOpen() const |
1038 | { | 1038 | { |
1039 | return _open; | 1039 | return _open; |
1040 | } | 1040 | } |
1041 | 1041 | ||
1042 | 1042 | ||
1043 | void OPacketCapturer::readyToReceive() | 1043 | void OPacketCapturer::readyToReceive() |
1044 | { | 1044 | { |
1045 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); | 1045 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); |
1046 | OPacket* p = next(); | 1046 | OPacket* p = next(); |
1047 | emit receivedPacket( p ); | 1047 | emit receivedPacket( p ); |
1048 | // emit is synchronous - packet has been dealt with, now it's safe to delete | 1048 | // emit is synchronous - packet has been dealt with, now it's safe to delete |
1049 | delete p; | 1049 | delete p; |
1050 | } | 1050 | } |
1051 | 1051 | ||
1052 | 1052 | ||
1053 | const QMap<QString,int>& OPacketCapturer::statistics() const | 1053 | const QMap<QString,int>& OPacketCapturer::statistics() const |
1054 | { | 1054 | { |
1055 | return _stats; | 1055 | return _stats; |
1056 | } | 1056 | } |
1057 | 1057 | ||