NOX: moved uintToHexStr() definition from AbstractProtocol to AbstractProtocolConfigForm because it is supposed to be used by config widgets in their load methods. For Mac/Arp protocols which were using it to display mac address as text a new macro uintToMacStr() was added and used

This commit is contained in:
Srivats P. 2014-05-02 04:52:00 +05:30
parent 40837fae40
commit 5ee4786008
4 changed files with 23 additions and 9 deletions

View File

@ -35,9 +35,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#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;

View File

@ -23,6 +23,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
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)
{

View File

@ -20,6 +20,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "arp.h"
#include <QHostAddress>
#include <QRegExp>
#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;

View File

@ -19,6 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "mac.h"
#include <QRegExp>
#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;