Diffstat (limited to 'libopie2/opienet/onetutils.cpp') (more/less context) (show 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 ); //TODO: Incorporate Ethernet Manufacturer database here! OMacAddress::OMacAddress( unsigned char* p ) { - memcpy( _bytes, p, 6 ); // D'OH! memcpy in my sources... eeek... + memcpy( _bytes, p, 6 ); } OMacAddress::OMacAddress( const unsigned char* p ) { memcpy( _bytes, p, 6 ); @@ -80,12 +80,38 @@ OMacAddress::OMacAddress( struct ifreq& ifr ) OMacAddress::~OMacAddress() { } +#ifdef QT_NO_DEBUG +inline +#endif +const unsigned char* OMacAddress::native() const +{ + return (const unsigned char*) &_bytes; +} + + +OMacAddress OMacAddress::fromString( const QString& str ) +{ + QString addr( str ); + unsigned char buf[6]; + bool ok = true; + int index = 14; + for ( int i = 5; i >= 0; --i ) + { + buf[i] = addr.right( 2 ).toUShort( &ok, 16 ); + if ( !ok ) return OMacAddress::unknown; + addr.truncate( index ); + index -= 3; + } + return (const unsigned char*) &buf; +} + + QString OMacAddress::toString() const { QString s; s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff, _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); |