Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

opcap.h

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de>
00004               =.
00005             .=l.
00006            .>+-=
00007  _;:,     .>    :=|.         This program is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; version 2 of the License.
00012      ._= =}       :           
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This program is distributed in the hope that
00015      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=       =       ;      Library General Public License for more
00020 ++=   -.     .`     .:       details.
00021  :     =  ...= . :.=-
00022  -.   .:....=;==+<;          You should have received a copy of the GNU
00023   -_. . .   )=.  =           Library General Public License along with
00024     --        :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
00028 
00029 */
00030 
00031 #ifndef OPCAP_H
00032 #define OPCAP_H
00033 
00034 /* OPIE */
00035 #include <opie2/onetutils.h>
00036 
00037 /* QT */
00038 #include <qevent.h>
00039 #include <qfile.h>
00040 #include <qhostaddress.h>
00041 #include <qobject.h>
00042 #include <qstring.h>
00043 #include <qtextstream.h>
00044 #include <qmap.h>
00045 
00046 /* STD */
00047 extern "C"  // work around a bpf/pcap conflict in recent headers
00048 {
00049     #include <pcap.h>
00050 }
00051 #include <netinet/ether.h>
00052 #include <netinet/ip.h>
00053 #include <netinet/udp.h>
00054 #include <netinet/tcp.h>
00055 #include <time.h>
00056 
00057 /* Custom Network Includes (must go here, don't reorder!) */
00058 #include "802_11_user.h"
00059 #include "dhcp.h"
00060 
00061 /* TYPEDEFS */
00062 typedef struct timeval timevalstruct;
00063 typedef struct pcap_pkthdr packetheaderstruct;
00064 
00065 /* FORWARDS */
00066 class QSocketNotifier;
00067 namespace Opie {
00068 namespace Net  {
00069 class OPacketCapturer;
00070 
00071 /*======================================================================================
00072  * OPacket - A frame on the wire
00073  *======================================================================================*/
00074 
00117 class OPacket : public QObject
00118 {
00119   Q_OBJECT
00120 
00121   friend class OPacketCapturer;
00122   friend QTextStream& operator<<( QTextStream& s, const OPacket& p );
00123 
00124   public:
00125     OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent );
00126     virtual ~OPacket();
00127 
00128     timevalstruct timeval() const;
00129 
00130     int caplen() const;
00131     int len() const;
00132     QString dump( int = 32 ) const; //FIXME: remove that
00133 
00134     void updateStats( QMap<QString,int>&, QObjectList* ); //FIXME: Revise
00135 
00136     QString dumpStructure() const; //FIXME: Revise
00137   private:
00138     QString _dumpStructure( QObjectList* ) const; //FIXME: Revise
00139 
00140   private:
00141     const packetheaderstruct _hdr;  // pcap packet header
00142     const unsigned char* _data;     // pcap packet data
00143     const unsigned char* _end;      // end of pcap packet data
00144   private:
00145     class Private;
00146     Private *d;
00147 };
00148 
00149 QTextStream& operator<<( QTextStream& s, const OPacket& p ); //FIXME: Revise
00150 
00151 /*======================================================================================
00152  * OEthernetPacket - DLT_EN10MB frame
00153  *======================================================================================*/
00154 
00155 class OEthernetPacket : public QObject
00156 {
00157   Q_OBJECT
00158 
00159   public:
00160     OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 );
00161     virtual ~OEthernetPacket();
00162 
00163     OMacAddress sourceAddress() const;
00164     OMacAddress destinationAddress() const;
00165     int type() const;
00166 
00167   private:
00168     const struct ether_header* _ether;
00169   private:
00170     class Private;
00171     Private *d;
00172 };
00173 
00174 /*======================================================================================
00175  * OPrismHeaderPacket - DLT_PRISM_HEADER frame
00176  *======================================================================================*/
00177 
00178 class OPrismHeaderPacket : public QObject
00179 {
00180   Q_OBJECT
00181 
00182   public:
00183     OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 );
00184     virtual ~OPrismHeaderPacket();
00185 
00186     unsigned int signalStrength() const;
00187 
00188   private:
00189     const struct prism_hdr* _header;
00190     class Private;
00191     Private *d;
00192 };
00193 
00194 /*======================================================================================
00195  * OWaveLanPacket - DLT_IEEE802_11 frame
00196  *======================================================================================*/
00197 
00198 class OWaveLanPacket : public QObject
00199 {
00200   Q_OBJECT
00201 
00202   public:
00203     OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 );
00204     virtual ~OWaveLanPacket();
00205 
00206     int duration() const;
00207     bool fromDS() const;
00208     bool toDS() const;
00209     virtual OMacAddress macAddress1() const;
00210     virtual OMacAddress macAddress2() const;
00211     virtual OMacAddress macAddress3() const;
00212     virtual OMacAddress macAddress4() const;
00213     bool usesPowerManagement() const;
00214     int type() const;
00215     int subType() const;
00216     int version() const;
00217     bool usesWep() const;
00218 
00219   private:
00220     const struct ieee_802_11_header* _wlanhdr;
00221     class Private;
00222     Private *d;
00223 };
00224 
00225 
00226 /*======================================================================================
00227  * OWaveLanManagementPacket - type: management (T_MGMT)
00228  *======================================================================================*/
00229 
00230 class OWaveLanManagementPacket : public QObject
00231 {
00232   Q_OBJECT
00233 
00234   public:
00235     OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 );
00236     virtual ~OWaveLanManagementPacket();
00237 
00238     QString managementType() const;
00239 
00240     int beaconInterval() const;
00241     int capabilities() const; // generic
00242 
00243     bool canESS() const;
00244     bool canIBSS() const;
00245     bool canCFP() const;
00246     bool canCFP_REQ() const;
00247     bool canPrivacy() const;
00248 
00249   private:
00250     const struct ieee_802_11_mgmt_header* _header;
00251     const struct ieee_802_11_mgmt_body* _body;
00252     class Private;
00253     Private *d;
00254 };
00255 
00256 
00257 /*======================================================================================
00258  * OWaveLanManagementSSID
00259  *======================================================================================*/
00260 
00261 class OWaveLanManagementSSID : public QObject
00262 {
00263   Q_OBJECT
00264 
00265   public:
00266     OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 );
00267     virtual ~OWaveLanManagementSSID();
00268 
00269     QString ID( bool decloak = false ) const;
00270 
00271   private:
00272     const struct ssid_t* _data;
00273     class Private;
00274     Private *d;
00275 };
00276 
00277 /*======================================================================================
00278  * OWaveLanManagementRates
00279  *======================================================================================*/
00280 
00281 class OWaveLanManagementRates : public QObject
00282 {
00283   Q_OBJECT
00284 
00285   public:
00286     OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 );
00287     virtual ~OWaveLanManagementRates();
00288 
00289   private:
00290     const struct rates_t* _data;
00291     class Private;
00292     Private *d;
00293 };
00294 
00295 /*======================================================================================
00296  * OWaveLanManagementCF
00297  *======================================================================================*/
00298 
00299 class OWaveLanManagementCF : public QObject
00300 {
00301   Q_OBJECT
00302 
00303   public:
00304     OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 );
00305     virtual ~OWaveLanManagementCF();
00306 
00307   private:
00308     const struct cf_t* _data;
00309     class Private;
00310     Private *d;
00311 };
00312 
00313 /*======================================================================================
00314  * OWaveLanManagementFH
00315  *======================================================================================*/
00316 
00317 class OWaveLanManagementFH : public QObject
00318 {
00319   Q_OBJECT
00320 
00321   public:
00322     OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 );
00323     virtual ~OWaveLanManagementFH();
00324 
00325   private:
00326     const struct fh_t* _data;
00327     class Private;
00328     Private *d;
00329 };
00330 
00331 /*======================================================================================
00332  * OWaveLanManagementDS
00333  *======================================================================================*/
00334 
00335 class OWaveLanManagementDS : public QObject
00336 {
00337   Q_OBJECT
00338 
00339   public:
00340     OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 );
00341     virtual ~OWaveLanManagementDS();
00342 
00343     int channel() const;
00344 
00345   private:
00346     const struct ds_t* _data;
00347     class Private;
00348     Private *d;
00349 };
00350 
00351 /*======================================================================================
00352  * OWaveLanManagementTim
00353  *======================================================================================*/
00354 
00355 class OWaveLanManagementTim : public QObject
00356 {
00357   Q_OBJECT
00358 
00359   public:
00360     OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 );
00361     virtual ~OWaveLanManagementTim();
00362 
00363   private:
00364     const struct tim_t* _data;
00365     class Private;
00366     Private *d;
00367 };
00368 
00369 /*======================================================================================
00370  * OWaveLanManagementIBSS
00371  *======================================================================================*/
00372 
00373 class OWaveLanManagementIBSS : public QObject
00374 {
00375   Q_OBJECT
00376 
00377   public:
00378     OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 );
00379     virtual ~OWaveLanManagementIBSS();
00380 
00381   private:
00382     const struct ibss_t* _data;
00383     class Private;
00384     Private *d;
00385 };
00386 
00387 /*======================================================================================
00388  * OWaveLanManagementChallenge
00389  *======================================================================================*/
00390 
00391 class OWaveLanManagementChallenge : public QObject
00392 {
00393   Q_OBJECT
00394 
00395   public:
00396     OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 );
00397     virtual ~OWaveLanManagementChallenge();
00398 
00399   private:
00400     const struct challenge_t* _data;
00401     class Private;
00402     Private *d;
00403 };
00404 
00405 /*======================================================================================
00406  * OWaveLanDataPacket - type: data (T_DATA)
00407  *======================================================================================*/
00408 
00409 class OWaveLanDataPacket : public QObject
00410 {
00411   Q_OBJECT
00412 
00413   public:
00414     OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 );
00415     virtual ~OWaveLanDataPacket();
00416 
00417   private:
00418     const struct ieee_802_11_data_header* _header;
00419     class Private;
00420     Private *d;
00421 };
00422 
00423 /*======================================================================================
00424  * OWaveLanControlPacket - type: control (T_CTRL)
00425  *======================================================================================*/
00426 
00427 class OWaveLanControlPacket : public QObject
00428 {
00429   Q_OBJECT
00430 
00431   public:
00432     OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 );
00433     virtual ~OWaveLanControlPacket();
00434 
00435     QString controlType() const;
00436 
00437   private:
00438     const struct ieee_802_11_control_header* _header;
00439     class Private;
00440     Private *d;
00441 };
00442 
00443 /*======================================================================================
00444  * OLLCPacket - IEEE 802.2 Link Level Control
00445  *======================================================================================*/
00446 
00447 class OLLCPacket : public QObject
00448 {
00449   Q_OBJECT
00450 
00451   public:
00452     OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 );
00453     virtual ~OLLCPacket();
00454 
00455   private:
00456     const struct ieee_802_11_802_2_header* _header;
00457     class Private;
00458     Private *d;
00459 };
00460 
00461 /*======================================================================================
00462  * OIPPacket
00463  *======================================================================================*/
00464 
00465 class OIPPacket : public QObject
00466 {
00467   Q_OBJECT
00468 
00469   public:
00470     OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 );
00471     virtual ~OIPPacket();
00472 
00473     QHostAddress fromIPAddress() const;
00474     QHostAddress toIPAddress() const;
00475 
00476     int tos() const;
00477     int len() const;
00478     int id() const;
00479     int offset() const;
00480     int ttl() const;
00481     int protocol() const;
00482     int checksum() const;
00483 
00484   private:
00485     const struct iphdr* _iphdr;
00486     class Private;
00487     Private *d;
00488 };
00489 
00490 /*======================================================================================
00491  * OARPPacket
00492  *======================================================================================*/
00493 
00494 class OARPPacket : public QObject
00495 {
00496   Q_OBJECT
00497 
00498   public:
00499     OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 );
00500     virtual ~OARPPacket();
00501 
00502     QHostAddress senderIPV4Address() const;
00503     OMacAddress senderMacAddress() const;
00504     QHostAddress targetIPV4Address() const;
00505     OMacAddress targetMacAddress() const;
00506 
00507     //int type() const;
00508     QString type() const;
00509 
00510   private:
00511     const struct myarphdr* _arphdr;
00512     class Private;
00513     Private *d;
00514 };
00515 
00516 /*======================================================================================
00517  * OUDPPacket
00518  *======================================================================================*/
00519 
00520 class OUDPPacket : public QObject
00521 {
00522   Q_OBJECT
00523 
00524   public:
00525     OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 );
00526     virtual ~OUDPPacket();
00527 
00528     int fromPort() const;
00529     int toPort() const;
00530     int length() const;
00531     int checksum() const;
00532 
00533   private:
00534     const struct udphdr* _udphdr;
00535     class Private;
00536     Private *d;
00537 };
00538 
00539 /*======================================================================================
00540  * ODHCPPacket
00541  *======================================================================================*/
00542 
00543 class ODHCPPacket : public QObject
00544 {
00545   Q_OBJECT
00546 
00547   public:
00548     ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 );
00549     virtual ~ODHCPPacket();
00550 
00551     QHostAddress clientAddress() const;
00552     QHostAddress yourAddress() const;
00553     QHostAddress serverAddress() const;
00554     QHostAddress relayAddress() const;
00555 
00556     OMacAddress clientMacAddress() const;
00557 
00558     bool isRequest() const;
00559     bool isReply() const;
00560     QString type() const;
00561 
00562   private:
00563     const struct dhcp_packet* _dhcphdr;
00564     unsigned char _type;
00565     class Private;
00566     Private *d;
00567 };
00568 
00569 /*======================================================================================
00570  * OTCPPacket
00571  *======================================================================================*/
00572 
00573 class OTCPPacket : public QObject
00574 {
00575   Q_OBJECT
00576 
00577   public:
00578     OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 );
00579     virtual ~OTCPPacket();
00580 
00581     int fromPort() const;
00582     int toPort() const;
00583     int seq() const;
00584     int ack() const;
00585     int window() const;
00586     int checksum() const;
00587 
00588   private:
00589     const struct tcphdr* _tcphdr;
00590     class Private;
00591     Private *d;
00592 };
00593 
00594 
00595 /*======================================================================================
00596  * OPacketCapturer
00597  *======================================================================================*/
00598 
00606 class OPacketCapturer : public QObject
00607 {
00608   Q_OBJECT
00609 
00610   public:
00614     OPacketCapturer( QObject* parent = 0, const char* name = 0 );
00618     ~OPacketCapturer();
00623     void setBlocking( bool );
00627     bool blocking() const;
00631     void close();
00635     void closeDumpFile();
00640     int dataLink() const;
00644     void dump( OPacket* );
00649     int fileno() const;
00654     OPacket* next();
00659     OPacket* next( int time );
00663     bool open( const QString& interface );
00667     bool openCaptureFile( const QString& filename );
00671     bool openDumpFile( const QString& filename );
00675     bool isOpen() const;
00679     int snapShot() const;
00684     bool swapped() const;
00688     QString version() const;
00693     const QMap<QString,int>& statistics() const;
00701     void setAutoDelete( bool enable );
00705     bool autoDelete() const;
00706 
00707   signals:
00711     void receivedPacket( Opie::Net::OPacket* );
00712 
00713   protected slots:
00714     void readyToReceive();
00715 
00716   protected:
00717     QString _name;                                  // devicename
00718     bool _open;                                     // check this before doing pcap calls
00719     pcap_t* _pch;                                   // pcap library handle
00720     pcap_dumper_t* _pcd;                            // pcap dumper handle
00721     QSocketNotifier* _sn;                           // socket notifier for main loop
00722     mutable char _errbuf[PCAP_ERRBUF_SIZE];         // holds error strings from libpcap
00723     QMap<QString, int> _stats;                      // statistics;
00724     bool _autodelete;                               // if we auto delete packets after emit
00725     class Private;                                  // Private Forward declaration
00726     Private *d;                                     // if we need to add data
00727 };
00728 }
00729 }
00730 
00731 #endif // OPCAP_H
00732 

Generated on Sat Nov 5 16:16:13 2005 for OPIE by  doxygen 1.4.2