Diffstat (limited to 'libopie2/opienet/onetutils.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opienet/onetutils.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp index b317810..0fb21ff 100644 --- a/libopie2/opienet/onetutils.cpp +++ b/libopie2/opienet/onetutils.cpp | |||
@@ -59,13 +59,13 @@ const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); | |||
59 | 59 | ||
60 | 60 | ||
61 | //TODO: Incorporate Ethernet Manufacturer database here! | 61 | //TODO: Incorporate Ethernet Manufacturer database here! |
62 | 62 | ||
63 | OMacAddress::OMacAddress( unsigned char* p ) | 63 | OMacAddress::OMacAddress( unsigned char* p ) |
64 | { | 64 | { |
65 | memcpy( _bytes, p, 6 ); // D'OH! memcpy in my sources... eeek... | 65 | memcpy( _bytes, p, 6 ); |
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
69 | OMacAddress::OMacAddress( const unsigned char* p ) | 69 | OMacAddress::OMacAddress( const unsigned char* p ) |
70 | { | 70 | { |
71 | memcpy( _bytes, p, 6 ); | 71 | memcpy( _bytes, p, 6 ); |
@@ -80,12 +80,38 @@ OMacAddress::OMacAddress( struct ifreq& ifr ) | |||
80 | 80 | ||
81 | OMacAddress::~OMacAddress() | 81 | OMacAddress::~OMacAddress() |
82 | { | 82 | { |
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
86 | #ifdef QT_NO_DEBUG | ||
87 | inline | ||
88 | #endif | ||
89 | const unsigned char* OMacAddress::native() const | ||
90 | { | ||
91 | return (const unsigned char*) &_bytes; | ||
92 | } | ||
93 | |||
94 | |||
95 | OMacAddress OMacAddress::fromString( const QString& str ) | ||
96 | { | ||
97 | QString addr( str ); | ||
98 | unsigned char buf[6]; | ||
99 | bool ok = true; | ||
100 | int index = 14; | ||
101 | for ( int i = 5; i >= 0; --i ) | ||
102 | { | ||
103 | buf[i] = addr.right( 2 ).toUShort( &ok, 16 ); | ||
104 | if ( !ok ) return OMacAddress::unknown; | ||
105 | addr.truncate( index ); | ||
106 | index -= 3; | ||
107 | } | ||
108 | return (const unsigned char*) &buf; | ||
109 | } | ||
110 | |||
111 | |||
86 | QString OMacAddress::toString() const | 112 | QString OMacAddress::toString() const |
87 | { | 113 | { |
88 | QString s; | 114 | QString s; |
89 | s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 115 | s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
90 | _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff, | 116 | _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff, |
91 | _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); | 117 | _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); |