summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp2
-rw-r--r--libopie2/opienet/opcap.cpp2
2 files changed, 2 insertions, 2 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 767651e..dc2e388 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -468,257 +468,257 @@ QString OWirelessNetworkInterface::associatedAP() const
468 { 468 {
469 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 469 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
470 _ifr.ifr_hwaddr.sa_data[0]&0xff, 470 _ifr.ifr_hwaddr.sa_data[0]&0xff,
471 _ifr.ifr_hwaddr.sa_data[1]&0xff, 471 _ifr.ifr_hwaddr.sa_data[1]&0xff,
472 _ifr.ifr_hwaddr.sa_data[2]&0xff, 472 _ifr.ifr_hwaddr.sa_data[2]&0xff,
473 _ifr.ifr_hwaddr.sa_data[3]&0xff, 473 _ifr.ifr_hwaddr.sa_data[3]&0xff,
474 _ifr.ifr_hwaddr.sa_data[4]&0xff, 474 _ifr.ifr_hwaddr.sa_data[4]&0xff,
475 _ifr.ifr_hwaddr.sa_data[5]&0xff ); 475 _ifr.ifr_hwaddr.sa_data[5]&0xff );
476 } 476 }
477 else 477 else
478 { 478 {
479 mac = "<Unknown>"; 479 mac = "<Unknown>";
480 } 480 }
481 return mac; 481 return mac;
482} 482}
483 483
484 484
485void OWirelessNetworkInterface::buildChannelList() 485void OWirelessNetworkInterface::buildChannelList()
486{ 486{
487 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck 487 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
488 //ML: The HostAP drivers need more than sizeof struct_iw range to complete 488 //ML: The HostAP drivers need more than sizeof struct_iw range to complete
489 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". 489 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
490 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate 490 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
491 //ML: _too much_ space. This is damn shitty crap *sigh* 491 //ML: _too much_ space. This is damn shitty crap *sigh*
492 //ML: We allocate a large memory region in RAM and check whether the 492 //ML: We allocate a large memory region in RAM and check whether the
493 //ML: driver pollutes this extra space. The complaint will be made on stdout, 493 //ML: driver pollutes this extra space. The complaint will be made on stdout,
494 //ML: so please forward this... 494 //ML: so please forward this...
495 495
496 struct iwreq wrq; 496 struct iwreq wrq;
497 int len = sizeof( struct iw_range )*2; 497 int len = sizeof( struct iw_range )*2;
498 char *buffer = (char*) malloc( len ); 498 char *buffer = (char*) malloc( len );
499 //FIXME: Validate if we actually got the memory block 499 //FIXME: Validate if we actually got the memory block
500 memset( buffer, 0, len ); 500 memset( buffer, 0, len );
501 memcpy( wrq.ifr_name, name(), IFNAMSIZ); 501 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
502 wrq.u.data.pointer = (caddr_t) buffer; 502 wrq.u.data.pointer = (caddr_t) buffer;
503 wrq.u.data.length = sizeof( struct iw_range ); 503 wrq.u.data.length = sizeof( struct iw_range );
504 wrq.u.data.flags = 0; 504 wrq.u.data.flags = 0;
505 505
506 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) 506 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
507 { 507 {
508 qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); 508 qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) );
509 _channels.insert( 2412, 1 ); // 2.412 GHz 509 _channels.insert( 2412, 1 ); // 2.412 GHz
510 _channels.insert( 2417, 2 ); // 2.417 GHz 510 _channels.insert( 2417, 2 ); // 2.417 GHz
511 _channels.insert( 2422, 3 ); // 2.422 GHz 511 _channels.insert( 2422, 3 ); // 2.422 GHz
512 _channels.insert( 2427, 4 ); // 2.427 GHz 512 _channels.insert( 2427, 4 ); // 2.427 GHz
513 _channels.insert( 2432, 5 ); // 2.432 GHz 513 _channels.insert( 2432, 5 ); // 2.432 GHz
514 _channels.insert( 2437, 6 ); // 2.437 GHz 514 _channels.insert( 2437, 6 ); // 2.437 GHz
515 _channels.insert( 2442, 7 ); // 2.442 GHz 515 _channels.insert( 2442, 7 ); // 2.442 GHz
516 _channels.insert( 2447, 8 ); // 2.447 GHz 516 _channels.insert( 2447, 8 ); // 2.447 GHz
517 _channels.insert( 2452, 9 ); // 2.452 GHz 517 _channels.insert( 2452, 9 ); // 2.452 GHz
518 _channels.insert( 2457, 10 ); // 2.457 GHz 518 _channels.insert( 2457, 10 ); // 2.457 GHz
519 _channels.insert( 2462, 11 ); // 2.462 GHz 519 _channels.insert( 2462, 11 ); // 2.462 GHz
520 } 520 }
521 else 521 else
522 { 522 {
523 // <check if the driver overwrites stuff> 523 // <check if the driver overwrites stuff>
524 int max = 0; 524 int max = 0;
525 for ( int r = sizeof( struct iw_range ); r < len; r++ ) 525 for ( int r = sizeof( struct iw_range ); r < len; r++ )
526 if (buffer[r] != 0) 526 if (buffer[r] != 0)
527 max = r; 527 max = r;
528 if (max > 0) 528 if (max > 0)
529 { 529 {
530 qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" 530 qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'"
531 "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); 531 "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) );
532 } 532 }
533 // </check if the driver overwrites stuff> 533 // </check if the driver overwrites stuff>
534 534
535 struct iw_range range; 535 struct iw_range range;
536 memcpy( &range, buffer, sizeof range ); 536 memcpy( &range, buffer, sizeof range );
537 537
538 qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); 538 qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency );
539 for ( int i = 0; i < range.num_frequency; ++i ) 539 for ( int i = 0; i < range.num_frequency; ++i )
540 { 540 {
541 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 541 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
542 _channels.insert( freq, i+1 ); 542 _channels.insert( freq, i+1 );
543 } 543 }
544 } 544 }
545 545
546 qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); 546 qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." );
547 free(buffer); 547 free(buffer);
548} 548}
549 549
550 550
551void OWirelessNetworkInterface::buildPrivateList() 551void OWirelessNetworkInterface::buildPrivateList()
552{ 552{
553 qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); 553 qDebug( "OWirelessNetworkInterface::buildPrivateList()" );
554 554
555 struct iw_priv_args priv[IW_MAX_PRIV_DEF]; 555 struct iw_priv_args priv[IW_MAX_PRIV_DEF];
556 556
557 _iwr.u.data.pointer = (char*) &priv; 557 _iwr.u.data.pointer = (char*) &priv;
558 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself 558 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
559 _iwr.u.data.flags = 0; 559 _iwr.u.data.flags = 0;
560 560
561 if ( !wioctl( SIOCGIWPRIV ) ) 561 if ( !wioctl( SIOCGIWPRIV ) )
562 { 562 {
563 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); 563 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) );
564 return; 564 return;
565 } 565 }
566 566
567 for ( int i = 0; i < _iwr.u.data.length; ++i ) 567 for ( int i = 0; i < _iwr.u.data.length; ++i )
568 { 568 {
569 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); 569 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
570 } 570 }
571 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); 571 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." );
572} 572}
573 573
574 574
575int OWirelessNetworkInterface::channel() const 575int OWirelessNetworkInterface::channel() const
576{ 576{
577 //FIXME: When monitoring enabled, then use it 577 //FIXME: When monitoring enabled, then use it
578 //FIXME: to gather the current RF channel 578 //FIXME: to gather the current RF channel
579 //FIXME: Until then, get active channel from hopper. 579 //FIXME: Until then, get active channel from hopper.
580 if ( _hopper && _hopper->isActive() ) 580 if ( _hopper && _hopper->isActive() )
581 return _hopper->channel(); 581 return _hopper->channel();
582 582
583 if ( !wioctl( SIOCGIWFREQ ) ) 583 if ( !wioctl( SIOCGIWFREQ ) )
584 { 584 {
585 return -1; 585 return -1;
586 } 586 }
587 else 587 else
588 { 588 {
589 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; 589 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
590 } 590 }
591} 591}
592 592
593 593
594void OWirelessNetworkInterface::setChannel( int c ) const 594void OWirelessNetworkInterface::setChannel( int c ) const
595{ 595{
596 if ( c ) 596 if ( !c )
597 { 597 {
598 qWarning( "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" ); 598 qWarning( "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" );
599 return; 599 return;
600 } 600 }
601 601
602 if ( !_mon ) 602 if ( !_mon )
603 { 603 {
604 memset( &_iwr, 0, sizeof( struct iwreq ) ); 604 memset( &_iwr, 0, sizeof( struct iwreq ) );
605 _iwr.u.freq.m = c; 605 _iwr.u.freq.m = c;
606 _iwr.u.freq.e = 0; 606 _iwr.u.freq.e = 0;
607 wioctl( SIOCSIWFREQ ); 607 wioctl( SIOCSIWFREQ );
608 } 608 }
609 else 609 else
610 { 610 {
611 _mon->setChannel( c ); 611 _mon->setChannel( c );
612 } 612 }
613} 613}
614 614
615 615
616double OWirelessNetworkInterface::frequency() const 616double OWirelessNetworkInterface::frequency() const
617{ 617{
618 if ( !wioctl( SIOCGIWFREQ ) ) 618 if ( !wioctl( SIOCGIWFREQ ) )
619 { 619 {
620 return -1.0; 620 return -1.0;
621 } 621 }
622 else 622 else
623 { 623 {
624 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; 624 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
625 } 625 }
626} 626}
627 627
628 628
629int OWirelessNetworkInterface::channels() const 629int OWirelessNetworkInterface::channels() const
630{ 630{
631 return _channels.count(); 631 return _channels.count();
632} 632}
633 633
634 634
635void OWirelessNetworkInterface::setChannelHopping( int interval ) 635void OWirelessNetworkInterface::setChannelHopping( int interval )
636{ 636{
637 if ( !_hopper ) _hopper = new OChannelHopper( this ); 637 if ( !_hopper ) _hopper = new OChannelHopper( this );
638 _hopper->setInterval( interval ); 638 _hopper->setInterval( interval );
639 //FIXME: When and by whom will the channel hopper be deleted? 639 //FIXME: When and by whom will the channel hopper be deleted?
640 //TODO: rely on QObject hierarchy 640 //TODO: rely on QObject hierarchy
641} 641}
642 642
643 643
644int OWirelessNetworkInterface::channelHopping() const 644int OWirelessNetworkInterface::channelHopping() const
645{ 645{
646 return _hopper->interval(); 646 return _hopper->interval();
647} 647}
648 648
649 649
650OChannelHopper* OWirelessNetworkInterface::channelHopper() const 650OChannelHopper* OWirelessNetworkInterface::channelHopper() const
651{ 651{
652 return _hopper; 652 return _hopper;
653} 653}
654 654
655 655
656void OWirelessNetworkInterface::setMode( const QString& mode ) 656void OWirelessNetworkInterface::setMode( const QString& mode )
657{ 657{
658 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; 658 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO;
659 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; 659 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC;
660 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; 660 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA;
661 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; 661 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER;
662 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; 662 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT;
663 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; 663 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND;
664 #if WIRELESS_EXT > 14 664 #if WIRELESS_EXT > 14
665 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; 665 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR;
666 #endif 666 #endif
667 else 667 else
668 { 668 {
669 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); 669 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode );
670 return; 670 return;
671 } 671 }
672 wioctl( SIOCSIWMODE ); 672 wioctl( SIOCSIWMODE );
673} 673}
674 674
675 675
676QString OWirelessNetworkInterface::mode() const 676QString OWirelessNetworkInterface::mode() const
677{ 677{
678 if ( !wioctl( SIOCGIWMODE ) ) 678 if ( !wioctl( SIOCGIWMODE ) )
679 { 679 {
680 return "<unknown>"; 680 return "<unknown>";
681 } 681 }
682 switch ( _iwr.u.mode ) 682 switch ( _iwr.u.mode )
683 { 683 {
684 case IW_MODE_AUTO: return "auto"; 684 case IW_MODE_AUTO: return "auto";
685 case IW_MODE_ADHOC: return "adhoc"; 685 case IW_MODE_ADHOC: return "adhoc";
686 case IW_MODE_INFRA: return "managed"; 686 case IW_MODE_INFRA: return "managed";
687 case IW_MODE_MASTER: return "master"; 687 case IW_MODE_MASTER: return "master";
688 case IW_MODE_REPEAT: return "repeater"; 688 case IW_MODE_REPEAT: return "repeater";
689 case IW_MODE_SECOND: return "secondary"; 689 case IW_MODE_SECOND: return "secondary";
690 #if WIRELESS_EXT > 14 690 #if WIRELESS_EXT > 14
691 case IW_MODE_MONITOR: return "monitor"; 691 case IW_MODE_MONITOR: return "monitor";
692 #endif 692 #endif
693 default: assert( 0 ); // shouldn't happen 693 default: assert( 0 ); // shouldn't happen
694 } 694 }
695} 695}
696 696
697 697
698void OWirelessNetworkInterface::setMonitorMode( bool b ) 698void OWirelessNetworkInterface::setMonitorMode( bool b )
699{ 699{
700 if ( _mon ) 700 if ( _mon )
701 _mon->setEnabled( b ); 701 _mon->setEnabled( b );
702 else 702 else
703 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 703 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
704} 704}
705 705
706 706
707bool OWirelessNetworkInterface::monitorMode() const 707bool OWirelessNetworkInterface::monitorMode() const
708{ 708{
709 qDebug( "dataLinkType = %d", dataLinkType() ); 709 qDebug( "dataLinkType = %d", dataLinkType() );
710 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); 710 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 );
711 // 802 is the header type for PRISM - Linux support for this is pending... 711 // 802 is the header type for PRISM - Linux support for this is pending...
712} 712}
713 713
714 714
715void OWirelessNetworkInterface::setNickName( const QString& nickname ) 715void OWirelessNetworkInterface::setNickName( const QString& nickname )
716{ 716{
717 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); 717 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
718 _iwr.u.essid.length = nickname.length(); 718 _iwr.u.essid.length = nickname.length();
719 wioctl( SIOCSIWNICKN ); 719 wioctl( SIOCSIWNICKN );
720} 720}
721 721
722 722
723QString OWirelessNetworkInterface::nickName() const 723QString OWirelessNetworkInterface::nickName() const
724{ 724{
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 38ca1a1..6331b2d 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -1018,257 +1018,257 @@ OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const st
1018{ 1018{
1019 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); 1019 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." );
1020 //TODO: Implement this 1020 //TODO: Implement this
1021} 1021}
1022 1022
1023 1023
1024OWaveLanControlPacket::~OWaveLanControlPacket() 1024OWaveLanControlPacket::~OWaveLanControlPacket()
1025{ 1025{
1026} 1026}
1027 1027
1028 1028
1029/*====================================================================================== 1029/*======================================================================================
1030 * OPacketCapturer 1030 * OPacketCapturer
1031 *======================================================================================*/ 1031 *======================================================================================*/
1032 1032
1033OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) 1033OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
1034 :QObject( parent, name ), _name( QString::null ), _open( false ), 1034 :QObject( parent, name ), _name( QString::null ), _open( false ),
1035 _pch( 0 ), _pcd( 0 ), _sn( 0 ) 1035 _pch( 0 ), _pcd( 0 ), _sn( 0 )
1036{ 1036{
1037} 1037}
1038 1038
1039 1039
1040OPacketCapturer::~OPacketCapturer() 1040OPacketCapturer::~OPacketCapturer()
1041{ 1041{
1042 if ( _open ) 1042 if ( _open )
1043 { 1043 {
1044 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); 1044 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." );
1045 close(); 1045 close();
1046 } 1046 }
1047} 1047}
1048 1048
1049 1049
1050void OPacketCapturer::setBlocking( bool b ) 1050void OPacketCapturer::setBlocking( bool b )
1051{ 1051{
1052 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) 1052 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
1053 { 1053 {
1054 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); 1054 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." );
1055 } 1055 }
1056 else 1056 else
1057 { 1057 {
1058 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); 1058 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf );
1059 } 1059 }
1060} 1060}
1061 1061
1062 1062
1063bool OPacketCapturer::blocking() const 1063bool OPacketCapturer::blocking() const
1064{ 1064{
1065 int b = pcap_getnonblock( _pch, _errbuf ); 1065 int b = pcap_getnonblock( _pch, _errbuf );
1066 if ( b == -1 ) 1066 if ( b == -1 )
1067 { 1067 {
1068 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); 1068 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf );
1069 return -1; 1069 return -1;
1070 } 1070 }
1071 return !b; 1071 return !b;
1072} 1072}
1073 1073
1074 1074
1075void OPacketCapturer::closeDumpFile() 1075void OPacketCapturer::closeDumpFile()
1076{ 1076{
1077 if ( _pcd ) 1077 if ( _pcd )
1078 { 1078 {
1079 pcap_dump_close( _pcd ); 1079 pcap_dump_close( _pcd );
1080 _pcd = 0; 1080 _pcd = 0;
1081 } 1081 }
1082 pcap_close( _pch ); 1082 pcap_close( _pch );
1083} 1083}
1084 1084
1085 1085
1086void OPacketCapturer::close() 1086void OPacketCapturer::close()
1087{ 1087{
1088 if ( _open ) 1088 if ( _open )
1089 { 1089 {
1090 if ( _sn ) 1090 if ( _sn )
1091 { 1091 {
1092 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1092 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1093 delete _sn; 1093 delete _sn;
1094 } 1094 }
1095 closeDumpFile(); 1095 closeDumpFile();
1096 _open = false; 1096 _open = false;
1097 } 1097 }
1098 1098
1099 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); 1099 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." );
1100 qDebug( "--------------------------------------------------" ); 1100 qDebug( "--------------------------------------------------" );
1101 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) 1101 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it )
1102 qDebug( "%s : %d", (const char*) it.key(), it.data() ); 1102 qDebug( "%s : %d", (const char*) it.key(), it.data() );
1103 qDebug( "--------------------------------------------------" ); 1103 qDebug( "--------------------------------------------------" );
1104 1104
1105} 1105}
1106 1106
1107 1107
1108int OPacketCapturer::dataLink() const 1108int OPacketCapturer::dataLink() const
1109{ 1109{
1110 return pcap_datalink( _pch ); 1110 return pcap_datalink( _pch );
1111} 1111}
1112 1112
1113 1113
1114void OPacketCapturer::dump( OPacket* p ) 1114void OPacketCapturer::dump( OPacket* p )
1115{ 1115{
1116 if ( !_pcd ) 1116 if ( !_pcd )
1117 { 1117 {
1118 qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" ); 1118 qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" );
1119 return; 1119 return;
1120 } 1120 }
1121 pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data ); 1121 pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data );
1122} 1122}
1123 1123
1124 1124
1125int OPacketCapturer::fileno() const 1125int OPacketCapturer::fileno() const
1126{ 1126{
1127 if ( _open ) 1127 if ( _open )
1128 { 1128 {
1129 return pcap_fileno( _pch ); 1129 return pcap_fileno( _pch );
1130 } 1130 }
1131 else 1131 else
1132 { 1132 {
1133 return -1; 1133 return -1;
1134 } 1134 }
1135} 1135}
1136 1136
1137 1137
1138OPacket* OPacketCapturer::next( int time ) 1138OPacket* OPacketCapturer::next( int time )
1139{ 1139{
1140 fd_set fds; 1140 fd_set fds;
1141 struct timeval tv; 1141 struct timeval tv;
1142 FD_ZERO( &fds ); 1142 FD_ZERO( &fds );
1143 FD_SET( pcap_fileno( _pch ), &fds ); 1143 FD_SET( pcap_fileno( _pch ), &fds );
1144 tv.tv_sec = time / 1000; 1144 tv.tv_sec = time / 1000;
1145 tv.tv_usec = time % 1000; 1145 tv.tv_usec = time % 1000;
1146 int retval = select( 1, &fds, NULL, NULL, &tv); 1146 int retval = select( pcap_fileno( _pch )+1, &fds, NULL, NULL, &tv);
1147 if ( retval > 0 ) // clear to read! 1147 if ( retval > 0 ) // clear to read!
1148 return next(); 1148 return next();
1149 else 1149 else
1150 return 0; 1150 return 0;
1151} 1151}
1152 1152
1153 1153
1154OPacket* OPacketCapturer::next() 1154OPacket* OPacketCapturer::next()
1155{ 1155{
1156 packetheaderstruct header; 1156 packetheaderstruct header;
1157 qDebug( "==> OPacketCapturer::next()" ); 1157 qDebug( "==> OPacketCapturer::next()" );
1158 const unsigned char* pdata = pcap_next( _pch, &header ); 1158 const unsigned char* pdata = pcap_next( _pch, &header );
1159 qDebug( "<== OPacketCapturer::next()" ); 1159 qDebug( "<== OPacketCapturer::next()" );
1160 1160
1161 if ( pdata && header.len ) 1161 if ( pdata && header.len )
1162 { 1162 {
1163 OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); 1163 OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
1164 // packets shouldn't be inserted in the QObject child-parent hierarchy, 1164 // packets shouldn't be inserted in the QObject child-parent hierarchy,
1165 // because due to memory constraints they will be deleted as soon 1165 // because due to memory constraints they will be deleted as soon
1166 // as possible - that is right after they have been processed 1166 // as possible - that is right after they have been processed
1167 // by emit() [ see below ] 1167 // by emit() [ see below ]
1168 //TODO: make gathering statistics optional, because it takes time 1168 //TODO: make gathering statistics optional, because it takes time
1169 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); 1169 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
1170 #ifndef NODEBUG 1170 #ifndef NODEBUG
1171 p->dumpStructure( const_cast<QObjectList*>( p->children() ) ); 1171 p->dumpStructure( const_cast<QObjectList*>( p->children() ) );
1172 #endif 1172 #endif
1173 return p; 1173 return p;
1174 } 1174 }
1175 else 1175 else
1176 { 1176 {
1177 qWarning( "OPacketCapturer::next() - no packet received!" ); 1177 qWarning( "OPacketCapturer::next() - no packet received!" );
1178 return 0; 1178 return 0;
1179 } 1179 }
1180} 1180}
1181 1181
1182 1182
1183bool OPacketCapturer::open( const QString& name ) 1183bool OPacketCapturer::open( const QString& name )
1184{ 1184{
1185 if ( _open ) 1185 if ( _open )
1186 { 1186 {
1187 if ( name == _name ) // ignore opening an already openend device 1187 if ( name == _name ) // ignore opening an already openend device
1188 { 1188 {
1189 return true; 1189 return true;
1190 } 1190 }
1191 else // close the last opened device 1191 else // close the last opened device
1192 { 1192 {
1193 close(); 1193 close();
1194 } 1194 }
1195 } 1195 }
1196 1196
1197 _name = name; 1197 _name = name;
1198 1198
1199 // open libpcap 1199 // open libpcap
1200 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 1200 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
1201 1201
1202 if ( !handle ) 1202 if ( !handle )
1203 { 1203 {
1204 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 1204 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
1205 return false; 1205 return false;
1206 } 1206 }
1207 1207
1208 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); 1208 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name );
1209 _pch = handle; 1209 _pch = handle;
1210 _open = true; 1210 _open = true;
1211 _stats.clear(); 1211 _stats.clear();
1212 1212
1213 // in case we have an application object, create a socket notifier 1213 // in case we have an application object, create a socket notifier
1214 if ( qApp ) //TODO: I don't like this here... 1214 if ( qApp ) //TODO: I don't like this here...
1215 { 1215 {
1216 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 1216 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
1217 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1217 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1218 } 1218 }
1219 1219
1220 return true; 1220 return true;
1221} 1221}
1222 1222
1223 1223
1224bool OPacketCapturer::openDumpFile( const QString& filename ) 1224bool OPacketCapturer::openDumpFile( const QString& filename )
1225{ 1225{
1226 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); 1226 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) );
1227 if ( !dump ) 1227 if ( !dump )
1228 { 1228 {
1229 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); 1229 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf );
1230 return false; 1230 return false;
1231 } 1231 }
1232 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); 1232 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename );
1233 _pcd = dump; 1233 _pcd = dump;
1234 1234
1235 return true; 1235 return true;
1236} 1236}
1237 1237
1238 1238
1239bool OPacketCapturer::open( const QFile& file ) 1239bool OPacketCapturer::open( const QFile& file )
1240{ 1240{
1241 QString name = file.name(); 1241 QString name = file.name();
1242 1242
1243 if ( _open ) 1243 if ( _open )
1244 { 1244 {
1245 close(); 1245 close();
1246 if ( name == _name ) // ignore opening an already openend device 1246 if ( name == _name ) // ignore opening an already openend device
1247 { 1247 {
1248 return true; 1248 return true;
1249 } 1249 }
1250 else // close the last opened device 1250 else // close the last opened device
1251 { 1251 {
1252 close(); 1252 close();
1253 } 1253 }
1254 } 1254 }
1255 1255
1256 _name = name; 1256 _name = name;
1257 1257
1258 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); 1258 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] );
1259 1259
1260 if ( handle ) 1260 if ( handle )
1261 { 1261 {
1262 qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); 1262 qDebug( "OPacketCapturer::open(): libpcap opened successfully." );
1263 _pch = handle; 1263 _pch = handle;
1264 _open = true; 1264 _open = true;
1265 1265
1266 // in case we have an application object, create a socket notifier 1266 // in case we have an application object, create a socket notifier
1267 if ( qApp ) 1267 if ( qApp )
1268 { 1268 {
1269 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 1269 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
1270 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1270 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1271 } 1271 }
1272 1272
1273 return true; 1273 return true;
1274 } 1274 }