-rw-r--r-- | libopie2/opienet/opcap.h | 64 |
1 files changed, 55 insertions, 9 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 | |||
@@ -38,24 +38,25 @@ | |||
38 | extern "C" // work around a bpf/pcap conflict in recent headers | 38 | extern "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 */ |
60 | typedef struct timeval timevalstruct; | 61 | typedef struct timeval timevalstruct; |
61 | typedef struct pcap_pkthdr packetheaderstruct; | 62 | typedef struct pcap_pkthdr packetheaderstruct; |
@@ -411,49 +412,94 @@ class OTCPPacket : public QObject | |||
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 | */ | ||
423 | class OPacketCapturer : public QObject | 430 | class 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 | ||