summaryrefslogtreecommitdiff
authorzecke <zecke>2004-08-23 22:36:53 (UTC)
committer zecke <zecke>2004-08-23 22:36:53 (UTC)
commitf8f1d4f340b591f21cd7c10259da1241ecf69dd9 (patch) (side-by-side diff)
tree1dd1f56716000d7952c31340e4b299c5635cbade
parentbf5a6236fe0f0ab42075a6a20539b7fd856ddcdd (diff)
downloadopie-f8f1d4f340b591f21cd7c10259da1241ecf69dd9.zip
opie-f8f1d4f340b591f21cd7c10259da1241ecf69dd9.tar.gz
opie-f8f1d4f340b591f21cd7c10259da1241ecf69dd9.tar.bz2
Fix warnings raised by the compiler
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp12
-rw-r--r--libopie2/opienet/opcap.cpp23
2 files changed, 18 insertions, 17 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 171a2bc..591681c 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -741,451 +741,451 @@ void OWirelessNetworkInterface::setMode( const QString& newMode )
else // special iwpriv fallback for monitor mode
{
if ( wioctl( SIOCSIWMODE ) )
{
odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl;
}
else
{
odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl;
if ( _mon )
_mon->setEnabled( true );
else
odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl;
}
}
}
QString OWirelessNetworkInterface::mode() const
{
memset( &_iwr, 0, sizeof( struct iwreq ) );
if ( !wioctl( SIOCGIWMODE ) )
{
return "<unknown>";
}
odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl;
// legacy compatible monitor mode check
if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 )
{
return "monitor";
}
else
{
return modeToString( _iwr.u.mode );
}
}
void OWirelessNetworkInterface::setNickName( const QString& nickname )
{
_iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
_iwr.u.essid.length = nickname.length();
wioctl( SIOCSIWNICKN );
}
QString OWirelessNetworkInterface::nickName() const
{
char str[IW_ESSID_MAX_SIZE];
_iwr.u.data.pointer = &str[0];
_iwr.u.data.length = IW_ESSID_MAX_SIZE;
if ( !wioctl( SIOCGIWNICKN ) )
{
return "<unknown>";
}
else
{
str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
return str;
}
}
void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
{
OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
if ( !priv )
{
owarn << "OWirelessNetworkInterface::setPrivate(): interface '" << name()
<< "' does not support private ioctl '" << call << "'" << oendl;
return;
}
if ( priv->numberSetArgs() != numargs )
{
owarn << "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '"
<< call << "' expects " << priv->numberSetArgs() << ", but got " << numargs << oendl;
return;
}
odebug << "OWirelessNetworkInterface::setPrivate(): about to call '" << call << "' on interface '" << name() << "'" << oendl;
memset( &_iwr, 0, sizeof _iwr );
va_list argp;
va_start( argp, numargs );
for ( int i = 0; i < numargs; ++i )
{
priv->setParameter( i, va_arg( argp, int ) );
}
va_end( argp );
priv->invoke();
}
-void OWirelessNetworkInterface::getPrivate( const QString& call )
+void OWirelessNetworkInterface::getPrivate( const QString& )
{
oerr << "OWirelessNetworkInterface::getPrivate() is not implemented yet." << oendl;
}
bool OWirelessNetworkInterface::hasPrivate( const QString& call )
{
- return child( (const char*) call );
+ return child( call.local8Bit() );
}
QString OWirelessNetworkInterface::SSID() const
{
char str[IW_ESSID_MAX_SIZE];
_iwr.u.essid.pointer = &str[0];
_iwr.u.essid.length = IW_ESSID_MAX_SIZE;
if ( !wioctl( SIOCGIWESSID ) )
{
return "<unknown>";
}
else
{
return str;
}
}
void OWirelessNetworkInterface::setSSID( const QString& ssid )
{
_iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
_iwr.u.essid.length = ssid.length();
wioctl( SIOCSIWESSID );
}
OStationList* OWirelessNetworkInterface::scanNetwork()
{
_iwr.u.param.flags = IW_SCAN_DEFAULT;
_iwr.u.param.value = 0;
if ( !wioctl( SIOCSIWSCAN ) )
{
return 0;
}
OStationList* stations = new OStationList();
int timeout = 1000000;
odebug << "ONetworkInterface::scanNetwork() - scan started." << oendl;
bool results = false;
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 250000; // initial timeout ~ 250ms
char buffer[IW_SCAN_MAX_DATA];
while ( !results && timeout > 0 )
{
timeout -= tv.tv_usec;
select( 0, 0, 0, 0, &tv );
_iwr.u.data.pointer = &buffer[0];
_iwr.u.data.flags = 0;
_iwr.u.data.length = sizeof buffer;
if ( wioctl( SIOCGIWSCAN ) )
{
results = true;
continue;
}
else if ( errno == EAGAIN)
{
odebug << "ONetworkInterface::scanNetwork() - scan in progress..." << oendl;
#if 0
if ( qApp )
{
qApp->processEvents( 100 );
continue;
}
#endif
tv.tv_sec = 0;
tv.tv_usec = 100000;
continue;
}
}
odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl;
if ( results )
{
odebug << " - result length = " << _iwr.u.data.length << oendl;
if ( !_iwr.u.data.length )
{
odebug << " - no results (empty neighbourhood)" << oendl;
return stations;
}
odebug << " - results are in!" << oendl;
dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length );
// parse results
int offset = 0;
struct iw_event* we = (struct iw_event*) &buffer[0];
while ( offset < _iwr.u.data.length )
{
//const char* cmd = *(*_ioctlmap)[we->cmd];
//if ( !cmd ) cmd = "<unknown>";
odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl;
switch (we->cmd)
{
case SIOCGIWAP:
{
odebug << "SIOCGIWAP" << oendl;
stations->append( new OStation() );
stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0];
break;
}
case SIOCGIWMODE:
{
odebug << "SIOCGIWMODE" << oendl;
stations->last()->type = modeToString( we->u.mode );
break;
}
case SIOCGIWFREQ:
{
odebug << "SIOCGIWFREQ" << oendl;
stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ];
break;
}
case SIOCGIWESSID:
{
odebug << "SIOCGIWESSID" << oendl;
stations->last()->ssid = static_cast<const char*>( we->u.essid.pointer );
break;
}
case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break;
case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break;
case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */
case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */
case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */
case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */
case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */
default: odebug << "unhandled event" << oendl;
}
offset += we->len;
we = (struct iw_event*) &buffer[offset];
}
return stations;
return stations;
}
else
{
odebug << " - no results (timeout) :(" << oendl;
return stations;
}
}
int OWirelessNetworkInterface::signalStrength() const
{
iw_statistics stat;
::memset( &stat, 0, sizeof stat );
_iwr.u.data.pointer = (char*) &stat;
_iwr.u.data.flags = 0;
_iwr.u.data.length = sizeof stat;
if ( !wioctl( SIOCGIWSTATS ) )
{
return -1;
}
int max = _range.max_qual.qual;
int cur = stat.qual.qual;
- int lev = stat.qual.level; //FIXME: Do something with them?
- int noi = stat.qual.noise; //FIXME: Do something with them?
+// int lev = stat.qual.level; //FIXME: Do something with them?
+// int noi = stat.qual.noise; //FIXME: Do something with them?
return max != 0 ? cur*100/max: -1;
}
bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
{
#ifndef NODEBUG
int result = ::ioctl( _sfd, call, &iwreq );
if ( result == -1 )
odebug << "ONetworkInterface::wioctl (" << name() << ") call '"
<< debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl;
else
odebug << "ONetworkInterface::wioctl (" << name() << ") call '"
<< debugmapper->map( call ) << "' - Status: Ok." << oendl;
return ( result != -1 );
#else
return ::ioctl( _sfd, call, &iwreq ) != -1;
#endif
}
bool OWirelessNetworkInterface::wioctl( int call ) const
{
strcpy( _iwr.ifr_name, name() );
return wioctl( call, _iwr );
}
/*======================================================================================
* OMonitoringInterface
*======================================================================================*/
OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
:_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader )
{
}
OMonitoringInterface::~OMonitoringInterface()
{
}
void OMonitoringInterface::setChannel( int c )
{
// use standard WE channel switching protocol
memset( &_if->_iwr, 0, sizeof( struct iwreq ) );
_if->_iwr.u.freq.m = c;
_if->_iwr.u.freq.e = 0;
_if->wioctl( SIOCSIWFREQ );
}
-void OMonitoringInterface::setEnabled( bool b )
+void OMonitoringInterface::setEnabled( bool )
{
}
/*======================================================================================
* OCiscoMonitoringInterface
*======================================================================================*/
OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
:OMonitoringInterface( iface, prismHeader )
{
iface->setMonitoring( this );
}
OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
{
}
-void OCiscoMonitoringInterface::setEnabled( bool b )
+void OCiscoMonitoringInterface::setEnabled( bool /*b*/ )
{
QString fname;
fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
QFile f( fname );
if ( !f.exists() ) return;
if ( f.open( IO_WriteOnly ) )
{
QTextStream s( &f );
s << "Mode: r";
s << "Mode: y";
s << "XmitPower: 1";
}
// flushing and closing will be done automatically when f goes out of scope
}
QString OCiscoMonitoringInterface::name() const
{
return "cisco";
}
void OCiscoMonitoringInterface::setChannel( int )
{
// cisco devices automatically switch channels when in monitor mode
}
/*======================================================================================
* OWlanNGMonitoringInterface
*======================================================================================*/
OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
:OMonitoringInterface( iface, prismHeader )
{
iface->setMonitoring( this );
}
OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
{
}
void OWlanNGMonitoringInterface::setEnabled( bool b )
{
//FIXME: do nothing if its already in the same mode
QString enable = b ? "true" : "false";
QString prism = _prismHeader ? "true" : "false";
QString cmd;
cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
(const char*) _if->name(), 1, (const char*) enable, (const char*) prism );
system( cmd );
}
QString OWlanNGMonitoringInterface::name() const
{
return "wlan-ng";
}
void OWlanNGMonitoringInterface::setChannel( int c )
{
//NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't.
QString enable = "true"; //_if->monitorMode() ? "true" : "false";
QString prism = _prismHeader ? "true" : "false";
QString cmd;
cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
(const char*) _if->name(), c, (const char*) enable, (const char*) prism );
system( cmd );
}
/*======================================================================================
* OHostAPMonitoringInterface
*======================================================================================*/
OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
:OMonitoringInterface( iface, prismHeader )
{
iface->setMonitoring( this );
}
OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
{
}
void OHostAPMonitoringInterface::setEnabled( bool b )
{
int monitorCode = _prismHeader ? 1 : 2;
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 03e4502..25ac09b 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -97,330 +97,331 @@ OPacket::~OPacket()
timevalstruct OPacket::timeval() const
{
return _hdr.ts;
}
int OPacket::caplen() const
{
return _hdr.caplen;
}
void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l )
{
if (!l) return;
QObject* o = l->first();
while ( o )
{
stats[o->name()]++;
updateStats( stats, const_cast<QObjectList*>( o->children() ) );
o = l->next();
}
}
QString OPacket::dumpStructure() const
{
return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]";
}
QString OPacket::_dumpStructure( QObjectList* l ) const
{
if (!l) return QString::null;
QObject* o = l->first();
QString str(" ");
while ( o )
{
str.append( o->name() );
str.append( " |" );
str += _dumpStructure( const_cast<QObjectList*>( o->children() ) );
o = l->next();
}
return str;
}
QString OPacket::dump( int bpl ) const
{
static int index = 0;
index++;
int len = _hdr.caplen;
QString str( "000:" );
QString tmp;
QString bytes;
QString chars;
for ( int i = 0; i < len; ++i )
{
tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp );
if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] );
else chars.append( '.' );
if ( !((i+1) % bpl) )
{
str.append( bytes );
str.append( ' ' );
str.append( chars );
str.append( '\n' );
tmp.sprintf( "%03X:", i+1 ); str.append( tmp );
bytes = "";
chars = "";
}
}
if ( (len % bpl) )
{
str.append( bytes.leftJustify( 1 + 3*bpl ) );
str.append( chars );
}
str.append( '\n' );
return str;
}
int OPacket::len() const
{
return _hdr.len;
}
QTextStream& operator<<( QTextStream& s, const OPacket& p )
{
s << p.dumpStructure();
+ return s;
}
/*======================================================================================
* OEthernetPacket
*======================================================================================*/
OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
:QObject( parent, "Ethernet" ), _ether( data )
{
odebug << "Source = " << sourceAddress().toString() << oendl;
odebug << "Destination = " << destinationAddress().toString() << oendl;
if ( sourceAddress() == OMacAddress::broadcast )
odebug << "Source is broadcast address" << oendl;
if ( destinationAddress() == OMacAddress::broadcast )
odebug << "Destination is broadcast address" << oendl;
switch ( type() )
{
case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break;
case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; }
default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl;
}
}
OEthernetPacket::~OEthernetPacket()
{
}
OMacAddress OEthernetPacket::sourceAddress() const
{
return OMacAddress( _ether->ether_shost );
}
OMacAddress OEthernetPacket::destinationAddress() const
{
return OMacAddress( _ether->ether_dhost );
}
int OEthernetPacket::type() const
{
return ntohs( _ether->ether_type );
}
/*======================================================================================
* OIPPacket
*======================================================================================*/
OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent )
:QObject( parent, "IP" ), _iphdr( data )
{
odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl;
odebug << "FromAddress = " << fromIPAddress().toString() << oendl;
odebug << " toAddress = " << toIPAddress().toString() << oendl;
switch ( protocol() )
{
case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break;
case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break;
default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl;
}
}
OIPPacket::~OIPPacket()
{
}
QHostAddress OIPPacket::fromIPAddress() const
{
return EXTRACT_32BITS( &_iphdr->saddr );
}
QHostAddress OIPPacket::toIPAddress() const
{
return EXTRACT_32BITS( &_iphdr->saddr );
}
int OIPPacket::tos() const
{
return _iphdr->tos;
}
int OIPPacket::len() const
{
return EXTRACT_16BITS( &_iphdr->tot_len );
}
int OIPPacket::id() const
{
return EXTRACT_16BITS( &_iphdr->id );
}
int OIPPacket::offset() const
{
return EXTRACT_16BITS( &_iphdr->frag_off );
}
int OIPPacket::ttl() const
{
return _iphdr->ttl;
}
int OIPPacket::protocol() const
{
return _iphdr->protocol;
}
int OIPPacket::checksum() const
{
return EXTRACT_16BITS( &_iphdr->check );
}
/*======================================================================================
* OARPPacket
*======================================================================================*/
-OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent )
+OARPPacket::OARPPacket( const unsigned char* /*end*/, const struct myarphdr* data, QObject* parent )
:QObject( parent, "ARP" ), _arphdr( data )
{
odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl;
odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl;
odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl;
odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl;
}
OARPPacket::~OARPPacket()
{
}
QString OARPPacket::type() const
{
switch ( EXTRACT_16BITS( &_arphdr->ar_op ) )
{
case 1: return "REQUEST";
case 2: return "REPLY";
case 3: return "RREQUEST";
case 4: return "RREPLY";
case 8: return "InREQUEST";
case 9: return "InREPLY";
case 10: return "NAK";
default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>";
}
}
QHostAddress OARPPacket::senderIPV4Address() const
{
return EXTRACT_32BITS( &_arphdr->ar_sip );
}
QHostAddress OARPPacket::targetIPV4Address() const
{
return EXTRACT_32BITS( &_arphdr->ar_tip );
}
OMacAddress OARPPacket::senderMacAddress() const
{
return OMacAddress( _arphdr->ar_sha );
}
OMacAddress OARPPacket::targetMacAddress() const
{
return OMacAddress( _arphdr->ar_tha );
}
/*======================================================================================
* OUDPPacket
*======================================================================================*/
OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent )
:QObject( parent, "UDP" ), _udphdr( data )
{
odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl;
odebug << "fromPort = " << fromPort() << oendl;
odebug << " toPort = " << toPort() << oendl;
// TODO: Make this a case or a hash if we know more udp protocols
if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC ||
toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC )
{
odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl;
new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this );
}
}
OUDPPacket::~OUDPPacket()
{
}
int OUDPPacket::fromPort() const
{
return EXTRACT_16BITS( &_udphdr->source );
}
int OUDPPacket::toPort() const
{
return EXTRACT_16BITS( &_udphdr->dest );
}
int OUDPPacket::length() const
@@ -454,193 +455,193 @@ ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* da
_type = 0;
const unsigned char* option = &_dhcphdr->options[4];
char tag = -1;
char len = -1;
while ( ( tag = *option++ ) != -1 /* end of option field */ )
{
len = *option++;
odebug << "recognized DHCP option #" << tag << ", length " << len << oendl;
if ( tag == DHO_DHCP_MESSAGE_TYPE )
_type = *option;
option += len;
if ( option >= end )
{
owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl;
break;
}
}
odebug << "DHCP type seems to be << " << type() << oendl;
}
ODHCPPacket::~ODHCPPacket()
{
}
bool ODHCPPacket::isRequest() const
{
return ( _dhcphdr->op == 01 );
}
bool ODHCPPacket::isReply() const
{
return ( _dhcphdr->op == 02 );
}
QString ODHCPPacket::type() const
{
switch ( _type )
{
case 1: return "DISCOVER";
case 2: return "OFFER";
case 3: return "REQUEST";
case 4: return "DECLINE";
case 5: return "ACK";
case 6: return "NAK";
case 7: return "RELEASE";
case 8: return "INFORM";
default: owarn << "ODHCPPacket::type(): invalid DHCP type " << _dhcphdr->op << oendl; return "<unknown>";
}
}
QHostAddress ODHCPPacket::clientAddress() const
{
return EXTRACT_32BITS( &_dhcphdr->ciaddr );
}
QHostAddress ODHCPPacket::yourAddress() const
{
return EXTRACT_32BITS( &_dhcphdr->yiaddr );
}
QHostAddress ODHCPPacket::serverAddress() const
{
return EXTRACT_32BITS( &_dhcphdr->siaddr );
}
QHostAddress ODHCPPacket::relayAddress() const
{
return EXTRACT_32BITS( &_dhcphdr->giaddr );
}
OMacAddress ODHCPPacket::clientMacAddress() const
{
return OMacAddress( _dhcphdr->chaddr );
}
/*======================================================================================
* OTCPPacket
*======================================================================================*/
-OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent )
+OTCPPacket::OTCPPacket( const unsigned char* /*end*/, const struct tcphdr* data, QObject* parent )
:QObject( parent, "TCP" ), _tcphdr( data )
{
odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl;
}
OTCPPacket::~OTCPPacket()
{
}
int OTCPPacket::fromPort() const
{
return EXTRACT_16BITS( &_tcphdr->source );
}
int OTCPPacket::toPort() const
{
return EXTRACT_16BITS( &_tcphdr->dest );
}
int OTCPPacket::seq() const
{
return EXTRACT_16BITS( &_tcphdr->seq );
}
int OTCPPacket::ack() const
{
return EXTRACT_16BITS( &_tcphdr->ack_seq );
}
int OTCPPacket::window() const
{
return EXTRACT_16BITS( &_tcphdr->window );
}
int OTCPPacket::checksum() const
{
return EXTRACT_16BITS( &_tcphdr->check );
}
/*======================================================================================
* OPrismHeaderPacket
*======================================================================================*/
OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent )
:QObject( parent, "Prism" ), _header( data )
{
odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl;
odebug << "Signal Strength = " << data->signal.data << oendl;
new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this );
}
OPrismHeaderPacket::~OPrismHeaderPacket()
{
}
unsigned int OPrismHeaderPacket::signalStrength() const
{
return _header->signal.data;
}
/*======================================================================================
* OWaveLanPacket
*======================================================================================*/
OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent )
:QObject( parent, "802.11" ), _wlanhdr( data )
{
odebug << "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." << oendl;
odebug << "type = " << type() << oendl;
odebug << "subType = " << subType() << oendl;
odebug << "duration = " << duration() << oendl;
odebug << "powermanagement = " << usesPowerManagement() << oendl;
odebug << "payload is encrypted = " << ( usesWep() ? "yes" : "no" ) << oendl;
odebug << "MAC1 = " << macAddress1().toString() << oendl;
odebug << "MAC2 = " << macAddress2().toString() << oendl;
odebug << "MAC3 = " << macAddress3().toString() << oendl;
odebug << "MAC4 = " << macAddress4().toString() << oendl;
switch ( type() )
{
case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break;
@@ -741,391 +742,391 @@ OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, co
// Grab tagged values.
// Beacons contain a 12 byte long fixed parameters set before the tagged parameters come,
// Other management frames don't - which is why we have to inspect the subtype here.
const unsigned char* ptr = managementType() == "Beacon" ? (const unsigned char*) (_body+1) : (const unsigned char*) (_header+1);
while (ptr < end)
{
switch ( *ptr )
{
case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break;
case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break;
case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break;
case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break;
case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break;
case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break;
case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break;
case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break;
}
ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value
ptr+= 2; // skip tag ID and length
}
}
OWaveLanManagementPacket::~OWaveLanManagementPacket()
{
}
QString OWaveLanManagementPacket::managementType() const
{
switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) )
{
case ST_ASSOC_REQUEST: return "AssociationRequest"; break;
case ST_ASSOC_RESPONSE: return "AssociationResponse"; break;
case ST_REASSOC_REQUEST: return "ReassociationRequest"; break;
case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break;
case ST_PROBE_REQUEST: return "ProbeRequest"; break;
case ST_PROBE_RESPONSE: return "ProbeResponse"; break;
case ST_BEACON: return "Beacon"; break;
case ST_ATIM: return "Atim"; break;
case ST_DISASSOC: return "Disassociation"; break;
case ST_AUTH: return "Authentication"; break;
case ST_DEAUTH: return "Deathentication"; break;
default: owarn << "OWaveLanManagementPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; return "Unknown";
}
}
int OWaveLanManagementPacket::beaconInterval() const
{
return EXTRACT_LE_16BITS( &_body->beacon_interval );
}
int OWaveLanManagementPacket::capabilities() const
{
return EXTRACT_LE_16BITS( &_body->capability_info );
}
bool OWaveLanManagementPacket::canESS() const
{
return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) );
}
bool OWaveLanManagementPacket::canIBSS() const
{
return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) );
}
bool OWaveLanManagementPacket::canCFP() const
{
return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) );
}
bool OWaveLanManagementPacket::canCFP_REQ() const
{
return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) );
}
bool OWaveLanManagementPacket::canPrivacy() const
{
return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) );
}
/*======================================================================================
* OWaveLanManagementSSID
*======================================================================================*/
-OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent )
+OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* /*end*/, const struct ssid_t* data, QObject* parent )
:QObject( parent, "802.11 SSID" ), _data( data )
{
odebug << "OWaveLanManagementSSID()" << oendl;
}
OWaveLanManagementSSID::~OWaveLanManagementSSID()
{
}
QString OWaveLanManagementSSID::ID( bool decloak ) const
{
int length = _data->length;
if ( length > 32 ) length = 32;
char essid[length+1];
memcpy( &essid, &_data->ssid, length );
essid[length] = 0x0;
if ( !decloak || length < 2 || essid[0] != '\0' ) return essid;
odebug << "OWaveLanManagementSSID:ID(): SSID is cloaked - decloaking..." << oendl;
QString decloakedID;
for ( int i = 1; i < length; ++i )
{
if ( essid[i] >= 32 && essid[i] <= 126 ) decloakedID.append( essid[i] );
else decloakedID.append( '.' );
}
return decloakedID;
}
/*======================================================================================
* OWaveLanManagementRates
*======================================================================================*/
-OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent )
+OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* /*end*/, const struct rates_t* data, QObject* parent )
:QObject( parent, "802.11 Rates" ), _data( data )
{
odebug << "OWaveLanManagementRates()" << oendl;
}
OWaveLanManagementRates::~OWaveLanManagementRates()
{
}
/*======================================================================================
* OWaveLanManagementCF
*======================================================================================*/
-OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent )
+OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* /*end*/, const struct cf_t* data, QObject* parent )
:QObject( parent, "802.11 CF" ), _data( data )
{
odebug << "OWaveLanManagementCF()" << oendl;
}
OWaveLanManagementCF::~OWaveLanManagementCF()
{
}
/*======================================================================================
* OWaveLanManagementFH
*======================================================================================*/
-OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent )
+OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* /*end*/, const struct fh_t* data, QObject* parent )
:QObject( parent, "802.11 FH" ), _data( data )
{
odebug << "OWaveLanManagementFH()" << oendl;
}
OWaveLanManagementFH::~OWaveLanManagementFH()
{
}
/*======================================================================================
* OWaveLanManagementDS
*======================================================================================*/
-OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent )
+OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* /*end*/, const struct ds_t* data, QObject* parent )
:QObject( parent, "802.11 DS" ), _data( data )
{
odebug << "OWaveLanManagementDS()" << oendl;
}
OWaveLanManagementDS::~OWaveLanManagementDS()
{
}
int OWaveLanManagementDS::channel() const
{
return _data->channel;
}
/*======================================================================================
* OWaveLanManagementTim
*======================================================================================*/
-OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent )
+OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* /*end*/, const struct tim_t* data, QObject* parent )
:QObject( parent, "802.11 Tim" ), _data( data )
{
odebug << "OWaveLanManagementTim()" << oendl;
}
OWaveLanManagementTim::~OWaveLanManagementTim()
{
}
/*======================================================================================
* OWaveLanManagementIBSS
*======================================================================================*/
-OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent )
+OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* /*end*/, const struct ibss_t* data, QObject* parent )
:QObject( parent, "802.11 IBSS" ), _data( data )
{
odebug << "OWaveLanManagementIBSS()" << oendl;
}
OWaveLanManagementIBSS::~OWaveLanManagementIBSS()
{
}
/*======================================================================================
* OWaveLanManagementChallenge
*======================================================================================*/
-OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent )
+OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* /*end*/, const struct challenge_t* data, QObject* parent )
:QObject( parent, "802.11 Challenge" ), _data( data )
{
odebug << "OWaveLanManagementChallenge()" << oendl;
}
OWaveLanManagementChallenge::~OWaveLanManagementChallenge()
{
}
/*======================================================================================
* OWaveLanDataPacket
*======================================================================================*/
OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent )
:QObject( parent, "802.11 Data" ), _header( data )
{
odebug << "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." << oendl;
const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header );
#warning The next line works for most cases, but can not be correct generally!
if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address
new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this );
}
OWaveLanDataPacket::~OWaveLanDataPacket()
{
}
/*======================================================================================
* OLLCPacket
*======================================================================================*/
OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent )
:QObject( parent, "802.11 LLC" ), _header( data )
{
odebug << "OLLCPacket::OLLCPacket(): decoding frame..." << oendl;
if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) )
{
owarn << "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type = " << EXTRACT_16BITS( &_header->type ) << ")" << oendl;
switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h
{
case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break;
default: owarn << "OLLCPacket::OLLCPacket(): Unknown Encapsulation type = " << EXTRACT_16BITS( &_header->type ) << oendl;
}
}
}
OLLCPacket::~OLLCPacket()
{
}
/*======================================================================================
* OWaveLanControlPacket
*======================================================================================*/
-OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent )
+OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* /*end*/, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent )
:QObject( parent, "802.11 Control" ), _header( data )
{
odebug << "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." << oendl;
odebug << "Detected subtype is " << controlType() << oendl;
}
OWaveLanControlPacket::~OWaveLanControlPacket()
{
}
QString OWaveLanControlPacket::controlType() const
{
switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) )
{
case CTRL_PS_POLL: return "PowerSavePoll"; break;
case CTRL_RTS: return "RequestToSend"; break;
case CTRL_CTS: return "ClearToSend"; break;
case CTRL_ACK: return "Acknowledge"; break;
case CTRL_CF_END: return "ContentionFreeEnd"; break;
case CTRL_END_ACK: return "AcknowledgeEnd"; break;
default:
owarn << "OWaveLanControlPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl;
return "Unknown";
}
}
/*======================================================================================
* OPacketCapturer
*======================================================================================*/
OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
:QObject( parent, name ), _name( QString::null ), _open( false ), _pch( 0 ), _pcd( 0 ), _sn( 0 ), _autodelete( true )
{
}
OPacketCapturer::~OPacketCapturer()
{
if ( _open )
{
odebug << "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." << oendl;
close();
}
}
void OPacketCapturer::setAutoDelete( bool b )
{
_autodelete = b;
}
bool OPacketCapturer::autoDelete() const
{
return _autodelete;
}
void OPacketCapturer::setBlocking( bool b )
{
if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
{
odebug << "OPacketCapturer::setBlocking(): blocking mode changed successfully." << oendl;
}
else
{
odebug << "OPacketCapturer::setBlocking(): can't change blocking mode: " << _errbuf << oendl;
}
}
bool OPacketCapturer::blocking() const
{
int b = pcap_getnonblock( _pch, _errbuf );
if ( b == -1 )
{
odebug << "OPacketCapturer::blocking(): can't get blocking mode: " << _errbuf << oendl;
return -1;
}
return !b;
}
void OPacketCapturer::closeDumpFile()
{
if ( _pcd )
{
pcap_dump_close( _pcd );
_pcd = 0;
}
pcap_close( _pch );
}