-rw-r--r-- | libopie2/opienet/omanufacturerdb.cpp | 24 | ||||
-rw-r--r-- | libopie2/opienet/omanufacturerdb.h | 18 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.cpp | 5 |
3 files changed, 41 insertions, 6 deletions
diff --git a/libopie2/opienet/omanufacturerdb.cpp b/libopie2/opienet/omanufacturerdb.cpp index ea15125..c185fc5 100644 --- a/libopie2/opienet/omanufacturerdb.cpp +++ b/libopie2/opienet/omanufacturerdb.cpp @@ -60,6 +60,7 @@ OManufacturerDB::OManufacturerDB() QTextStream s( &file ); QString addr; QString manu; + QString extManu; while (!s.atEnd()) { s >> addr; @@ -70,13 +71,22 @@ OManufacturerDB::OManufacturerDB() else if ( addr[0] == '#' ) { - s.readLine(); continue; } s.skipWhiteSpace(); s >> manu; - s.readLine(); - //qDebug( "ManufacturerDB: read pair %s, %s", (const char*) addr, (const char*) manu ); + s.skipWhiteSpace(); + s >> extManu; + if ( extManu[0] == '#' ) // we have an extended manufacturer + { + s.skipWhiteSpace(); + extManu = s.readLine(); + qDebug( "OManufacturerDB: read '%s' as extended manufacturer string", (const char*) extManu ); + manufacturersExt.insert( addr, extManu ); + } + else + s.readLine(); + qDebug( "ManufacturerDB: read tuple %s, %s", (const char*) addr, (const char*) manu ); manufacturers.insert( addr, manu ); } @@ -94,3 +104,11 @@ const QString& OManufacturerDB::lookup( const QString& macaddr ) const { return manufacturers[macaddr.upper().left(8)]; } + + +const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const +{ + QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) ); + return it == manufacturersExt.end() ? lookup( macaddr ) : *it; +} + diff --git a/libopie2/opienet/omanufacturerdb.h b/libopie2/opienet/omanufacturerdb.h index cb0b6c8..651f624 100644 --- a/libopie2/opienet/omanufacturerdb.h +++ b/libopie2/opienet/omanufacturerdb.h @@ -18,12 +18,27 @@ #include <qmap.h> +/** + * @brief A Ethernet card vendor database. + * + * This class encapsulates the lookup of Ethernet vendor given a + * certain Mac Address. Only the first three bytes define the vendor. + */ class OManufacturerDB { public: - //FIXME make us consistent -zecke I use self(), sandman inst() you use instance() so we need to chose one! + /** + * @returns the one-and-only @ref OManufacturerDB instance. + */ static OManufacturerDB* instance(); + /** + * @returns the short manufacturer string given a @a macaddr. + */ const QString& lookup( const QString& macaddr ) const; + /** + * @returns the enhanced manufacturer string given a @a macaddr. + */ + const QString& lookupExt( const QString& macaddr ) const; protected: OManufacturerDB(); @@ -31,6 +46,7 @@ class OManufacturerDB private: QMap<QString, QString> manufacturers; + QMap<QString, QString> manufacturersExt; static OManufacturerDB* _instance; }; diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp index e05efc2..08c40b4 100644 --- a/libopie2/opienet/onetutils.cpp +++ b/libopie2/opienet/onetutils.cpp @@ -119,15 +119,16 @@ QString OMacAddress::toString( bool substitute ) const if ( !substitute ) return manu+serial; // fallback - if no vendor is found, just use the number QString textmanu = OManufacturerDB::instance()->lookup( manu ); - return textmanu.isNull() ? manu+serial : textmanu + serial; + return textmanu.isNull() ? manu+serial : textmanu+serial; } QString OMacAddress::manufacturer() const { - return OManufacturerDB::instance()->lookup( toString() ); + return OManufacturerDB::instance()->lookupExt( toString() ); } + bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) { return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; |