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:
parent
40837fae40
commit
5ee4786008
@ -35,9 +35,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#define BASE_DEC (10)
|
#define BASE_DEC (10)
|
||||||
#define BASE_HEX (16)
|
#define BASE_HEX (16)
|
||||||
|
|
||||||
#define uintToHexStr(num, bytes) \
|
|
||||||
QString("%1").arg(num, bytes*2, BASE_HEX, QChar('0'))
|
|
||||||
|
|
||||||
class StreamBase;
|
class StreamBase;
|
||||||
class ProtocolListIterator;
|
class ProtocolListIterator;
|
||||||
|
|
||||||
|
@ -23,6 +23,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
class AbstractProtocol;
|
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
|
class AbstractProtocolConfigForm : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
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)
|
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)
|
quint64 hexStrToUInt64(QString text, bool *ok=NULL)
|
||||||
{
|
{
|
||||||
|
@ -20,6 +20,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include "arp.h"
|
#include "arp.h"
|
||||||
|
|
||||||
#include <QHostAddress>
|
#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)
|
ArpProtocol::ArpProtocol(StreamBase *stream, AbstractProtocol *parent)
|
||||||
: AbstractProtocol(stream, parent)
|
: AbstractProtocol(stream, parent)
|
||||||
@ -295,7 +300,7 @@ QVariant ArpProtocol::fieldData(int index, FieldAttrib attrib,
|
|||||||
case FieldValue:
|
case FieldValue:
|
||||||
return hwAddr;
|
return hwAddr;
|
||||||
case FieldTextValue:
|
case FieldTextValue:
|
||||||
return uintToHexStr(hwAddr, 6);
|
return uintToMacStr(hwAddr);
|
||||||
case FieldFrameValue:
|
case FieldFrameValue:
|
||||||
{
|
{
|
||||||
QByteArray fv;
|
QByteArray fv;
|
||||||
@ -403,7 +408,7 @@ QVariant ArpProtocol::fieldData(int index, FieldAttrib attrib,
|
|||||||
case FieldValue:
|
case FieldValue:
|
||||||
return hwAddr;
|
return hwAddr;
|
||||||
case FieldTextValue:
|
case FieldTextValue:
|
||||||
return uintToHexStr(hwAddr, 6);
|
return uintToMacStr(hwAddr);
|
||||||
case FieldFrameValue:
|
case FieldFrameValue:
|
||||||
{
|
{
|
||||||
QByteArray fv;
|
QByteArray fv;
|
||||||
|
@ -19,6 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
#include "mac.h"
|
#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)
|
MacProtocol::MacProtocol(StreamBase *stream, AbstractProtocol *parent)
|
||||||
: AbstractProtocol(stream, parent)
|
: AbstractProtocol(stream, parent)
|
||||||
{
|
{
|
||||||
@ -129,7 +135,7 @@ QVariant MacProtocol::fieldData(int index, FieldAttrib attrib,
|
|||||||
case FieldValue:
|
case FieldValue:
|
||||||
return dstMac;
|
return dstMac;
|
||||||
case FieldTextValue:
|
case FieldTextValue:
|
||||||
return uintToHexStr(dstMac, 6);
|
return uintToMacStr(dstMac);
|
||||||
case FieldFrameValue:
|
case FieldFrameValue:
|
||||||
{
|
{
|
||||||
QByteArray fv;
|
QByteArray fv;
|
||||||
@ -174,7 +180,7 @@ QVariant MacProtocol::fieldData(int index, FieldAttrib attrib,
|
|||||||
case FieldValue:
|
case FieldValue:
|
||||||
return srcMac;
|
return srcMac;
|
||||||
case FieldTextValue:
|
case FieldTextValue:
|
||||||
return uintToHexStr(srcMac, 6);
|
return uintToMacStr(srcMac);
|
||||||
case FieldFrameValue:
|
case FieldFrameValue:
|
||||||
{
|
{
|
||||||
QByteArray fv;
|
QByteArray fv;
|
||||||
|
Loading…
Reference in New Issue
Block a user