-rw-r--r-- | libopie2/opienet/opcap.cpp | 82 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 10 |
2 files changed, 92 insertions, 0 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index f1f2b4b..7a6f61b 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -220,392 +220,474 @@ OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObjec | |||
220 | qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); | 220 | qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); |
221 | 221 | ||
222 | switch ( protocol() ) | 222 | switch ( protocol() ) |
223 | { | 223 | { |
224 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; | 224 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
225 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; | 225 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
226 | default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); | 226 | default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); |
227 | } | 227 | } |
228 | 228 | ||
229 | } | 229 | } |
230 | 230 | ||
231 | OIPPacket::~OIPPacket() | 231 | OIPPacket::~OIPPacket() |
232 | { | 232 | { |
233 | } | 233 | } |
234 | 234 | ||
235 | 235 | ||
236 | QHostAddress OIPPacket::fromIPAddress() const | 236 | QHostAddress OIPPacket::fromIPAddress() const |
237 | { | 237 | { |
238 | return EXTRACT_32BITS( &_iphdr->saddr ); | 238 | return EXTRACT_32BITS( &_iphdr->saddr ); |
239 | } | 239 | } |
240 | 240 | ||
241 | 241 | ||
242 | QHostAddress OIPPacket::toIPAddress() const | 242 | QHostAddress OIPPacket::toIPAddress() const |
243 | { | 243 | { |
244 | return EXTRACT_32BITS( &_iphdr->saddr ); | 244 | return EXTRACT_32BITS( &_iphdr->saddr ); |
245 | } | 245 | } |
246 | 246 | ||
247 | 247 | ||
248 | int OIPPacket::tos() const | 248 | int OIPPacket::tos() const |
249 | { | 249 | { |
250 | return _iphdr->tos; | 250 | return _iphdr->tos; |
251 | } | 251 | } |
252 | 252 | ||
253 | 253 | ||
254 | int OIPPacket::len() const | 254 | int OIPPacket::len() const |
255 | { | 255 | { |
256 | return EXTRACT_16BITS( &_iphdr->tot_len ); | 256 | return EXTRACT_16BITS( &_iphdr->tot_len ); |
257 | } | 257 | } |
258 | 258 | ||
259 | 259 | ||
260 | int OIPPacket::id() const | 260 | int OIPPacket::id() const |
261 | { | 261 | { |
262 | return EXTRACT_16BITS( &_iphdr->id ); | 262 | return EXTRACT_16BITS( &_iphdr->id ); |
263 | } | 263 | } |
264 | 264 | ||
265 | 265 | ||
266 | int OIPPacket::offset() const | 266 | int OIPPacket::offset() const |
267 | { | 267 | { |
268 | return EXTRACT_16BITS( &_iphdr->frag_off ); | 268 | return EXTRACT_16BITS( &_iphdr->frag_off ); |
269 | } | 269 | } |
270 | 270 | ||
271 | 271 | ||
272 | int OIPPacket::ttl() const | 272 | int OIPPacket::ttl() const |
273 | { | 273 | { |
274 | return _iphdr->ttl; | 274 | return _iphdr->ttl; |
275 | } | 275 | } |
276 | 276 | ||
277 | 277 | ||
278 | int OIPPacket::protocol() const | 278 | int OIPPacket::protocol() const |
279 | { | 279 | { |
280 | return _iphdr->protocol; | 280 | return _iphdr->protocol; |
281 | } | 281 | } |
282 | 282 | ||
283 | 283 | ||
284 | int OIPPacket::checksum() const | 284 | int OIPPacket::checksum() const |
285 | { | 285 | { |
286 | return EXTRACT_16BITS( &_iphdr->check ); | 286 | return EXTRACT_16BITS( &_iphdr->check ); |
287 | } | 287 | } |
288 | 288 | ||
289 | /*====================================================================================== | 289 | /*====================================================================================== |
290 | * OARPPacket | 290 | * OARPPacket |
291 | *======================================================================================*/ | 291 | *======================================================================================*/ |
292 | 292 | ||
293 | 293 | ||
294 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) | 294 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) |
295 | :QObject( parent, "ARP" ), _arphdr( data ) | 295 | :QObject( parent, "ARP" ), _arphdr( data ) |
296 | { | 296 | { |
297 | qDebug( "OARPPacket::OARPPacket(): decoding ARP header..." ); | 297 | qDebug( "OARPPacket::OARPPacket(): decoding ARP header..." ); |
298 | qDebug( "ARP type seems to be %02d - '%s'", EXTRACT_16BITS( &_arphdr->ar_op ), (const char*) type() ); | 298 | qDebug( "ARP type seems to be %02d - '%s'", EXTRACT_16BITS( &_arphdr->ar_op ), (const char*) type() ); |
299 | qDebug( "Sender: MAC %s = IP %s", (const char*) senderMacAddress().toString(), (const char*) senderIPV4Address().toString() ); | 299 | qDebug( "Sender: MAC %s = IP %s", (const char*) senderMacAddress().toString(), (const char*) senderIPV4Address().toString() ); |
300 | qDebug( "Target: MAC %s = IP %s", (const char*) targetMacAddress().toString(), (const char*) targetIPV4Address().toString() ); | 300 | qDebug( "Target: MAC %s = IP %s", (const char*) targetMacAddress().toString(), (const char*) targetIPV4Address().toString() ); |
301 | } | 301 | } |
302 | 302 | ||
303 | 303 | ||
304 | OARPPacket::~OARPPacket() | 304 | OARPPacket::~OARPPacket() |
305 | { | 305 | { |
306 | } | 306 | } |
307 | 307 | ||
308 | 308 | ||
309 | QString OARPPacket::type() const | 309 | QString OARPPacket::type() const |
310 | { | 310 | { |
311 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) | 311 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) |
312 | { | 312 | { |
313 | case 1: return "REQUEST"; | 313 | case 1: return "REQUEST"; |
314 | case 2: return "REPLY"; | 314 | case 2: return "REPLY"; |
315 | case 3: return "RREQUEST"; | 315 | case 3: return "RREQUEST"; |
316 | case 4: return "RREPLY"; | 316 | case 4: return "RREPLY"; |
317 | case 8: return "InREQUEST"; | 317 | case 8: return "InREQUEST"; |
318 | case 9: return "InREPLY"; | 318 | case 9: return "InREPLY"; |
319 | case 10: return "NAK"; | 319 | case 10: return "NAK"; |
320 | default: qWarning( "OARPPacket::type(): invalid ARP type!" ); return "<unknown>"; | 320 | default: qWarning( "OARPPacket::type(): invalid ARP type!" ); return "<unknown>"; |
321 | } | 321 | } |
322 | } | 322 | } |
323 | 323 | ||
324 | 324 | ||
325 | QHostAddress OARPPacket::senderIPV4Address() const | 325 | QHostAddress OARPPacket::senderIPV4Address() const |
326 | { | 326 | { |
327 | return EXTRACT_32BITS( &_arphdr->ar_sip ); | 327 | return EXTRACT_32BITS( &_arphdr->ar_sip ); |
328 | } | 328 | } |
329 | 329 | ||
330 | 330 | ||
331 | QHostAddress OARPPacket::targetIPV4Address() const | 331 | QHostAddress OARPPacket::targetIPV4Address() const |
332 | { | 332 | { |
333 | return EXTRACT_32BITS( &_arphdr->ar_tip ); | 333 | return EXTRACT_32BITS( &_arphdr->ar_tip ); |
334 | } | 334 | } |
335 | 335 | ||
336 | 336 | ||
337 | OMacAddress OARPPacket::senderMacAddress() const | 337 | OMacAddress OARPPacket::senderMacAddress() const |
338 | { | 338 | { |
339 | return OMacAddress( _arphdr->ar_sha ); | 339 | return OMacAddress( _arphdr->ar_sha ); |
340 | } | 340 | } |
341 | 341 | ||
342 | 342 | ||
343 | OMacAddress OARPPacket::targetMacAddress() const | 343 | OMacAddress OARPPacket::targetMacAddress() const |
344 | { | 344 | { |
345 | return OMacAddress( _arphdr->ar_tha ); | 345 | return OMacAddress( _arphdr->ar_tha ); |
346 | } | 346 | } |
347 | 347 | ||
348 | 348 | ||
349 | /*====================================================================================== | 349 | /*====================================================================================== |
350 | * OUDPPacket | 350 | * OUDPPacket |
351 | *======================================================================================*/ | 351 | *======================================================================================*/ |
352 | 352 | ||
353 | 353 | ||
354 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) | 354 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) |
355 | :QObject( parent, "UDP" ), _udphdr( data ) | 355 | :QObject( parent, "UDP" ), _udphdr( data ) |
356 | 356 | ||
357 | { | 357 | { |
358 | qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); | 358 | qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); |
359 | qDebug( "fromPort = %d", fromPort() ); | 359 | qDebug( "fromPort = %d", fromPort() ); |
360 | qDebug( " toPort = %d", toPort() ); | 360 | qDebug( " toPort = %d", toPort() ); |
361 | 361 | ||
362 | // TODO: Make this a case or a hash if we know more udp protocols | 362 | // TODO: Make this a case or a hash if we know more udp protocols |
363 | 363 | ||
364 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || | 364 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || |
365 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) | 365 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) |
366 | { | 366 | { |
367 | qDebug( "seems to be part of a DHCP conversation => creating DHCP packet." ); | 367 | qDebug( "seems to be part of a DHCP conversation => creating DHCP packet." ); |
368 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); | 368 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); |
369 | } | 369 | } |
370 | } | 370 | } |
371 | 371 | ||
372 | 372 | ||
373 | OUDPPacket::~OUDPPacket() | 373 | OUDPPacket::~OUDPPacket() |
374 | { | 374 | { |
375 | } | 375 | } |
376 | 376 | ||
377 | 377 | ||
378 | int OUDPPacket::fromPort() const | 378 | int OUDPPacket::fromPort() const |
379 | { | 379 | { |
380 | return EXTRACT_16BITS( &_udphdr->source ); | 380 | return EXTRACT_16BITS( &_udphdr->source ); |
381 | } | 381 | } |
382 | 382 | ||
383 | 383 | ||
384 | int OUDPPacket::toPort() const | 384 | int OUDPPacket::toPort() const |
385 | { | 385 | { |
386 | return EXTRACT_16BITS( &_udphdr->dest ); | 386 | return EXTRACT_16BITS( &_udphdr->dest ); |
387 | } | 387 | } |
388 | 388 | ||
389 | 389 | ||
390 | int OUDPPacket::length() const | 390 | int OUDPPacket::length() const |
391 | { | 391 | { |
392 | return EXTRACT_16BITS( &_udphdr->len ); | 392 | return EXTRACT_16BITS( &_udphdr->len ); |
393 | } | 393 | } |
394 | 394 | ||
395 | 395 | ||
396 | int OUDPPacket::checksum() const | 396 | int OUDPPacket::checksum() const |
397 | { | 397 | { |
398 | return EXTRACT_16BITS( &_udphdr->check ); | 398 | return EXTRACT_16BITS( &_udphdr->check ); |
399 | } | 399 | } |
400 | 400 | ||
401 | 401 | ||
402 | /*====================================================================================== | 402 | /*====================================================================================== |
403 | * ODHCPPacket | 403 | * ODHCPPacket |
404 | *======================================================================================*/ | 404 | *======================================================================================*/ |
405 | 405 | ||
406 | 406 | ||
407 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) | 407 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) |
408 | :QObject( parent, "DHCP" ), _dhcphdr( data ) | 408 | :QObject( parent, "DHCP" ), _dhcphdr( data ) |
409 | 409 | ||
410 | { | 410 | { |
411 | qDebug( "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." ); | 411 | qDebug( "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." ); |
412 | qDebug( "DHCP opcode seems to be %02d - '%s'", _dhcphdr->op, isRequest() ? "REQUEST" : "REPLY" ); | ||
413 | qDebug( "clientAddress: %s", (const char*) clientAddress().toString() ); | ||
414 | qDebug( " yourAddress: %s", (const char*) yourAddress().toString() ); | ||
415 | qDebug( "serverAddress: %s", (const char*) serverAddress().toString() ); | ||
416 | qDebug( " relayAddress: %s", (const char*) relayAddress().toString() ); | ||
417 | qDebug( "parsing DHCP options..." ); | ||
418 | |||
419 | _type = 0; | ||
420 | |||
421 | const unsigned char* option = &_dhcphdr->options[4]; | ||
422 | char tag = -1; | ||
423 | char len = -1; | ||
424 | |||
425 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) | ||
426 | { | ||
427 | len = *option++; | ||
428 | qDebug( "recognized DHCP option #%d, length %d", tag, len ); | ||
429 | |||
430 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) | ||
431 | _type = *option; | ||
432 | |||
433 | option += len; | ||
434 | if ( option >= end ) | ||
435 | { | ||
436 | qWarning( "DHCP parsing ERROR: sanity check says the packet is at its end!" ); | ||
437 | break; | ||
438 | } | ||
439 | } | ||
440 | |||
441 | qDebug( "DHCP type seems to be '%s'", (const char*) type() ); | ||
412 | } | 442 | } |
413 | 443 | ||
414 | 444 | ||
415 | ODHCPPacket::~ODHCPPacket() | 445 | ODHCPPacket::~ODHCPPacket() |
416 | { | 446 | { |
417 | } | 447 | } |
418 | 448 | ||
419 | 449 | ||
450 | bool ODHCPPacket::isRequest() const | ||
451 | { | ||
452 | return ( _dhcphdr->op == 01 ); | ||
453 | } | ||
454 | |||
455 | |||
456 | bool ODHCPPacket::isReply() const | ||
457 | { | ||
458 | return ( _dhcphdr->op == 02 ); | ||
459 | } | ||
460 | |||
461 | |||
462 | QString ODHCPPacket::type() const | ||
463 | { | ||
464 | switch ( _type ) | ||
465 | { | ||
466 | case 1: return "DISCOVER"; | ||
467 | case 2: return "OFFER"; | ||
468 | case 3: return "REQUEST"; | ||
469 | case 4: return "DECLINE"; | ||
470 | case 5: return "ACK"; | ||
471 | case 6: return "NAK"; | ||
472 | case 7: return "RELEASE"; | ||
473 | case 8: return "INFORM"; | ||
474 | default: qWarning( "ODHCPPacket::type(): invalid DHCP type (%d) !", _dhcphdr->op ); return "<unknown>"; | ||
475 | } | ||
476 | } | ||
477 | |||
478 | |||
479 | QHostAddress ODHCPPacket::clientAddress() const | ||
480 | { | ||
481 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); | ||
482 | } | ||
483 | |||
484 | |||
485 | QHostAddress ODHCPPacket::yourAddress() const | ||
486 | { | ||
487 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); | ||
488 | } | ||
489 | |||
490 | |||
491 | QHostAddress ODHCPPacket::serverAddress() const | ||
492 | { | ||
493 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); | ||
494 | } | ||
495 | |||
496 | |||
497 | QHostAddress ODHCPPacket::relayAddress() const | ||
498 | { | ||
499 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); | ||
500 | } | ||
501 | |||
420 | /*====================================================================================== | 502 | /*====================================================================================== |
421 | * OTCPPacket | 503 | * OTCPPacket |
422 | *======================================================================================*/ | 504 | *======================================================================================*/ |
423 | 505 | ||
424 | 506 | ||
425 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) | 507 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) |
426 | :QObject( parent, "TCP" ), _tcphdr( data ) | 508 | :QObject( parent, "TCP" ), _tcphdr( data ) |
427 | 509 | ||
428 | { | 510 | { |
429 | qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); | 511 | qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); |
430 | } | 512 | } |
431 | 513 | ||
432 | 514 | ||
433 | OTCPPacket::~OTCPPacket() | 515 | OTCPPacket::~OTCPPacket() |
434 | { | 516 | { |
435 | } | 517 | } |
436 | 518 | ||
437 | 519 | ||
438 | int OTCPPacket::fromPort() const | 520 | int OTCPPacket::fromPort() const |
439 | { | 521 | { |
440 | return EXTRACT_16BITS( &_tcphdr->source ); | 522 | return EXTRACT_16BITS( &_tcphdr->source ); |
441 | } | 523 | } |
442 | 524 | ||
443 | 525 | ||
444 | int OTCPPacket::toPort() const | 526 | int OTCPPacket::toPort() const |
445 | { | 527 | { |
446 | return EXTRACT_16BITS( &_tcphdr->dest ); | 528 | return EXTRACT_16BITS( &_tcphdr->dest ); |
447 | } | 529 | } |
448 | 530 | ||
449 | 531 | ||
450 | int OTCPPacket::seq() const | 532 | int OTCPPacket::seq() const |
451 | { | 533 | { |
452 | return EXTRACT_16BITS( &_tcphdr->seq ); | 534 | return EXTRACT_16BITS( &_tcphdr->seq ); |
453 | } | 535 | } |
454 | 536 | ||
455 | 537 | ||
456 | int OTCPPacket::ack() const | 538 | int OTCPPacket::ack() const |
457 | { | 539 | { |
458 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); | 540 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); |
459 | } | 541 | } |
460 | 542 | ||
461 | 543 | ||
462 | int OTCPPacket::window() const | 544 | int OTCPPacket::window() const |
463 | { | 545 | { |
464 | return EXTRACT_16BITS( &_tcphdr->window ); | 546 | return EXTRACT_16BITS( &_tcphdr->window ); |
465 | } | 547 | } |
466 | 548 | ||
467 | 549 | ||
468 | int OTCPPacket::checksum() const | 550 | int OTCPPacket::checksum() const |
469 | { | 551 | { |
470 | return EXTRACT_16BITS( &_tcphdr->check ); | 552 | return EXTRACT_16BITS( &_tcphdr->check ); |
471 | } | 553 | } |
472 | 554 | ||
473 | /*====================================================================================== | 555 | /*====================================================================================== |
474 | * OPrismHeaderPacket | 556 | * OPrismHeaderPacket |
475 | *======================================================================================*/ | 557 | *======================================================================================*/ |
476 | 558 | ||
477 | 559 | ||
478 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) | 560 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) |
479 | :QObject( parent, "Prism" ), _header( data ) | 561 | :QObject( parent, "Prism" ), _header( data ) |
480 | 562 | ||
481 | { | 563 | { |
482 | qDebug( "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." ); | 564 | qDebug( "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." ); |
483 | 565 | ||
484 | qDebug( "Signal Strength = %d", data->signal.data ); | 566 | qDebug( "Signal Strength = %d", data->signal.data ); |
485 | 567 | ||
486 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); | 568 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); |
487 | } | 569 | } |
488 | 570 | ||
489 | OPrismHeaderPacket::~OPrismHeaderPacket() | 571 | OPrismHeaderPacket::~OPrismHeaderPacket() |
490 | { | 572 | { |
491 | } | 573 | } |
492 | 574 | ||
493 | 575 | ||
494 | unsigned int OPrismHeaderPacket::signalStrength() const | 576 | unsigned int OPrismHeaderPacket::signalStrength() const |
495 | { | 577 | { |
496 | return _header->signal.data; | 578 | return _header->signal.data; |
497 | } | 579 | } |
498 | 580 | ||
499 | /*====================================================================================== | 581 | /*====================================================================================== |
500 | * OWaveLanPacket | 582 | * OWaveLanPacket |
501 | *======================================================================================*/ | 583 | *======================================================================================*/ |
502 | 584 | ||
503 | 585 | ||
504 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) | 586 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) |
505 | :QObject( parent, "802.11" ), _wlanhdr( data ) | 587 | :QObject( parent, "802.11" ), _wlanhdr( data ) |
506 | 588 | ||
507 | { | 589 | { |
508 | qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); | 590 | qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); |
509 | qDebug( "type: %0X", type() ); | 591 | qDebug( "type: %0X", type() ); |
510 | qDebug( "subType: %0X", subType() ); | 592 | qDebug( "subType: %0X", subType() ); |
511 | qDebug( "duration: %d", duration() ); | 593 | qDebug( "duration: %d", duration() ); |
512 | qDebug( "powermanagement: %d", usesPowerManagement() ); | 594 | qDebug( "powermanagement: %d", usesPowerManagement() ); |
513 | qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); | 595 | qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); |
514 | qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); | 596 | qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); |
515 | qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); | 597 | qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); |
516 | qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); | 598 | qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); |
517 | qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); | 599 | qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); |
518 | 600 | ||
519 | switch ( type() ) | 601 | switch ( type() ) |
520 | { | 602 | { |
521 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; | 603 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
522 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; | 604 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
523 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; | 605 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; |
524 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); | 606 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); |
525 | } | 607 | } |
526 | } | 608 | } |
527 | 609 | ||
528 | OWaveLanPacket::~OWaveLanPacket() | 610 | OWaveLanPacket::~OWaveLanPacket() |
529 | { | 611 | { |
530 | } | 612 | } |
531 | 613 | ||
532 | 614 | ||
533 | int OWaveLanPacket::duration() const | 615 | int OWaveLanPacket::duration() const |
534 | { | 616 | { |
535 | return _wlanhdr->duration; | 617 | return _wlanhdr->duration; |
536 | } | 618 | } |
537 | 619 | ||
538 | 620 | ||
539 | OMacAddress OWaveLanPacket::macAddress1() const | 621 | OMacAddress OWaveLanPacket::macAddress1() const |
540 | { | 622 | { |
541 | return OMacAddress( _wlanhdr->mac1 ); | 623 | return OMacAddress( _wlanhdr->mac1 ); |
542 | } | 624 | } |
543 | 625 | ||
544 | 626 | ||
545 | OMacAddress OWaveLanPacket::macAddress2() const | 627 | OMacAddress OWaveLanPacket::macAddress2() const |
546 | { | 628 | { |
547 | return OMacAddress( _wlanhdr->mac2 ); | 629 | return OMacAddress( _wlanhdr->mac2 ); |
548 | } | 630 | } |
549 | 631 | ||
550 | 632 | ||
551 | OMacAddress OWaveLanPacket::macAddress3() const | 633 | OMacAddress OWaveLanPacket::macAddress3() const |
552 | { | 634 | { |
553 | return OMacAddress( _wlanhdr->mac3 ); | 635 | return OMacAddress( _wlanhdr->mac3 ); |
554 | } | 636 | } |
555 | 637 | ||
556 | 638 | ||
557 | OMacAddress OWaveLanPacket::macAddress4() const | 639 | OMacAddress OWaveLanPacket::macAddress4() const |
558 | { | 640 | { |
559 | return OMacAddress( _wlanhdr->mac4 ); | 641 | return OMacAddress( _wlanhdr->mac4 ); |
560 | } | 642 | } |
561 | 643 | ||
562 | 644 | ||
563 | int OWaveLanPacket::subType() const | 645 | int OWaveLanPacket::subType() const |
564 | { | 646 | { |
565 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 647 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
566 | } | 648 | } |
567 | 649 | ||
568 | 650 | ||
569 | int OWaveLanPacket::type() const | 651 | int OWaveLanPacket::type() const |
570 | { | 652 | { |
571 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 653 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
572 | } | 654 | } |
573 | 655 | ||
574 | 656 | ||
575 | int OWaveLanPacket::version() const | 657 | int OWaveLanPacket::version() const |
576 | { | 658 | { |
577 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 659 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
578 | } | 660 | } |
579 | 661 | ||
580 | 662 | ||
581 | bool OWaveLanPacket::fromDS() const | 663 | bool OWaveLanPacket::fromDS() const |
582 | { | 664 | { |
583 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 665 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
584 | } | 666 | } |
585 | 667 | ||
586 | 668 | ||
587 | bool OWaveLanPacket::toDS() const | 669 | bool OWaveLanPacket::toDS() const |
588 | { | 670 | { |
589 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 671 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
590 | } | 672 | } |
591 | 673 | ||
592 | 674 | ||
593 | bool OWaveLanPacket::usesPowerManagement() const | 675 | bool OWaveLanPacket::usesPowerManagement() const |
594 | { | 676 | { |
595 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 677 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
596 | } | 678 | } |
597 | 679 | ||
598 | 680 | ||
599 | bool OWaveLanPacket::usesWep() const | 681 | bool OWaveLanPacket::usesWep() const |
600 | { | 682 | { |
601 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 683 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
602 | } | 684 | } |
603 | 685 | ||
604 | 686 | ||
605 | /*====================================================================================== | 687 | /*====================================================================================== |
606 | * OWaveLanManagementPacket | 688 | * OWaveLanManagementPacket |
607 | *======================================================================================*/ | 689 | *======================================================================================*/ |
608 | 690 | ||
609 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) | 691 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) |
610 | :QObject( parent, "802.11 Management" ), _header( data ), | 692 | :QObject( parent, "802.11 Management" ), _header( data ), |
611 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) | 693 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) |
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index 0c9e7da..a031dd1 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -310,336 +310,346 @@ class OWaveLanManagementDS : public QObject | |||
310 | Q_OBJECT | 310 | Q_OBJECT |
311 | 311 | ||
312 | public: | 312 | public: |
313 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); | 313 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); |
314 | virtual ~OWaveLanManagementDS(); | 314 | virtual ~OWaveLanManagementDS(); |
315 | 315 | ||
316 | int channel() const; | 316 | int channel() const; |
317 | 317 | ||
318 | private: | 318 | private: |
319 | const struct ds_t* _data; | 319 | const struct ds_t* _data; |
320 | }; | 320 | }; |
321 | 321 | ||
322 | /*====================================================================================== | 322 | /*====================================================================================== |
323 | * OWaveLanManagementTim | 323 | * OWaveLanManagementTim |
324 | *======================================================================================*/ | 324 | *======================================================================================*/ |
325 | 325 | ||
326 | class OWaveLanManagementTim : public QObject | 326 | class OWaveLanManagementTim : public QObject |
327 | { | 327 | { |
328 | Q_OBJECT | 328 | Q_OBJECT |
329 | 329 | ||
330 | public: | 330 | public: |
331 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); | 331 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); |
332 | virtual ~OWaveLanManagementTim(); | 332 | virtual ~OWaveLanManagementTim(); |
333 | 333 | ||
334 | private: | 334 | private: |
335 | const struct tim_t* _data; | 335 | const struct tim_t* _data; |
336 | }; | 336 | }; |
337 | 337 | ||
338 | /*====================================================================================== | 338 | /*====================================================================================== |
339 | * OWaveLanManagementIBSS | 339 | * OWaveLanManagementIBSS |
340 | *======================================================================================*/ | 340 | *======================================================================================*/ |
341 | 341 | ||
342 | class OWaveLanManagementIBSS : public QObject | 342 | class OWaveLanManagementIBSS : public QObject |
343 | { | 343 | { |
344 | Q_OBJECT | 344 | Q_OBJECT |
345 | 345 | ||
346 | public: | 346 | public: |
347 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); | 347 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); |
348 | virtual ~OWaveLanManagementIBSS(); | 348 | virtual ~OWaveLanManagementIBSS(); |
349 | 349 | ||
350 | private: | 350 | private: |
351 | const struct ibss_t* _data; | 351 | const struct ibss_t* _data; |
352 | }; | 352 | }; |
353 | 353 | ||
354 | /*====================================================================================== | 354 | /*====================================================================================== |
355 | * OWaveLanManagementChallenge | 355 | * OWaveLanManagementChallenge |
356 | *======================================================================================*/ | 356 | *======================================================================================*/ |
357 | 357 | ||
358 | class OWaveLanManagementChallenge : public QObject | 358 | class OWaveLanManagementChallenge : public QObject |
359 | { | 359 | { |
360 | Q_OBJECT | 360 | Q_OBJECT |
361 | 361 | ||
362 | public: | 362 | public: |
363 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); | 363 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); |
364 | virtual ~OWaveLanManagementChallenge(); | 364 | virtual ~OWaveLanManagementChallenge(); |
365 | 365 | ||
366 | private: | 366 | private: |
367 | const struct challenge_t* _data; | 367 | const struct challenge_t* _data; |
368 | }; | 368 | }; |
369 | 369 | ||
370 | /*====================================================================================== | 370 | /*====================================================================================== |
371 | * OWaveLanDataPacket - type: data (T_DATA) | 371 | * OWaveLanDataPacket - type: data (T_DATA) |
372 | *======================================================================================*/ | 372 | *======================================================================================*/ |
373 | 373 | ||
374 | class OWaveLanDataPacket : public QObject | 374 | class OWaveLanDataPacket : public QObject |
375 | { | 375 | { |
376 | Q_OBJECT | 376 | Q_OBJECT |
377 | 377 | ||
378 | public: | 378 | public: |
379 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); | 379 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); |
380 | virtual ~OWaveLanDataPacket(); | 380 | virtual ~OWaveLanDataPacket(); |
381 | 381 | ||
382 | private: | 382 | private: |
383 | const struct ieee_802_11_data_header* _header; | 383 | const struct ieee_802_11_data_header* _header; |
384 | }; | 384 | }; |
385 | 385 | ||
386 | /*====================================================================================== | 386 | /*====================================================================================== |
387 | * OWaveLanControlPacket - type: control (T_CTRL) | 387 | * OWaveLanControlPacket - type: control (T_CTRL) |
388 | *======================================================================================*/ | 388 | *======================================================================================*/ |
389 | 389 | ||
390 | class OWaveLanControlPacket : public QObject | 390 | class OWaveLanControlPacket : public QObject |
391 | { | 391 | { |
392 | Q_OBJECT | 392 | Q_OBJECT |
393 | 393 | ||
394 | public: | 394 | public: |
395 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); | 395 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); |
396 | virtual ~OWaveLanControlPacket(); | 396 | virtual ~OWaveLanControlPacket(); |
397 | 397 | ||
398 | private: | 398 | private: |
399 | const struct ieee_802_11_control_header* _header; | 399 | const struct ieee_802_11_control_header* _header; |
400 | }; | 400 | }; |
401 | 401 | ||
402 | /*====================================================================================== | 402 | /*====================================================================================== |
403 | * OLLCPacket - IEEE 802.2 Link Level Control | 403 | * OLLCPacket - IEEE 802.2 Link Level Control |
404 | *======================================================================================*/ | 404 | *======================================================================================*/ |
405 | 405 | ||
406 | class OLLCPacket : public QObject | 406 | class OLLCPacket : public QObject |
407 | { | 407 | { |
408 | Q_OBJECT | 408 | Q_OBJECT |
409 | 409 | ||
410 | public: | 410 | public: |
411 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); | 411 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); |
412 | virtual ~OLLCPacket(); | 412 | virtual ~OLLCPacket(); |
413 | 413 | ||
414 | private: | 414 | private: |
415 | const struct ieee_802_11_802_2_header* _header; | 415 | const struct ieee_802_11_802_2_header* _header; |
416 | }; | 416 | }; |
417 | 417 | ||
418 | /*====================================================================================== | 418 | /*====================================================================================== |
419 | * OIPPacket | 419 | * OIPPacket |
420 | *======================================================================================*/ | 420 | *======================================================================================*/ |
421 | 421 | ||
422 | class OIPPacket : public QObject | 422 | class OIPPacket : public QObject |
423 | { | 423 | { |
424 | Q_OBJECT | 424 | Q_OBJECT |
425 | 425 | ||
426 | public: | 426 | public: |
427 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); | 427 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); |
428 | virtual ~OIPPacket(); | 428 | virtual ~OIPPacket(); |
429 | 429 | ||
430 | QHostAddress fromIPAddress() const; | 430 | QHostAddress fromIPAddress() const; |
431 | QHostAddress toIPAddress() const; | 431 | QHostAddress toIPAddress() const; |
432 | 432 | ||
433 | int tos() const; | 433 | int tos() const; |
434 | int len() const; | 434 | int len() const; |
435 | int id() const; | 435 | int id() const; |
436 | int offset() const; | 436 | int offset() const; |
437 | int ttl() const; | 437 | int ttl() const; |
438 | int protocol() const; | 438 | int protocol() const; |
439 | int checksum() const; | 439 | int checksum() const; |
440 | 440 | ||
441 | private: | 441 | private: |
442 | const struct iphdr* _iphdr; | 442 | const struct iphdr* _iphdr; |
443 | }; | 443 | }; |
444 | 444 | ||
445 | /*====================================================================================== | 445 | /*====================================================================================== |
446 | * OARPPacket | 446 | * OARPPacket |
447 | *======================================================================================*/ | 447 | *======================================================================================*/ |
448 | 448 | ||
449 | class OARPPacket : public QObject | 449 | class OARPPacket : public QObject |
450 | { | 450 | { |
451 | Q_OBJECT | 451 | Q_OBJECT |
452 | 452 | ||
453 | public: | 453 | public: |
454 | OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); | 454 | OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); |
455 | virtual ~OARPPacket(); | 455 | virtual ~OARPPacket(); |
456 | 456 | ||
457 | QHostAddress senderIPV4Address() const; | 457 | QHostAddress senderIPV4Address() const; |
458 | OMacAddress senderMacAddress() const; | 458 | OMacAddress senderMacAddress() const; |
459 | QHostAddress targetIPV4Address() const; | 459 | QHostAddress targetIPV4Address() const; |
460 | OMacAddress targetMacAddress() const; | 460 | OMacAddress targetMacAddress() const; |
461 | 461 | ||
462 | //int type() const; | 462 | //int type() const; |
463 | QString type() const; | 463 | QString type() const; |
464 | 464 | ||
465 | private: | 465 | private: |
466 | const struct myarphdr* _arphdr; | 466 | const struct myarphdr* _arphdr; |
467 | }; | 467 | }; |
468 | 468 | ||
469 | /*====================================================================================== | 469 | /*====================================================================================== |
470 | * OUDPPacket | 470 | * OUDPPacket |
471 | *======================================================================================*/ | 471 | *======================================================================================*/ |
472 | 472 | ||
473 | class OUDPPacket : public QObject | 473 | class OUDPPacket : public QObject |
474 | { | 474 | { |
475 | Q_OBJECT | 475 | Q_OBJECT |
476 | 476 | ||
477 | public: | 477 | public: |
478 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); | 478 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); |
479 | virtual ~OUDPPacket(); | 479 | virtual ~OUDPPacket(); |
480 | 480 | ||
481 | int fromPort() const; | 481 | int fromPort() const; |
482 | int toPort() const; | 482 | int toPort() const; |
483 | int length() const; | 483 | int length() const; |
484 | int checksum() const; | 484 | int checksum() const; |
485 | 485 | ||
486 | private: | 486 | private: |
487 | const struct udphdr* _udphdr; | 487 | const struct udphdr* _udphdr; |
488 | }; | 488 | }; |
489 | 489 | ||
490 | /*====================================================================================== | 490 | /*====================================================================================== |
491 | * ODHCPPacket | 491 | * ODHCPPacket |
492 | *======================================================================================*/ | 492 | *======================================================================================*/ |
493 | 493 | ||
494 | class ODHCPPacket : public QObject | 494 | class ODHCPPacket : public QObject |
495 | { | 495 | { |
496 | Q_OBJECT | 496 | Q_OBJECT |
497 | 497 | ||
498 | public: | 498 | public: |
499 | ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); | 499 | ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); |
500 | virtual ~ODHCPPacket(); | 500 | virtual ~ODHCPPacket(); |
501 | 501 | ||
502 | QHostAddress clientAddress() const; | ||
503 | QHostAddress yourAddress() const; | ||
504 | QHostAddress serverAddress() const; | ||
505 | QHostAddress relayAddress() const; | ||
506 | |||
507 | bool isRequest() const; | ||
508 | bool isReply() const; | ||
509 | QString type() const; | ||
510 | |||
502 | private: | 511 | private: |
503 | const struct dhcp_packet* _dhcphdr; | 512 | const struct dhcp_packet* _dhcphdr; |
513 | unsigned char _type; | ||
504 | }; | 514 | }; |
505 | 515 | ||
506 | /*====================================================================================== | 516 | /*====================================================================================== |
507 | * OTCPPacket | 517 | * OTCPPacket |
508 | *======================================================================================*/ | 518 | *======================================================================================*/ |
509 | 519 | ||
510 | class OTCPPacket : public QObject | 520 | class OTCPPacket : public QObject |
511 | { | 521 | { |
512 | Q_OBJECT | 522 | Q_OBJECT |
513 | 523 | ||
514 | public: | 524 | public: |
515 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); | 525 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); |
516 | virtual ~OTCPPacket(); | 526 | virtual ~OTCPPacket(); |
517 | 527 | ||
518 | int fromPort() const; | 528 | int fromPort() const; |
519 | int toPort() const; | 529 | int toPort() const; |
520 | int seq() const; | 530 | int seq() const; |
521 | int ack() const; | 531 | int ack() const; |
522 | int window() const; | 532 | int window() const; |
523 | int checksum() const; | 533 | int checksum() const; |
524 | 534 | ||
525 | private: | 535 | private: |
526 | const struct tcphdr* _tcphdr; | 536 | const struct tcphdr* _tcphdr; |
527 | }; | 537 | }; |
528 | 538 | ||
529 | 539 | ||
530 | /*====================================================================================== | 540 | /*====================================================================================== |
531 | * OPacketCapturer | 541 | * OPacketCapturer |
532 | *======================================================================================*/ | 542 | *======================================================================================*/ |
533 | 543 | ||
534 | /** | 544 | /** |
535 | * @brief A class based wrapper for network packet capturing. | 545 | * @brief A class based wrapper for network packet capturing. |
536 | * | 546 | * |
537 | * This class is the base of a high-level interface to the well known packet capturing | 547 | * This class is the base of a high-level interface to the well known packet capturing |
538 | * library libpcap. | 548 | * library libpcap. |
539 | * @see http://tcpdump.org | 549 | * @see http://tcpdump.org |
540 | */ | 550 | */ |
541 | class OPacketCapturer : public QObject | 551 | class OPacketCapturer : public QObject |
542 | { | 552 | { |
543 | Q_OBJECT | 553 | Q_OBJECT |
544 | 554 | ||
545 | public: | 555 | public: |
546 | /** | 556 | /** |
547 | * Constructor. | 557 | * Constructor. |
548 | */ | 558 | */ |
549 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); | 559 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); |
550 | /** | 560 | /** |
551 | * Destructor. | 561 | * Destructor. |
552 | */ | 562 | */ |
553 | ~OPacketCapturer(); | 563 | ~OPacketCapturer(); |
554 | /** | 564 | /** |
555 | * Set the packet capturer to use blocking or non-blocking IO. This can be useful when | 565 | * Set the packet capturer to use blocking or non-blocking IO. This can be useful when |
556 | * not using the socket notifier, e.g. without an application object. | 566 | * not using the socket notifier, e.g. without an application object. |
557 | */ | 567 | */ |
558 | void setBlocking( bool ); | 568 | void setBlocking( bool ); |
559 | /** | 569 | /** |
560 | * @returns true if the packet capturer uses blocking IO calls. | 570 | * @returns true if the packet capturer uses blocking IO calls. |
561 | */ | 571 | */ |
562 | bool blocking() const; | 572 | bool blocking() const; |
563 | /** | 573 | /** |
564 | * Close the packet capturer. This is automatically done in the destructor. | 574 | * Close the packet capturer. This is automatically done in the destructor. |
565 | */ | 575 | */ |
566 | void close(); | 576 | void close(); |
567 | /** | 577 | /** |
568 | * Close the output capture file. | 578 | * Close the output capture file. |
569 | */ | 579 | */ |
570 | void closeDumpFile(); | 580 | void closeDumpFile(); |
571 | /** | 581 | /** |
572 | * @returns the data link type. | 582 | * @returns the data link type. |
573 | * @see <pcap.h> for possible values. | 583 | * @see <pcap.h> for possible values. |
574 | */ | 584 | */ |
575 | int dataLink() const; | 585 | int dataLink() const; |
576 | /** | 586 | /** |
577 | * Dump a packet to the output capture file. | 587 | * Dump a packet to the output capture file. |
578 | */ | 588 | */ |
579 | void dump( OPacket* ); | 589 | void dump( OPacket* ); |
580 | /** | 590 | /** |
581 | * @returns the file descriptor of the packet capturer. This is only useful, if | 591 | * @returns the file descriptor of the packet capturer. This is only useful, if |
582 | * not using the socket notifier, e.g. without an application object. | 592 | * not using the socket notifier, e.g. without an application object. |
583 | */ | 593 | */ |
584 | int fileno() const; | 594 | int fileno() const; |
585 | /** | 595 | /** |
586 | * @returns the next @ref OPacket from the packet capturer. | 596 | * @returns the next @ref OPacket from the packet capturer. |
587 | * @note If blocking mode is true then this call might block. | 597 | * @note If blocking mode is true then this call might block. |
588 | */ | 598 | */ |
589 | OPacket* next(); | 599 | OPacket* next(); |
590 | /** | 600 | /** |
591 | * Open the packet capturer to capture packets in live-mode from @a interface. | 601 | * Open the packet capturer to capture packets in live-mode from @a interface. |
592 | */ | 602 | */ |
593 | bool open( const QString& interface ); | 603 | bool open( const QString& interface ); |
594 | /** | 604 | /** |
595 | * Open the packet capturer to capture packets in offline-mode from @a file. | 605 | * Open the packet capturer to capture packets in offline-mode from @a file. |
596 | */ | 606 | */ |
597 | bool open( const QFile& file ); | 607 | bool open( const QFile& file ); |
598 | /** | 608 | /** |
599 | * Open a prerecorded tcpdump compatible capture file for use with @ref dump() | 609 | * Open a prerecorded tcpdump compatible capture file for use with @ref dump() |
600 | */ | 610 | */ |
601 | bool openDumpFile( const QString& filename ); | 611 | bool openDumpFile( const QString& filename ); |
602 | /** | 612 | /** |
603 | * @returns true if the packet capturer is open | 613 | * @returns true if the packet capturer is open |
604 | */ | 614 | */ |
605 | bool isOpen() const; | 615 | bool isOpen() const; |
606 | /** | 616 | /** |
607 | * @returns the snapshot length of this packet capturer | 617 | * @returns the snapshot length of this packet capturer |
608 | */ | 618 | */ |
609 | int snapShot() const; | 619 | int snapShot() const; |
610 | /** | 620 | /** |
611 | * @returns true if the input capture file has a different byte-order | 621 | * @returns true if the input capture file has a different byte-order |
612 | * than the byte-order of the running system. | 622 | * than the byte-order of the running system. |
613 | */ | 623 | */ |
614 | bool swapped() const; | 624 | bool swapped() const; |
615 | /** | 625 | /** |
616 | * @returns the libpcap version string used to write the input capture file. | 626 | * @returns the libpcap version string used to write the input capture file. |
617 | */ | 627 | */ |
618 | QString version() const; | 628 | QString version() const; |
619 | /** | 629 | /** |
620 | * @returns the packet statistic database. | 630 | * @returns the packet statistic database. |
621 | * @see QMap | 631 | * @see QMap |
622 | */ | 632 | */ |
623 | const QMap<QString,int>& statistics() const; | 633 | const QMap<QString,int>& statistics() const; |
624 | 634 | ||
625 | signals: | 635 | signals: |
626 | /** | 636 | /** |
627 | * This signal is emitted, when a packet has been received. | 637 | * This signal is emitted, when a packet has been received. |
628 | */ | 638 | */ |
629 | void receivedPacket( OPacket* ); | 639 | void receivedPacket( OPacket* ); |
630 | 640 | ||
631 | protected slots: | 641 | protected slots: |
632 | void readyToReceive(); | 642 | void readyToReceive(); |
633 | 643 | ||
634 | protected: | 644 | protected: |
635 | QString _name; // devicename | 645 | QString _name; // devicename |
636 | bool _open; // check this before doing pcap calls | 646 | bool _open; // check this before doing pcap calls |
637 | pcap_t* _pch; // pcap library handle | 647 | pcap_t* _pch; // pcap library handle |
638 | pcap_dumper_t* _pcd; // pcap dumper handle | 648 | pcap_dumper_t* _pcd; // pcap dumper handle |
639 | QSocketNotifier* _sn; // socket notifier for main loop | 649 | QSocketNotifier* _sn; // socket notifier for main loop |
640 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap | 650 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap |
641 | QMap<QString, int> _stats; // statistics; | 651 | QMap<QString, int> _stats; // statistics; |
642 | }; | 652 | }; |
643 | 653 | ||
644 | #endif // OPCAP_H | 654 | #endif // OPCAP_H |
645 | 655 | ||