diff --git a/common/abstractprotocol.h b/common/abstractprotocol.h index 5206662..84388ae 100644 --- a/common/abstractprotocol.h +++ b/common/abstractprotocol.h @@ -35,9 +35,6 @@ along with this program. If not, see #define BASE_DEC (10) #define BASE_HEX (16) -#define uintToHexStr(num, bytes) \ - QString("%1").arg(num, bytes*2, BASE_HEX, QChar('0')) - class StreamBase; class ProtocolListIterator; diff --git a/common/abstractprotocolconfig.h b/common/abstractprotocolconfig.h index 4172a7c..a65c959 100644 --- a/common/abstractprotocolconfig.h +++ b/common/abstractprotocolconfig.h @@ -23,6 +23,12 @@ along with this program. If not, see class AbstractProtocol; +/*! + Convenience Macro - can be used by loadWidget() methods +*/ +#define uintToHexStr(num, bytes) \ + QString("%1").arg(num, bytes*2, BASE_HEX, QChar('0')) + class AbstractProtocolConfigForm : public QWidget { Q_OBJECT @@ -80,7 +86,7 @@ public: } /*! - Convenience Method - can be used by storeConfigWidget() implementations + Convenience Method - can be used by storeWidget() implementations */ uint hexStrToUInt(QString text, bool *ok=NULL) { @@ -94,7 +100,7 @@ public: } /*! - Convenience Method - can be used by storeConfigWidget() implementations + Convenience Method - can be used by storeWidget() implementations */ quint64 hexStrToUInt64(QString text, bool *ok=NULL) { diff --git a/common/arp.cpp b/common/arp.cpp index 11675a1..aee20ce 100644 --- a/common/arp.cpp +++ b/common/arp.cpp @@ -20,6 +20,11 @@ along with this program. If not, see #include "arp.h" #include +#include + +#define uintToMacStr(num) \ + QString("%1").arg(num, 6*2, BASE_HEX, QChar('0')) \ + .replace(QRegExp("([0-9a-fA-F]{2}\\B)"), "\\1:").toUpper() ArpProtocol::ArpProtocol(StreamBase *stream, AbstractProtocol *parent) : AbstractProtocol(stream, parent) @@ -295,7 +300,7 @@ QVariant ArpProtocol::fieldData(int index, FieldAttrib attrib, case FieldValue: return hwAddr; case FieldTextValue: - return uintToHexStr(hwAddr, 6); + return uintToMacStr(hwAddr); case FieldFrameValue: { QByteArray fv; @@ -403,7 +408,7 @@ QVariant ArpProtocol::fieldData(int index, FieldAttrib attrib, case FieldValue: return hwAddr; case FieldTextValue: - return uintToHexStr(hwAddr, 6); + return uintToMacStr(hwAddr); case FieldFrameValue: { QByteArray fv; diff --git a/common/mac.cpp b/common/mac.cpp index ec2bcc6..70d047b 100644 --- a/common/mac.cpp +++ b/common/mac.cpp @@ -19,6 +19,12 @@ along with this program. If not, see #include "mac.h" +#include + +#define uintToMacStr(num) \ + QString("%1").arg(num, 6*2, BASE_HEX, QChar('0')) \ + .replace(QRegExp("([0-9a-fA-F]{2}\\B)"), "\\1:").toUpper() + MacProtocol::MacProtocol(StreamBase *stream, AbstractProtocol *parent) : AbstractProtocol(stream, parent) { @@ -129,7 +135,7 @@ QVariant MacProtocol::fieldData(int index, FieldAttrib attrib, case FieldValue: return dstMac; case FieldTextValue: - return uintToHexStr(dstMac, 6); + return uintToMacStr(dstMac); case FieldFrameValue: { QByteArray fv; @@ -174,7 +180,7 @@ QVariant MacProtocol::fieldData(int index, FieldAttrib attrib, case FieldValue: return srcMac; case FieldTextValue: - return uintToHexStr(srcMac, 6); + return uintToMacStr(srcMac); case FieldFrameValue: { QByteArray fv;