summaryrefslogtreecommitdiff
path: root/libopie2/opienet/opcap.h
authormickeyl <mickeyl>2003-04-10 15:47:23 (UTC)
committer mickeyl <mickeyl>2003-04-10 15:47:23 (UTC)
commit3733471135ea180709fcf4695607cce0c5fc7fb5 (patch) (unidiff)
tree792c96ad5351b9396a0c129738b5cff9e2b00614 /libopie2/opienet/opcap.h
parent101e039ba53d4ccbe5b46575bb56c07f6f544db6 (diff)
downloadopie-3733471135ea180709fcf4695607cce0c5fc7fb5.zip
opie-3733471135ea180709fcf4695607cce0c5fc7fb5.tar.gz
opie-3733471135ea180709fcf4695607cce0c5fc7fb5.tar.bz2
add support for working with capture files (e.g. from tcpdump, ethereal, et.al.)
Diffstat (limited to 'libopie2/opienet/opcap.h') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opienet/opcap.h54
1 files changed, 50 insertions, 4 deletions
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h
index c9b0624..6c3ac6d 100644
--- a/libopie2/opienet/opcap.h
+++ b/libopie2/opienet/opcap.h
@@ -26,48 +26,49 @@
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef OPCAP_H 34#ifndef OPCAP_H
35#define OPCAP_H 35#define OPCAP_H
36 36
37/* LINUX */ 37/* LINUX */
38extern "C" // work around a bpf/pcap conflict in recent headers 38extern "C" // work around a bpf/pcap conflict in recent headers
39{ 39{
40 #include <pcap.h> 40 #include <pcap.h>
41} 41}
42#include <netinet/ether.h> 42#include <netinet/ether.h>
43#include <netinet/ip.h> 43#include <netinet/ip.h>
44#include <netinet/udp.h> 44#include <netinet/udp.h>
45#include <netinet/tcp.h> 45#include <netinet/tcp.h>
46#include <time.h> 46#include <time.h>
47 47
48/* QT */ 48/* QT */
49#include <qevent.h> 49#include <qevent.h>
50#include <qfile.h>
50#include <qhostaddress.h> 51#include <qhostaddress.h>
51#include <qobject.h> 52#include <qobject.h>
52#include <qstring.h> 53#include <qstring.h>
53#include <qmap.h> 54#include <qmap.h>
54 55
55/* OPIE */ 56/* OPIE */
56#include <opie2/onetutils.h> 57#include <opie2/onetutils.h>
57#include "802_11_user.h" 58#include "802_11_user.h"
58 59
59/* TYPEDEFS */ 60/* TYPEDEFS */
60typedef struct timeval timevalstruct; 61typedef struct timeval timevalstruct;
61typedef struct pcap_pkthdr packetheaderstruct; 62typedef struct pcap_pkthdr packetheaderstruct;
62 63
63/* FORWARDS */ 64/* FORWARDS */
64class OPacketCapturer; 65class OPacketCapturer;
65class QSocketNotifier; 66class QSocketNotifier;
66 67
67/*====================================================================================== 68/*======================================================================================
68 * OPacket - A frame on the wire 69 * OPacket - A frame on the wire
69 *======================================================================================*/ 70 *======================================================================================*/
70 71
71class OPacket : public QObject 72class OPacket : public QObject
72{ 73{
73 Q_OBJECT 74 Q_OBJECT
@@ -399,61 +400,106 @@ class OUDPPacket : public QObject
399/*====================================================================================== 400/*======================================================================================
400 * OTCPPacket 401 * OTCPPacket
401 *======================================================================================*/ 402 *======================================================================================*/
402 403
403class OTCPPacket : public QObject 404class OTCPPacket : public QObject
404{ 405{
405 Q_OBJECT 406 Q_OBJECT
406 407
407 public: 408 public:
408 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); 409 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 );
409 virtual ~OTCPPacket(); 410 virtual ~OTCPPacket();
410 411
411 int fromPort() const; 412 int fromPort() const;
412 int toPort() const; 413 int toPort() const;
413 414
414 private: 415 private:
415 const struct tcphdr* _tcphdr; 416 const struct tcphdr* _tcphdr;
416}; 417};
417 418
418 419
419/*====================================================================================== 420/*======================================================================================
420 * OPacketCapturer 421 * OPacketCapturer
421 *======================================================================================*/ 422 *======================================================================================*/
422 423
424/**
425 * @brief A class based wrapper for network packet capturing.
426 *
427 * This class is the base of a high-level interface to the well known packet capturing
428 * library libpcap. ...
429 */
423class OPacketCapturer : public QObject 430class OPacketCapturer : public QObject
424{ 431{
425 Q_OBJECT 432 Q_OBJECT
426 433
427 public: 434 public:
435 /**
436 * Constructor.
437 */
428 OPacketCapturer( QObject* parent = 0, const char* name = 0 ); 438 OPacketCapturer( QObject* parent = 0, const char* name = 0 );
439 /**
440 * Destructor.
441 */
429 ~OPacketCapturer(); 442 ~OPacketCapturer();
430 443 /**
444 * Setting the packet capturer to use blocking IO calls can be useful when
445 * not using the socket notifier, e.g. without an application object.
446 */
431 void setBlocking( bool ); 447 void setBlocking( bool );
448 /**
449 * @returns true if the packet capturer uses blocking IO calls.
450 */
432 bool blocking() const; 451 bool blocking() const;
433 452 /**
453 * Closes the packet capturer. This is automatically done in the destructor.
454 */
434 void close(); 455 void close();
456 /**
457 * @returns the data link type.
458 * @see <pcap.h> for possible values.
459 */
435 int dataLink() const; 460 int dataLink() const;
461 /**
462 * @returns the filedescriptor of the packet capturer. This is only useful, if
463 * not using the socket notifier, e.g. without an application object.
464 */
436 int fileno() const; 465 int fileno() const;
466 /**
467 * @returns the next @ref OPacket from the packet capturer.
468 * @note If blocking mode is true then this call might block.
469 */
437 OPacket* next(); 470 OPacket* next();
438 bool open( const QString& name ); 471 /**
472 * Open the packet capturer to capture packets in live-mode from @a interface.
473 */
474 bool open( const QString& interface );
475 /**
476 * Open the packet capturer to capture packets in offline-mode from @a file.
477 */
478 bool open( const QFile& file );
479 /**
480 * @returns true if the packet capturer is open
481 */
439 bool isOpen() const; 482 bool isOpen() const;
440 483
441 const QMap<QString,int>& statistics() const; 484 const QMap<QString,int>& statistics() const;
442 485
443 signals: 486 signals:
487 /**
488 * This signal is emitted, when a packet has been received.
489 */
444 void receivedPacket( OPacket* ); 490 void receivedPacket( OPacket* );
445 491
446 protected slots: 492 protected slots:
447 void readyToReceive(); 493 void readyToReceive();
448 494
449 protected: 495 protected:
450 QString _name; // devicename 496 QString _name; // devicename
451 bool _open; // check this before doing pcap calls 497 bool _open; // check this before doing pcap calls
452 pcap_t* _pch; // pcap library handle 498 pcap_t* _pch; // pcap library handle
453 QSocketNotifier* _sn; // socket notifier for main loop 499 QSocketNotifier* _sn; // socket notifier for main loop
454 mutable char _errbuf[PCAP_ERRBUF_SIZE]; 500 mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap
455 QMap<QString, int> _stats; // statistics; 501 QMap<QString, int> _stats; // statistics;
456}; 502};
457 503
458#endif // OPCAP_H 504#endif // OPCAP_H
459 505