1 #ifndef NUT_COMMON_MACADDRESS_H
2 #define NUT_COMMON_MACADDRESS_H
5 #include <QDBusArgument>
8 #include <net/ethernet.h>
10 namespace libnutcommon
{
13 QDBusArgument
&operator<< (QDBusArgument
&argument
, const MacAddress
&data
);
14 const QDBusArgument
&operator>> (const QDBusArgument
&argument
, MacAddress
&data
);
17 namespace libnutcommon
{
19 @author Stefan Bühler <stbuehler@web.de>
23 MacAddress() { clear(); }
24 MacAddress(const QString
&str
);
25 MacAddress(const quint8
*d
);
26 MacAddress(const ether_addr
* eth
);
29 inline bool operator==(const MacAddress
&ma
) const {
30 for (int i
= 0; i
< 6; i
++)
31 if (data
[i
] != ma
.data
[i
])
35 inline bool operator!=(const MacAddress
&ma
) const {
36 return !(*this == ma
);
38 inline bool operator<(const MacAddress
&b
) {
39 if ( *((quint32
*)data
) < *((quint32
*)b
.data
) ) {
42 else if ( *((quint32
*)data
) == *((quint32
*)b
.data
) ) { //First is equal
43 return ( (*((quint16
*)(data
+4))) < *((quint16
*)((b
.data
)+4)) );
49 inline QString
toString() const {
50 char buf
[sizeof("00:00:00:00:00:00")];
51 sprintf(buf
, "%02X:%02X:%02X:%02X:%02X:%02X",
52 data
[0],data
[1],data
[2],data
[3],data
[4],data
[5]);
56 inline bool zero() const {
57 return *((quint32
*)data
) == 0 && *((quint16
*)(data
+4)) == 0;
60 inline bool valid() const {
65 *((quint32
*)data
) = 0;
66 *((quint16
*)(data
+4)) = 0;
71 static inline uint
qHash(const libnutcommon::MacAddress
&key
) {
72 quint8 data
[8] = { key
.data
[0], key
.data
[2], key
.data
[3], key
.data
[4], key
.data
[5], key
.data
[6], 0, 0};
73 return qHash(*((quint64
*)data
));
76 Q_DECLARE_METATYPE(libnutcommon::MacAddress
)