IPv4 now supports options - configured as a hex string for now; fixes #120

This commit is contained in:
Srivats P 2016-10-27 23:50:24 +05:30
parent b45720b566
commit c2f36c5cb3
5 changed files with 57 additions and 13 deletions

View File

@ -112,6 +112,7 @@ AbstractProtocol::FieldFlags Ip4Protocol::fieldFlags(int index) const
case ip4_srcAddr:
case ip4_dstAddr:
case ip4_options:
break;
case ip4_isOverrideVer:
@ -168,7 +169,9 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
{
int hdrlen;
hdrlen = data.is_override_hdrlen() ? data.ver_hdrlen() & 0x0F : 5;
hdrlen = data.is_override_hdrlen() ?
data.ver_hdrlen() : 5 + data.options().length()/4;
hdrlen &= 0x0F;
switch(attrib)
{
@ -205,6 +208,7 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
break;
case ip4_totLen:
{
int ipLen = 20 + data.options().length();
switch(attrib)
{
case FieldName:
@ -213,7 +217,7 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
{
int totlen;
totlen = data.is_override_totlen() ? data.totlen() :
(protocolFramePayloadSize(streamIndex) + 20);
(protocolFramePayloadSize(streamIndex) + ipLen);
return totlen;
}
case FieldFrameValue:
@ -221,7 +225,7 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
QByteArray fv;
int totlen;
totlen = data.is_override_totlen() ? data.totlen() :
(protocolFramePayloadSize(streamIndex) + 20);
(protocolFramePayloadSize(streamIndex) + ipLen);
fv.resize(2);
qToBigEndian((quint16) totlen, (uchar*) fv.data());
return fv;
@ -230,7 +234,7 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
{
int totlen;
totlen = data.is_override_totlen() ? data.totlen() :
(protocolFramePayloadSize(streamIndex) + 20);
(protocolFramePayloadSize(streamIndex) + ipLen);
return QString("%1").arg(totlen);
}
case FieldBitSize:
@ -509,6 +513,32 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
}
break;
}
case ip4_options:
{
QByteArray ba;
switch(attrib)
{
case FieldValue:
case FieldFrameValue:
case FieldTextValue:
ba.append(QString().fromStdString(data.options()));
default:
break;
}
switch(attrib)
{
case FieldName:
return QString("Options");
case FieldValue:
case FieldFrameValue:
return ba;
case FieldTextValue:
return ba.toHex();
default:
break;
}
break;
}
// Meta fields
case ip4_isOverrideVer:
@ -695,6 +725,16 @@ bool Ip4Protocol::setFieldData(int index, const QVariant &value,
data.set_dst_ip(dstIp);
break;
}
case ip4_options:
{
QByteArray ba = value.toByteArray();
int pad = (4 - (ba.size() % 4)) % 4;
if (pad)
ba.append(QByteArray(pad, 0));
data.set_options(ba.constData(), ba.size());
isOk = true;
break;
}
// Meta-fields
case ip4_isOverrideVer:

View File

@ -44,6 +44,7 @@ public:
ip4_cksum,
ip4_srcAddr,
ip4_dstAddr,
ip4_options,
// Meta-fields
ip4_isOverrideVer,

View File

@ -58,7 +58,7 @@ message Ip4 {
optional uint32 dst_ip_count = 20 [default = 16];
optional fixed32 dst_ip_mask = 21 [default = 0xFFFFFF00];
//! \todo (LOW) IPv4 Options
optional bytes options = 22;
}
extend Protocol {

View File

@ -366,14 +366,7 @@ Length (x4)</string>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leIpOptions" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string>TODO</string>
</property>
</widget>
<widget class="QLineEdit" name="leIpOptions" />
</item>
<item>
<widget class="QToolButton" name="tbIpOptionsEdit" >

View File

@ -28,6 +28,8 @@ Ip4ConfigForm::Ip4ConfigForm(QWidget *parent)
setupUi(this);
leIpVersion->setValidator(new QIntValidator(0, 15, this));
leIpOptions->setValidator(new QRegExpValidator(QRegExp("[0-9a-fA-F]*"),
this));
connect(cmbIpSrcAddrMode, SIGNAL(currentIndexChanged(int)),
this, SLOT(on_cmbIpSrcAddrMode_currentIndexChanged(int)));
@ -176,6 +178,11 @@ void Ip4ConfigForm::loadWidget(AbstractProtocol *proto)
Ip4Protocol::ip4_dstAddrMask,
AbstractProtocol::FieldValue
).toUInt()).toString());
leIpOptions->setText(
proto->fieldData(
Ip4Protocol::ip4_options,
AbstractProtocol::FieldValue
).toByteArray().toHex());
}
void Ip4ConfigForm::storeWidget(AbstractProtocol *proto)
@ -263,6 +270,9 @@ void Ip4ConfigForm::storeWidget(AbstractProtocol *proto)
proto->setFieldData(
Ip4Protocol::ip4_dstAddrMask,
QHostAddress(leIpDstAddrMask->text()).toIPv4Address());
proto->setFieldData(
Ip4Protocol::ip4_options,
QByteArray::fromHex(QByteArray().append(leIpOptions->text())));
}
/*