-rw-r--r-- | libopie2/opienet/omanufacturerdb.cpp | 96 | ||||
-rw-r--r-- | libopie2/opienet/omanufacturerdb.h | 37 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.cpp | 21 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.h | 3 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 8 | ||||
-rw-r--r-- | libopie2/opienet/opienet.pro | 12 |
6 files changed, 162 insertions, 15 deletions
diff --git a/libopie2/opienet/omanufacturerdb.cpp b/libopie2/opienet/omanufacturerdb.cpp new file mode 100644 index 0000000..ea15125 --- a/dev/null +++ b/libopie2/opienet/omanufacturerdb.cpp | |||
@@ -0,0 +1,96 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Opie Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | **********************************************************************/ | ||
15 | |||
16 | #include "omanufacturerdb.h" | ||
17 | |||
18 | // Qt | ||
19 | #include <qstring.h> | ||
20 | #include <qfile.h> | ||
21 | #include <qtextstream.h> | ||
22 | |||
23 | OManufacturerDB* OManufacturerDB::_instance = 0; | ||
24 | |||
25 | OManufacturerDB* OManufacturerDB::instance() | ||
26 | { | ||
27 | if ( !OManufacturerDB::_instance ) | ||
28 | { | ||
29 | qDebug( "OManufacturerDB::instance(): creating OManufacturerDB..." ); | ||
30 | _instance = new OManufacturerDB(); | ||
31 | } | ||
32 | return _instance; | ||
33 | } | ||
34 | |||
35 | |||
36 | OManufacturerDB::OManufacturerDB() | ||
37 | { | ||
38 | QString filename( "/etc/manufacturers" ); | ||
39 | qDebug( "OManufacturerDB: trying to read '%s'...", (const char*) filename ); | ||
40 | if ( !QFile::exists( filename ) ) | ||
41 | { | ||
42 | filename = "/opt/QtPalmtop/etc/manufacturers"; | ||
43 | qDebug( "OManufacturerDB: trying to read '%s'...", (const char*) filename ); | ||
44 | if ( !QFile::exists( filename ) ) | ||
45 | { | ||
46 | filename = "/usr/share/wellenreiter/manufacturers"; | ||
47 | qDebug( "OManufacturerDB: trying to read '%s'...", (const char*) filename ); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | QFile file( filename ); | ||
52 | bool hasFile = file.open( IO_ReadOnly ); | ||
53 | if (!hasFile) | ||
54 | { | ||
55 | qWarning( "OManufacturerDB: no valid manufacturer list found.", (const char*) filename ); | ||
56 | } | ||
57 | else | ||
58 | { | ||
59 | qDebug( "OManufacturerDB: found manufacturer list in '%s'...", (const char*) filename ); | ||
60 | QTextStream s( &file ); | ||
61 | QString addr; | ||
62 | QString manu; | ||
63 | while (!s.atEnd()) | ||
64 | { | ||
65 | s >> addr; | ||
66 | if ( !addr ) // read nothing!? | ||
67 | { | ||
68 | continue; | ||
69 | } | ||
70 | else | ||
71 | if ( addr[0] == '#' ) | ||
72 | { | ||
73 | s.readLine(); | ||
74 | continue; | ||
75 | } | ||
76 | s.skipWhiteSpace(); | ||
77 | s >> manu; | ||
78 | s.readLine(); | ||
79 | //qDebug( "ManufacturerDB: read pair %s, %s", (const char*) addr, (const char*) manu ); | ||
80 | manufacturers.insert( addr, manu ); | ||
81 | |||
82 | } | ||
83 | } | ||
84 | |||
85 | } | ||
86 | |||
87 | |||
88 | OManufacturerDB::~OManufacturerDB() | ||
89 | { | ||
90 | } | ||
91 | |||
92 | |||
93 | const QString& OManufacturerDB::lookup( const QString& macaddr ) const | ||
94 | { | ||
95 | return manufacturers[macaddr.upper().left(8)]; | ||
96 | } | ||
diff --git a/libopie2/opienet/omanufacturerdb.h b/libopie2/opienet/omanufacturerdb.h new file mode 100644 index 0000000..5e66c37 --- a/dev/null +++ b/libopie2/opienet/omanufacturerdb.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Opie Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | **********************************************************************/ | ||
15 | |||
16 | #ifndef OMANUFACTURERDB_H | ||
17 | #define OMANUFACTURERDB_H | ||
18 | |||
19 | #include <qmap.h> | ||
20 | |||
21 | class OManufacturerDB | ||
22 | { | ||
23 | public: | ||
24 | static OManufacturerDB* instance(); | ||
25 | const QString& lookup( const QString& macaddr ) const; | ||
26 | |||
27 | protected: | ||
28 | OManufacturerDB(); | ||
29 | virtual ~OManufacturerDB(); | ||
30 | |||
31 | private: | ||
32 | QMap<QString, QString> manufacturers; | ||
33 | static OManufacturerDB* _instance; | ||
34 | }; | ||
35 | |||
36 | #endif | ||
37 | |||
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp index 2485f30..236f108 100644 --- a/libopie2/opienet/onetutils.cpp +++ b/libopie2/opienet/onetutils.cpp | |||
@@ -32,4 +32,5 @@ | |||
32 | #include <opie2/onetutils.h> | 32 | #include <opie2/onetutils.h> |
33 | #include <opie2/onetwork.h> | 33 | #include <opie2/onetwork.h> |
34 | #include <opie2/omanufacturerdb.h> | ||
34 | 35 | ||
35 | #include <net/if.h> | 36 | #include <net/if.h> |
@@ -110,14 +111,22 @@ OMacAddress OMacAddress::fromString( const QString& str ) | |||
110 | 111 | ||
111 | 112 | ||
112 | QString OMacAddress::toString() const | 113 | QString OMacAddress::toString( bool substitute ) const |
113 | { | 114 | { |
114 | QString s; | 115 | QString manu; |
115 | s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 116 | manu.sprintf( "%.2X:%.2X:%.2X", _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff ); |
116 | _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff, | 117 | QString serial; |
117 | _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); | 118 | serial.sprintf( ":%.2X:%.2X:%.2X", _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); |
118 | return s; | 119 | if ( !substitute ) return manu+serial; |
120 | // fallback - if no vendor is found, just use the number | ||
121 | QString textmanu = OManufacturerDB::instance()->lookup( manu ); | ||
122 | return textmanu.isNull() ? manu+serial : textmanu + serial; | ||
119 | } | 123 | } |
120 | 124 | ||
121 | 125 | ||
126 | QString OMacAddress::manufacturer() const | ||
127 | { | ||
128 | return OManufacturerDB::instance()->lookup( toString() ); | ||
129 | } | ||
130 | |||
122 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) | 131 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) |
123 | { | 132 | { |
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h index 73d52cc..bedea63 100644 --- a/libopie2/opienet/onetutils.h +++ b/libopie2/opienet/onetutils.h | |||
@@ -56,5 +56,6 @@ class OMacAddress | |||
56 | ~OMacAddress(); | 56 | ~OMacAddress(); |
57 | 57 | ||
58 | QString toString() const; | 58 | QString manufacturer() const; |
59 | QString toString( bool substitute = false ) const; | ||
59 | const unsigned char* native() const; | 60 | const unsigned char* native() const; |
60 | 61 | ||
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 6ddd457..40aac2c 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -640,9 +640,9 @@ OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct i | |||
640 | :QObject( parent, "802.11 Data" ), _header( data ) | 640 | :QObject( parent, "802.11 Data" ), _header( data ) |
641 | { | 641 | { |
642 | //qDebug( "size of header = %d", sizeof( struct ieee_802_11_data_header ) ); | 642 | qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); |
643 | //qDebug( "header: %0x", data ); | 643 | |
644 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); | 644 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); |
645 | //qDebug( "payload: %0x", payload ); | ||
646 | 645 | ||
646 | #warning The next line works for most cases, but can not be correct generally! | ||
647 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | 647 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address |
648 | 648 | ||
@@ -661,5 +661,5 @@ OWaveLanDataPacket::~OWaveLanDataPacket() | |||
661 | 661 | ||
662 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) | 662 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) |
663 | :QObject( parent, "802.11 802_2" ), _header( data ) | 663 | :QObject( parent, "802.11 LLC" ), _header( data ) |
664 | { | 664 | { |
665 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); | 665 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); |
diff --git a/libopie2/opienet/opienet.pro b/libopie2/opienet/opienet.pro index e73afbf..3f9166a 100644 --- a/libopie2/opienet/opienet.pro +++ b/libopie2/opienet/opienet.pro | |||
@@ -2,7 +2,12 @@ TEMPLATE = lib | |||
2 | CONFIG += qt warn_on debug | 2 | CONFIG += qt warn_on debug |
3 | DESTDIR = $(OPIEDIR)/lib | 3 | DESTDIR = $(OPIEDIR)/lib |
4 | HEADERS = onetutils.cpp onetwork.h opcap.h | 4 | HEADERS = omanufacturerdb.cpp \ |
5 | 5 | onetutils.cpp \ | |
6 | SOURCES = onetutils.cpp onetwork.cpp opcap.cpp | 6 | onetwork.h \ |
7 | opcap.h | ||
8 | SOURCES = omanufacturerdb.cpp \ | ||
9 | onetutils.cpp \ | ||
10 | onetwork.cpp \ | ||
11 | opcap.cpp | ||
7 | INTERFACES = | 12 | INTERFACES = |
8 | TARGET = opienet2 | 13 | TARGET = opienet2 |
@@ -11,5 +16,4 @@ INCLUDEPATH += $(OPIEDIR)/include | |||
11 | DEPENDPATH += $(OPIEDIR)/include | 16 | DEPENDPATH += $(OPIEDIR)/include |
12 | LIBS += -lpcap | 17 | LIBS += -lpcap |
13 | |||
14 | MOC_DIR = moc | 18 | MOC_DIR = moc |
15 | OBJECTS_DIR = obj | 19 | OBJECTS_DIR = obj |