summaryrefslogtreecommitdiff
path: root/libopie2/opienet
Unidiff
Diffstat (limited to 'libopie2/opienet') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opienet/omanufacturerdb.cpp22
-rw-r--r--libopie2/opienet/omanufacturerdb.h18
-rw-r--r--libopie2/opienet/onetutils.cpp3
3 files changed, 39 insertions, 4 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()
60 QTextStream s( &file ); 60 QTextStream s( &file );
61 QString addr; 61 QString addr;
62 QString manu; 62 QString manu;
63 QString extManu;
63 while (!s.atEnd()) 64 while (!s.atEnd())
64 { 65 {
65 s >> addr; 66 s >> addr;
@@ -70,13 +71,22 @@ OManufacturerDB::OManufacturerDB()
70 else 71 else
71 if ( addr[0] == '#' ) 72 if ( addr[0] == '#' )
72 { 73 {
73 s.readLine();
74 continue; 74 continue;
75 } 75 }
76 s.skipWhiteSpace(); 76 s.skipWhiteSpace();
77 s >> manu; 77 s >> manu;
78 s.skipWhiteSpace();
79 s >> extManu;
80 if ( extManu[0] == '#' ) // we have an extended manufacturer
81 {
82 s.skipWhiteSpace();
83 extManu = s.readLine();
84 qDebug( "OManufacturerDB: read '%s' as extended manufacturer string", (const char*) extManu );
85 manufacturersExt.insert( addr, extManu );
86 }
87 else
78 s.readLine(); 88 s.readLine();
79 //qDebug( "ManufacturerDB: read pair %s, %s", (const char*) addr, (const char*) manu ); 89 qDebug( "ManufacturerDB: read tuple %s, %s", (const char*) addr, (const char*) manu );
80 manufacturers.insert( addr, manu ); 90 manufacturers.insert( addr, manu );
81 91
82 } 92 }
@@ -94,3 +104,11 @@ const QString& OManufacturerDB::lookup( const QString& macaddr ) const
94{ 104{
95 return manufacturers[macaddr.upper().left(8)]; 105 return manufacturers[macaddr.upper().left(8)];
96} 106}
107
108
109const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const
110{
111 QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) );
112 return it == manufacturersExt.end() ? lookup( macaddr ) : *it;
113}
114
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 @@
18 18
19#include <qmap.h> 19#include <qmap.h>
20 20
21/**
22 * @brief A Ethernet card vendor database.
23 *
24 * This class encapsulates the lookup of Ethernet vendor given a
25 * certain Mac Address. Only the first three bytes define the vendor.
26 */
21class OManufacturerDB 27class OManufacturerDB
22{ 28{
23 public: 29 public:
24 //FIXME make us consistent -zecke I use self(), sandman inst() you use instance() so we need to chose one! 30 /**
31 * @returns the one-and-only @ref OManufacturerDB instance.
32 */
25 static OManufacturerDB* instance(); 33 static OManufacturerDB* instance();
34 /**
35 * @returns the short manufacturer string given a @a macaddr.
36 */
26 const QString& lookup( const QString& macaddr ) const; 37 const QString& lookup( const QString& macaddr ) const;
38 /**
39 * @returns the enhanced manufacturer string given a @a macaddr.
40 */
41 const QString& lookupExt( const QString& macaddr ) const;
27 42
28 protected: 43 protected:
29 OManufacturerDB(); 44 OManufacturerDB();
@@ -31,6 +46,7 @@ class OManufacturerDB
31 46
32 private: 47 private:
33 QMap<QString, QString> manufacturers; 48 QMap<QString, QString> manufacturers;
49 QMap<QString, QString> manufacturersExt;
34 static OManufacturerDB* _instance; 50 static OManufacturerDB* _instance;
35}; 51};
36 52
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
@@ -125,9 +125,10 @@ QString OMacAddress::toString( bool substitute ) const
125 125
126QString OMacAddress::manufacturer() const 126QString OMacAddress::manufacturer() const
127{ 127{
128 return OManufacturerDB::instance()->lookup( toString() ); 128 return OManufacturerDB::instance()->lookupExt( toString() );
129} 129}
130 130
131
131bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) 132bool operator==( const OMacAddress &m1, const OMacAddress &m2 )
132{ 133{
133 return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; 134 return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0;