Diffstat (limited to 'libopie2/opienet/onetutils.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opienet/onetutils.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
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 | |||
@@ -22,24 +22,25 @@ | |||
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | 29 | ||
30 | */ | 30 | */ |
31 | 31 | ||
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> |
36 | 37 | ||
37 | #include <cstdio> | 38 | #include <cstdio> |
38 | using namespace std; | 39 | using namespace std; |
39 | 40 | ||
40 | #define IW_PRIV_TYPE_MASK 0x7000 | 41 | #define IW_PRIV_TYPE_MASK 0x7000 |
41 | #define IW_PRIV_TYPE_NONE 0x0000 | 42 | #define IW_PRIV_TYPE_NONE 0x0000 |
42 | #define IW_PRIV_TYPE_BYTE 0x1000 | 43 | #define IW_PRIV_TYPE_BYTE 0x1000 |
43 | #define IW_PRIV_TYPE_CHAR 0x2000 | 44 | #define IW_PRIV_TYPE_CHAR 0x2000 |
44 | #define IW_PRIV_TYPE_INT 0x4000 | 45 | #define IW_PRIV_TYPE_INT 0x4000 |
45 | #define IW_PRIV_TYPE_FLOAT 0x5000 | 46 | #define IW_PRIV_TYPE_FLOAT 0x5000 |
@@ -100,34 +101,42 @@ OMacAddress OMacAddress::fromString( const QString& str ) | |||
100 | int index = 14; | 101 | int index = 14; |
101 | for ( int i = 5; i >= 0; --i ) | 102 | for ( int i = 5; i >= 0; --i ) |
102 | { | 103 | { |
103 | buf[i] = addr.right( 2 ).toUShort( &ok, 16 ); | 104 | buf[i] = addr.right( 2 ).toUShort( &ok, 16 ); |
104 | if ( !ok ) return OMacAddress::unknown; | 105 | if ( !ok ) return OMacAddress::unknown; |
105 | addr.truncate( index ); | 106 | addr.truncate( index ); |
106 | index -= 3; | 107 | index -= 3; |
107 | } | 108 | } |
108 | return (const unsigned char*) &buf; | 109 | return (const unsigned char*) &buf; |
109 | } | 110 | } |
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 | { |
124 | return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; | 133 | return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; |
125 | } | 134 | } |
126 | 135 | ||
127 | 136 | ||
128 | /*====================================================================================== | 137 | /*====================================================================================== |
129 | * OHostAddress | 138 | * OHostAddress |
130 | *======================================================================================*/ | 139 | *======================================================================================*/ |
131 | 140 | ||
132 | 141 | ||
133 | /*====================================================================================== | 142 | /*====================================================================================== |