Change GRE optional fields implementation
* frameFieldCount() always includes all frame fields whether or not included in packet * if an optional field is not included in packet - FieldName is still returned - FieldTextValue is returned as "<not-included>" - FieldBitWidth is 0 - all remaining attributes are QVariant()
This commit is contained in:
parent
c8cc7a021f
commit
25a91e52f6
@ -83,29 +83,6 @@ int GreProtocol::fieldCount() const
|
|||||||
return gre_fieldCount;
|
return gre_fieldCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
TODO Return the number of frame fields for your protocol. A frame field
|
|
||||||
is a field which has the FrameField flag set \n
|
|
||||||
|
|
||||||
If your protocol has different sets of fields based on a OpCode/Type field
|
|
||||||
(e.g. icmp), you MUST re-implement this function; however, if your protocol
|
|
||||||
has a fixed set of frame fields always, you don't need to reimplement this
|
|
||||||
method - the base class implementation will do the right thing
|
|
||||||
*/
|
|
||||||
int GreProtocol::frameFieldCount() const
|
|
||||||
{
|
|
||||||
int count = 4; // mandatory fields - flags, rsvd0, version, protocol
|
|
||||||
|
|
||||||
if (data.flags() & GRE_FLAG_CKSUM)
|
|
||||||
count += 2; // checksum, rsvd1
|
|
||||||
if (data.flags() & GRE_FLAG_KEY)
|
|
||||||
count++;
|
|
||||||
if (data.flags() & GRE_FLAG_SEQ)
|
|
||||||
count++;
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractProtocol::FieldFlags GreProtocol::fieldFlags(int index) const
|
AbstractProtocol::FieldFlags GreProtocol::fieldFlags(int index) const
|
||||||
{
|
{
|
||||||
AbstractProtocol::FieldFlags flags;
|
AbstractProtocol::FieldFlags flags;
|
||||||
@ -227,22 +204,22 @@ QVariant GreProtocol::fieldData(int index, FieldAttrib attrib,
|
|||||||
}
|
}
|
||||||
case gre_checksum:
|
case gre_checksum:
|
||||||
{
|
{
|
||||||
if ((data.flags() & GRE_FLAG_CKSUM) == 0)
|
if (attrib == FieldName)
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
switch(attrib)
|
|
||||||
{
|
|
||||||
case FieldName:
|
|
||||||
return QString("Checksum");
|
return QString("Checksum");
|
||||||
case FieldBitSize:
|
|
||||||
return 16;
|
if ((data.flags() & GRE_FLAG_CKSUM) == 0)
|
||||||
default:
|
{
|
||||||
break;
|
if (attrib == FieldTextValue)
|
||||||
|
return QObject::tr("<not-included>");
|
||||||
|
else
|
||||||
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
quint16 cksum = 0;
|
if (attrib == FieldBitSize)
|
||||||
if (data.flags() & GRE_FLAG_CKSUM) {
|
return 16;
|
||||||
|
|
||||||
quint32 sum = 0;
|
quint32 sum = 0;
|
||||||
|
quint16 cksum;
|
||||||
|
|
||||||
cksum = protocolFrameCksum(streamIndex, CksumIp);
|
cksum = protocolFrameCksum(streamIndex, CksumIp);
|
||||||
sum += (quint16) ~cksum;
|
sum += (quint16) ~cksum;
|
||||||
@ -253,7 +230,6 @@ QVariant GreProtocol::fieldData(int index, FieldAttrib attrib,
|
|||||||
sum = (sum & 0xFFFF) + (sum >> 16);
|
sum = (sum & 0xFFFF) + (sum >> 16);
|
||||||
|
|
||||||
cksum = (~sum) & 0xFFFF;
|
cksum = (~sum) & 0xFFFF;
|
||||||
}
|
|
||||||
|
|
||||||
switch(attrib)
|
switch(attrib)
|
||||||
{
|
{
|
||||||
@ -277,13 +253,19 @@ QVariant GreProtocol::fieldData(int index, FieldAttrib attrib,
|
|||||||
|
|
||||||
case gre_rsvd1:
|
case gre_rsvd1:
|
||||||
{
|
{
|
||||||
|
if (attrib == FieldName)
|
||||||
|
return QString("Reserved1");
|
||||||
|
|
||||||
if ((data.flags() & GRE_FLAG_CKSUM) == 0)
|
if ((data.flags() & GRE_FLAG_CKSUM) == 0)
|
||||||
|
{
|
||||||
|
if (attrib == FieldTextValue)
|
||||||
|
return QObject::tr("<not-included>");
|
||||||
|
else
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
switch(attrib)
|
switch(attrib)
|
||||||
{
|
{
|
||||||
case FieldName:
|
|
||||||
return QString("Reserved1");
|
|
||||||
case FieldValue:
|
case FieldValue:
|
||||||
return data.rsvd1();
|
return data.rsvd1();
|
||||||
case FieldTextValue:
|
case FieldTextValue:
|
||||||
@ -303,13 +285,19 @@ QVariant GreProtocol::fieldData(int index, FieldAttrib attrib,
|
|||||||
|
|
||||||
case gre_key:
|
case gre_key:
|
||||||
{
|
{
|
||||||
|
if (attrib == FieldName)
|
||||||
|
return QString("Key");
|
||||||
|
|
||||||
if ((data.flags() & GRE_FLAG_KEY) == 0)
|
if ((data.flags() & GRE_FLAG_KEY) == 0)
|
||||||
|
{
|
||||||
|
if (attrib == FieldTextValue)
|
||||||
|
return QObject::tr("<not-included>");
|
||||||
|
else
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
switch(attrib)
|
switch(attrib)
|
||||||
{
|
{
|
||||||
case FieldName:
|
|
||||||
return QString("Key");
|
|
||||||
case FieldValue:
|
case FieldValue:
|
||||||
return data.key();
|
return data.key();
|
||||||
case FieldTextValue:
|
case FieldTextValue:
|
||||||
@ -326,15 +314,22 @@ QVariant GreProtocol::fieldData(int index, FieldAttrib attrib,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case gre_sequence:
|
case gre_sequence:
|
||||||
{
|
{
|
||||||
|
if (attrib == FieldName)
|
||||||
|
return QString("Sequence Number");
|
||||||
|
|
||||||
if ((data.flags() & GRE_FLAG_SEQ) == 0)
|
if ((data.flags() & GRE_FLAG_SEQ) == 0)
|
||||||
|
{
|
||||||
|
if (attrib == FieldTextValue)
|
||||||
|
return QObject::tr("<not-included>");
|
||||||
|
else
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
switch(attrib)
|
switch(attrib)
|
||||||
{
|
{
|
||||||
case FieldName:
|
|
||||||
return QString("Sequence Number");
|
|
||||||
case FieldValue:
|
case FieldValue:
|
||||||
return data.sequence_num();
|
return data.sequence_num();
|
||||||
case FieldTextValue:
|
case FieldTextValue:
|
||||||
|
@ -78,7 +78,6 @@ public:
|
|||||||
virtual QString shortName() const;
|
virtual QString shortName() const;
|
||||||
|
|
||||||
virtual int fieldCount() const;
|
virtual int fieldCount() const;
|
||||||
virtual int frameFieldCount() const;
|
|
||||||
|
|
||||||
virtual AbstractProtocol::FieldFlags fieldFlags(int index) const;
|
virtual AbstractProtocol::FieldFlags fieldFlags(int index) const;
|
||||||
virtual QVariant fieldData(int index, FieldAttrib attrib,
|
virtual QVariant fieldData(int index, FieldAttrib attrib,
|
||||||
|
Loading…
Reference in New Issue
Block a user