summaryrefslogtreecommitdiff
path: root/libopie2/opienet/opcap.cpp
authormickeyl <mickeyl>2003-03-30 01:41:56 (UTC)
committer mickeyl <mickeyl>2003-03-30 01:41:56 (UTC)
commit99899abc80a8aa05044eeecd8a061b0a8efaa713 (patch) (side-by-side diff)
tree45db7a60f17d00ae72d0e8d6b986d5be10232c6c /libopie2/opienet/opcap.cpp
parent340cb7e64fb898966996b00b93c03ca05a347aa5 (diff)
downloadopie-99899abc80a8aa05044eeecd8a061b0a8efaa713.zip
opie-99899abc80a8aa05044eeecd8a061b0a8efaa713.tar.gz
opie-99899abc80a8aa05044eeecd8a061b0a8efaa713.tar.bz2
- add classes for 802.11 tagged values
- adjust miniwellenreiter accordingly
Diffstat (limited to 'libopie2/opienet/opcap.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp253
1 files changed, 225 insertions, 28 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 48f874f..913d42e 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -51,2 +51,5 @@ OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject*
+ _end = (unsigned char*) data + header.len;
+ qDebug( "OPacket::data @ %0x, end @ %0x", data, _end );
+
if ( packetCapturer()->dataLink() == DLT_EN10MB )
@@ -54,3 +57,3 @@ OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject*
qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" );
- new OEthernetPacket( (const struct ether_header*) data, this );
+ new OEthernetPacket( _end, (const struct ether_header*) data, this );
}
@@ -59,3 +62,3 @@ OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject*
qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" );
- new OWaveLanPacket( (const struct ieee_802_11_header*) data, this );
+ new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this );
}
@@ -111,3 +114,3 @@ int OPacket::len() const
-OEthernetPacket::OEthernetPacket( const struct ether_header* data, QObject* parent )
+OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
:QObject( parent, "Ethernet" ), _ether( data )
@@ -126,3 +129,3 @@ OEthernetPacket::OEthernetPacket( const struct ether_header* data, QObject* pare
{
- case ETHERTYPE_IP: new OIPPacket( (const struct iphdr*) (data+1), this ); break;
+ case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; }
@@ -162,3 +165,3 @@ int OEthernetPacket::type() const
-OIPPacket::OIPPacket( const struct iphdr* data, QObject* parent )
+OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent )
:QObject( parent, "IP" ), _iphdr( data )
@@ -176,4 +179,4 @@ OIPPacket::OIPPacket( const struct iphdr* data, QObject* parent )
{
- case IPPROTO_UDP: new OUDPPacket( (const struct udphdr*) (data+1), this ); break;
- case IPPROTO_TCP: new OTCPPacket( (const struct tcphdr*) (data+1), this ); break;
+ 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: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() );
@@ -246,3 +249,3 @@ int OIPPacket::checksum() const
-OUDPPacket::OUDPPacket( const struct udphdr* data, QObject* parent )
+OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent )
:QObject( parent, "UDP" ), _udphdr( data )
@@ -263,3 +266,3 @@ OUDPPacket::~OUDPPacket()
-OTCPPacket::OTCPPacket( const struct tcphdr* data, QObject* parent )
+OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent )
:QObject( parent, "TCP" ), _tcphdr( data )
@@ -280,3 +283,3 @@ OTCPPacket::~OTCPPacket()
-OWaveLanPacket::OWaveLanPacket( const struct ieee_802_11_header* data, QObject* parent )
+OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent )
:QObject( parent, "802.11" ), _wlanhdr( data )
@@ -297,5 +300,5 @@ OWaveLanPacket::OWaveLanPacket( const struct ieee_802_11_header* data, QObject*
{
- case T_MGMT: new OWaveLanManagementPacket( (const struct ieee_802_11_mgmt_header*) data, this ); break;
- case T_DATA: new OWaveLanDataPacket( (const struct ieee_802_11_data_header*) data, this ); break;
- //case T_CTRL: new OWaveLanControlPacket( (const struct ieee_802_11_ctrl_header*) data, this ); break;
+ case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break;
+ case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break;
+ //case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_ctrl_header*) data, this ); break;
default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown type!" );
@@ -385,3 +388,3 @@ bool OWaveLanPacket::usesWep() const
-OWaveLanManagementPacket::OWaveLanManagementPacket( const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent )
+OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent )
:QObject( parent, "802.11 Management" ), _header( data ),
@@ -395,6 +398,23 @@ OWaveLanManagementPacket::OWaveLanManagementPacket( const struct ieee_802_11_mgm
{
- qDebug( "TYPE: BEACON FRAME" );
- qDebug( "ESSID: %s", (const char*) SSID() );
- break;
+ // nice, received a beacon...
+ }
+ }
+
+ // grab tagged values
+ const unsigned char* ptr = (const unsigned char*) (_body+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
}
@@ -408,8 +428,66 @@ OWaveLanManagementPacket::~OWaveLanManagementPacket()
-QString OWaveLanManagementPacket::SSID() const
+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
{
- int length = _body->ssid.length;
+ 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 )
+ :QObject( parent, "802.11 SSID" ), _data( data )
+{
+ qDebug( "OWaveLanManagementSSID()" );
+}
+
+
+OWaveLanManagementSSID::~OWaveLanManagementSSID()
+{
+}
+
+
+QString OWaveLanManagementSSID::ID() const
+{
+ int length = _data->length;
if ( length > 32 ) length = 32;
char essid[length+1];
- memcpy( &essid, _body->ssid.ssid, length );
+ memcpy( &essid, &_data->ssid, length );
essid[length] = 0x0;
@@ -420,2 +498,113 @@ QString OWaveLanManagementPacket::SSID() const
/*======================================================================================
+ * OWaveLanManagementRates
+ *======================================================================================*/
+
+OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent )
+ :QObject( parent, "802.11 Rates" ), _data( data )
+{
+ qDebug( "OWaveLanManagementRates()" );
+}
+
+
+OWaveLanManagementRates::~OWaveLanManagementRates()
+{
+}
+
+/*======================================================================================
+ * OWaveLanManagementCF
+ *======================================================================================*/
+
+OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent )
+ :QObject( parent, "802.11 CF" ), _data( data )
+{
+ qDebug( "OWaveLanManagementCF()" );
+}
+
+
+OWaveLanManagementCF::~OWaveLanManagementCF()
+{
+}
+
+/*======================================================================================
+ * OWaveLanManagementFH
+ *======================================================================================*/
+
+OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent )
+ :QObject( parent, "802.11 FH" ), _data( data )
+{
+ qDebug( "OWaveLanManagementFH()" );
+}
+
+
+OWaveLanManagementFH::~OWaveLanManagementFH()
+{
+}
+
+/*======================================================================================
+ * OWaveLanManagementDS
+ *======================================================================================*/
+
+OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent )
+ :QObject( parent, "802.11 DS" ), _data( data )
+{
+ qDebug( "OWaveLanManagementDS()" );
+}
+
+
+OWaveLanManagementDS::~OWaveLanManagementDS()
+{
+}
+
+
+int OWaveLanManagementDS::channel() const
+{
+ return _data->channel;
+}
+
+/*======================================================================================
+ * OWaveLanManagementTim
+ *======================================================================================*/
+
+OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent )
+ :QObject( parent, "802.11 Tim" ), _data( data )
+{
+ qDebug( "OWaveLanManagementTim()" );
+}
+
+
+OWaveLanManagementTim::~OWaveLanManagementTim()
+{
+}
+
+/*======================================================================================
+ * OWaveLanManagementIBSS
+ *======================================================================================*/
+
+OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent )
+ :QObject( parent, "802.11 IBSS" ), _data( data )
+{
+ qDebug( "OWaveLanManagementIBSS()" );
+}
+
+
+OWaveLanManagementIBSS::~OWaveLanManagementIBSS()
+{
+}
+
+/*======================================================================================
+ * OWaveLanManagementChallenge
+ *======================================================================================*/
+
+OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent )
+ :QObject( parent, "802.11 Challenge" ), _data( data )
+{
+ qDebug( "OWaveLanManagementChallenge()" );
+}
+
+
+OWaveLanManagementChallenge::~OWaveLanManagementChallenge()
+{
+}
+
+/*======================================================================================
* OWaveLanDataPacket
@@ -423,3 +612,3 @@ QString OWaveLanManagementPacket::SSID() const
-OWaveLanDataPacket::OWaveLanDataPacket( const struct ieee_802_11_data_header* data, OWaveLanPacket* parent )
+OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent )
:QObject( parent, "802.11 Data" ), _header( data )
@@ -433,3 +622,3 @@ OWaveLanDataPacket::OWaveLanDataPacket( const struct ieee_802_11_data_header* da
- new OLLCPacket( (const struct ieee_802_11_802_2_header*) payload, this );
+ new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this );
}
@@ -446,3 +635,3 @@ OWaveLanDataPacket::~OWaveLanDataPacket()
-OLLCPacket::OLLCPacket( const struct ieee_802_11_802_2_header* data, QObject* parent )
+OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent )
:QObject( parent, "802.11 802_2" ), _header( data )
@@ -457,3 +646,3 @@ OLLCPacket::OLLCPacket( const struct ieee_802_11_802_2_header* data, QObject* pa
{
- case ETH_P_IP: new OIPPacket( (const struct iphdr*) (data+1), this ); break;
+ case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" );
@@ -475,3 +664,3 @@ OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
:QObject( parent, name ), _name( QString::null ), _open( false ),
- _pch( 0 )
+ _pch( 0 ), _sn( 0 )
{
@@ -519,2 +708,7 @@ void OPacketCapturer::close()
{
+ if ( _sn )
+ {
+ _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
+ delete _sn;
+ }
pcap_close( _pch );
@@ -547,3 +741,6 @@ OPacket* OPacketCapturer::next()
packetheaderstruct header;
+ qDebug( "==> OPacketCapturer::next()" );
const unsigned char* pdata = pcap_next( _pch, &header );
+ qDebug( "<== OPacketCapturer::next()" );
+
if ( header.len )
@@ -579,7 +776,7 @@ bool OPacketCapturer::open( const QString& name )
- // in case we have a qapp, create a socket notifier
+ // in case we have an application object, create a socket notifier
if ( qApp )
{
- QSocketNotifier* sn = new QSocketNotifier( fileno(), QSocketNotifier::Read, this );
- connect( sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
+ _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
+ connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
}