-rw-r--r-- | libopie2/opienet/onetutils.cpp | 7 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.h | 1 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 27 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 5 |
4 files changed, 38 insertions, 2 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp index 08c40b4..ad0e89d 100644 --- a/libopie2/opienet/onetutils.cpp +++ b/libopie2/opienet/onetutils.cpp @@ -37,50 +37,55 @@ #include <cstdio> using namespace std; #define IW_PRIV_TYPE_MASK 0x7000 #define IW_PRIV_TYPE_NONE 0x0000 #define IW_PRIV_TYPE_BYTE 0x1000 #define IW_PRIV_TYPE_CHAR 0x2000 #define IW_PRIV_TYPE_INT 0x4000 #define IW_PRIV_TYPE_FLOAT 0x5000 #define IW_PRIV_TYPE_ADDR 0x6000 #define IW_PRIV_SIZE_FIXED 0x0800 #define IW_PRIV_SIZE_MASK 0x07FF /*====================================================================================== * OMacAddress *======================================================================================*/ // static initializer for broadcast and unknown MAC Adresses const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); +//TODO: Incorporate Ethernet Manufacturer database here! (inline or so) + +OMacAddress::OMacAddress() +{ + memcpy( _bytes, __unknown, 6 ); +} -//TODO: Incorporate Ethernet Manufacturer database here! OMacAddress::OMacAddress( unsigned char* p ) { memcpy( _bytes, p, 6 ); } OMacAddress::OMacAddress( const unsigned char* p ) { memcpy( _bytes, p, 6 ); } OMacAddress::OMacAddress( struct ifreq& ifr ) { memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); } OMacAddress::~OMacAddress() { } diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h index 9611518..18731ba 100644 --- a/libopie2/opienet/onetutils.h +++ b/libopie2/opienet/onetutils.h @@ -30,48 +30,49 @@ */ #ifndef ONETUTILS_H #define ONETUTILS_H #include <qdict.h> #include <qmap.h> #include <qstring.h> #include <qhostaddress.h> #include <qobject.h> #include <sys/types.h> struct ifreq; class OWirelessNetworkInterface; /*====================================================================================== * OMacAddress *======================================================================================*/ class OMacAddress { public: // QString c'tor? -zecke + OMacAddress(); OMacAddress( unsigned char* ); OMacAddress( const unsigned char* ); OMacAddress( struct ifreq& ); ~OMacAddress(); QString manufacturer() const; QString toString( bool substitute = false ) const; const unsigned char* native() const; // no c'tor but this one why not make it a c'tor. it could also replace the others or is this the problem? static OMacAddress fromString( const QString& ); public: static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff static const OMacAddress& unknown; // 44:44:44:44:44:44 private: unsigned char _bytes[6]; friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); }; bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 7a6f61b..313f5bb 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp @@ -87,48 +87,71 @@ 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(); } } +void OPacket::dumpStructure( QObjectList* l ) +{ + QString packetString( "[ |" + _dumpStructure( l ) + " ]" ); + qDebug( "OPacket::dumpStructure: %s", (const char*) packetString ); +} + + +QString OPacket::_dumpStructure( QObjectList* l ) +{ + 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; str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); str.append( "0000: " ); 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' ); @@ -1095,49 +1118,51 @@ int OPacketCapturer::fileno() const return pcap_fileno( _pch ); } else { return -1; } } OPacket* OPacketCapturer::next() { packetheaderstruct header; qDebug( "==> OPacketCapturer::next()" ); const unsigned char* pdata = pcap_next( _pch, &header ); qDebug( "<== OPacketCapturer::next()" ); if ( pdata && header.len ) { OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); // packets shouldn't be inserted in the QObject child-parent hierarchy, // because due to memory constraints they will be deleted as soon // as possible - that is right after they have been processed // by emit() [ see below ] //TODO: make gathering statistics optional, because it takes time p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); - + #ifndef NODEBUG + p->dumpStructure( const_cast<QObjectList*>( p->children() ) ); + #endif return p; } else { qWarning( "OPacketCapturer::next() - no packet received!" ); return 0; } } bool OPacketCapturer::open( const QString& name ) { if ( _open ) { if ( name == _name ) // ignore opening an already openend device { return true; } else // close the last opened device { close(); } } diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index a031dd1..f0d1d81 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h @@ -112,48 +112,53 @@ class QSocketNotifier; * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl; * */ class OPacket : public QObject { Q_OBJECT friend class OPacketCapturer; public: OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); virtual ~OPacket(); timevalstruct timeval() const; int caplen() const; int len() const; QString dump( int = 32 ) const; void updateStats( QMap<QString,int>&, QObjectList* ); private: + + void dumpStructure( QObjectList* ); + QString _dumpStructure( QObjectList* ); + + private: const packetheaderstruct _hdr; // pcap packet header const unsigned char* _data; // pcap packet data const unsigned char* _end; // end of pcap packet data }; /*====================================================================================== * OEthernetPacket - DLT_EN10MB frame *======================================================================================*/ class OEthernetPacket : public QObject { Q_OBJECT public: OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); virtual ~OEthernetPacket(); OMacAddress sourceAddress() const; OMacAddress destinationAddress() const; int type() const; private: const struct ether_header* _ether; }; |