diff --git a/common/ip4.cpp b/common/ip4.cpp index 6377bd9b..cdeea980 100644 --- a/common/ip4.cpp +++ b/common/ip4.cpp @@ -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: diff --git a/common/ip4.h b/common/ip4.h index 1d4dd39b..5666a9cc 100644 --- a/common/ip4.h +++ b/common/ip4.h @@ -44,6 +44,7 @@ class Ip4Protocol : public AbstractProtocol ip4_cksum, ip4_srcAddr, ip4_dstAddr, + ip4_options, // Meta-fields ip4_isOverrideVer, diff --git a/common/ip4.proto b/common/ip4.proto index be7391dd..33ebf5c0 100644 --- a/common/ip4.proto +++ b/common/ip4.proto @@ -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 { diff --git a/common/ip4.ui b/common/ip4.ui index 3e98d7c4..8d31ed67 100644 --- a/common/ip4.ui +++ b/common/ip4.ui @@ -366,14 +366,7 @@ Length (x4) - - - false - - - TODO - - + diff --git a/common/ip4config.cpp b/common/ip4config.cpp index 261da7a7..1e7d743f 100644 --- a/common/ip4config.cpp +++ b/common/ip4config.cpp @@ -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()))); } /*