Diffstat (limited to 'libopie2/opienet/onetutils.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opienet/onetutils.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp new file mode 100644 index 0000000..8006f41 --- a/dev/null +++ b/libopie2/opienet/onetutils.cpp | |||
@@ -0,0 +1,101 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | |||
4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
5 | =. | ||
6 | .=l. | ||
7 | .>+-= | ||
8 | _;:, .> :=|. This program is free software; you can | ||
9 | .> <`_, > . <= redistribute it and/or modify it under | ||
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
11 | .="- .-=="i, .._ License as published by the Free Software | ||
12 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
13 | ._= =} : or (at your option) any later version. | ||
14 | .%`+i> _;_. | ||
15 | .i_,=:_. -<s. This program is distributed in the hope that | ||
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
17 | : .. .:, . . . without even the implied warranty of | ||
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
20 | ..}^=.= = ; Library General Public License for more | ||
21 | ++= -. .` .: details. | ||
22 | : = ...= . :.=- | ||
23 | -. .:....=;==+<; You should have received a copy of the GNU | ||
24 | -_. . . )=. = Library General Public License along with | ||
25 | -- :-=` this library; see the file COPYING.LIB. | ||
26 | If not, write to the Free Software Foundation, | ||
27 | Inc., 59 Temple Place - Suite 330, | ||
28 | Boston, MA 02111-1307, USA. | ||
29 | |||
30 | */ | ||
31 | |||
32 | #include <opie2/onetutils.h> | ||
33 | |||
34 | #include <net/if.h> | ||
35 | |||
36 | #include <cstdio> | ||
37 | using namespace std; | ||
38 | |||
39 | /*====================================================================================== | ||
40 | * OMacAddress | ||
41 | *======================================================================================*/ | ||
42 | |||
43 | // static initializer for broadcast and unknown MAC Adresses | ||
44 | const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | ||
45 | const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); | ||
46 | const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; | ||
47 | const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); | ||
48 | |||
49 | |||
50 | //TODO: Incorporate Ethernet Manufacturer database here! | ||
51 | |||
52 | OMacAddress::OMacAddress( unsigned char* p ) | ||
53 | { | ||
54 | memcpy( _bytes, p, 6 ); // D'OH! memcpy in my sources... eeek... | ||
55 | } | ||
56 | |||
57 | |||
58 | OMacAddress::OMacAddress( const unsigned char* p ) | ||
59 | { | ||
60 | memcpy( _bytes, p, 6 ); | ||
61 | } | ||
62 | |||
63 | |||
64 | OMacAddress::OMacAddress( struct ifreq& ifr ) | ||
65 | { | ||
66 | memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); | ||
67 | } | ||
68 | |||
69 | |||
70 | OMacAddress::~OMacAddress() | ||
71 | { | ||
72 | } | ||
73 | |||
74 | |||
75 | QString OMacAddress::toString() const | ||
76 | { | ||
77 | QString s; | ||
78 | s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | ||
79 | _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff, | ||
80 | _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); | ||
81 | return s; | ||
82 | } | ||
83 | |||
84 | |||
85 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) | ||
86 | { | ||
87 | return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; | ||
88 | } | ||
89 | |||
90 | void dumpBytes( const unsigned char* data, int num ) | ||
91 | { | ||
92 | printf( "Dumping %d bytes @ %0x", num, data ); | ||
93 | printf( "-------------------------------------------\n" ); | ||
94 | |||
95 | for ( int i = 0; i < num; ++i ) | ||
96 | { | ||
97 | printf( "%02x ", data[i] ); | ||
98 | if ( !((i+1) % 32) ) printf( "\n" ); | ||
99 | } | ||
100 | printf( "\n\n" ); | ||
101 | } | ||