summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2003-10-10 00:15:28 (UTC)
committer mickeyl <mickeyl>2003-10-10 00:15:28 (UTC)
commitc1a897e63513c9647666970794c1684b2439501e (patch) (side-by-side diff)
tree6787f5b1731238c7010937dca220e97f116f19b7 /libopie2
parent802c9ab6b89fd10f709aa012e8ff075e9b4a5d7f (diff)
downloadopie-c1a897e63513c9647666970794c1684b2439501e.zip
opie-c1a897e63513c9647666970794c1684b2439501e.tar.gz
opie-c1a897e63513c9647666970794c1684b2439501e.tar.bz2
Question: What's wrong in select(1, [], NULL, NULL, {100, 0} = 0 (timeout) ?
Answer: It would help to give select the correct filedescriptor... /me hugs strace
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
@@ -548,97 +548,97 @@ void OWirelessNetworkInterface::buildChannelList()
}
void OWirelessNetworkInterface::buildPrivateList()
{
qDebug( "OWirelessNetworkInterface::buildPrivateList()" );
struct iw_priv_args priv[IW_MAX_PRIV_DEF];
_iwr.u.data.pointer = (char*) &priv;
_iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
_iwr.u.data.flags = 0;
if ( !wioctl( SIOCGIWPRIV ) )
{
qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) );
return;
}
for ( int i = 0; i < _iwr.u.data.length; ++i )
{
new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
}
qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." );
}
int OWirelessNetworkInterface::channel() const
{
//FIXME: When monitoring enabled, then use it
//FIXME: to gather the current RF channel
//FIXME: Until then, get active channel from hopper.
if ( _hopper && _hopper->isActive() )
return _hopper->channel();
if ( !wioctl( SIOCGIWFREQ ) )
{
return -1;
}
else
{
return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
}
}
void OWirelessNetworkInterface::setChannel( int c ) const
{
- if ( c )
+ if ( !c )
{
qWarning( "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" );
return;
}
if ( !_mon )
{
memset( &_iwr, 0, sizeof( struct iwreq ) );
_iwr.u.freq.m = c;
_iwr.u.freq.e = 0;
wioctl( SIOCSIWFREQ );
}
else
{
_mon->setChannel( c );
}
}
double OWirelessNetworkInterface::frequency() const
{
if ( !wioctl( SIOCGIWFREQ ) )
{
return -1.0;
}
else
{
return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
}
}
int OWirelessNetworkInterface::channels() const
{
return _channels.count();
}
void OWirelessNetworkInterface::setChannelHopping( int interval )
{
if ( !_hopper ) _hopper = new OChannelHopper( this );
_hopper->setInterval( interval );
//FIXME: When and by whom will the channel hopper be deleted?
//TODO: rely on QObject hierarchy
}
int OWirelessNetworkInterface::channelHopping() const
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
@@ -1098,97 +1098,97 @@ void OPacketCapturer::close()
qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." );
qDebug( "--------------------------------------------------" );
for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it )
qDebug( "%s : %d", (const char*) it.key(), it.data() );
qDebug( "--------------------------------------------------" );
}
int OPacketCapturer::dataLink() const
{
return pcap_datalink( _pch );
}
void OPacketCapturer::dump( OPacket* p )
{
if ( !_pcd )
{
qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" );
return;
}
pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data );
}
int OPacketCapturer::fileno() const
{
if ( _open )
{
return pcap_fileno( _pch );
}
else
{
return -1;
}
}
OPacket* OPacketCapturer::next( int time )
{
fd_set fds;
struct timeval tv;
FD_ZERO( &fds );
FD_SET( pcap_fileno( _pch ), &fds );
tv.tv_sec = time / 1000;
tv.tv_usec = time % 1000;
- int retval = select( 1, &fds, NULL, NULL, &tv);
+ int retval = select( pcap_fileno( _pch )+1, &fds, NULL, NULL, &tv);
if ( retval > 0 ) // clear to read!
return next();
else
return 0;
}
OPacket* OPacketCapturer::next()
{
packetheaderstruct header;
qDebug( "==> OPacketCapturer::next()" );
const unsigned char* pdata = pcap_next( _pch, &header );
qDebug( "<== OPacketCapturer::next()" );
if ( pdata && header.len )
{
OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
// packets shouldn't be inserted in the QObject child-parent hierarchy,
// because due to memory constraints they will be deleted as soon
// as possible - that is right after they have been processed
// by emit() [ see below ]
//TODO: make gathering statistics optional, because it takes time
p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
#ifndef NODEBUG
p->dumpStructure( const_cast<QObjectList*>( p->children() ) );
#endif
return p;
}
else
{
qWarning( "OPacketCapturer::next() - no packet received!" );
return 0;
}
}
bool OPacketCapturer::open( const QString& name )
{
if ( _open )
{
if ( name == _name ) // ignore opening an already openend device
{
return true;
}
else // close the last opened device
{
close();
}