2009-04-27 11:51:44 -05:00
|
|
|
#include <qendian.h>
|
|
|
|
#include <QHostAddress>
|
|
|
|
|
|
|
|
#include "udp.h"
|
|
|
|
|
|
|
|
UdpConfigForm *UdpProtocol::configForm = NULL;
|
|
|
|
|
|
|
|
UdpConfigForm::UdpConfigForm(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
}
|
|
|
|
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
UdpProtocol::UdpProtocol(
|
|
|
|
ProtocolList &frameProtoList,
|
|
|
|
OstProto::StreamCore *parent)
|
|
|
|
: AbstractProtocol(frameProtoList, parent)
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
|
|
|
if (configForm == NULL)
|
|
|
|
configForm = new UdpConfigForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
UdpProtocol::~UdpProtocol()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
AbstractProtocol* UdpProtocol::createInstance(
|
|
|
|
ProtocolList &frameProtoList,
|
|
|
|
OstProto::StreamCore *streamCore)
|
|
|
|
{
|
|
|
|
return new UdpProtocol(frameProtoList, streamCore);
|
|
|
|
}
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
void UdpProtocol::protoDataCopyInto(OstProto::Stream &stream)
|
|
|
|
{
|
|
|
|
// FIXME: multiple headers
|
|
|
|
stream.MutableExtension(OstProto::udp)->CopyFrom(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UdpProtocol::protoDataCopyFrom(const OstProto::Stream &stream)
|
|
|
|
{
|
|
|
|
// FIXME: multiple headers
|
|
|
|
if (stream.HasExtension(OstProto::udp))
|
|
|
|
data.MergeFrom(stream.GetExtension(OstProto::udp));
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UdpProtocol::name() const
|
|
|
|
{
|
|
|
|
return QString("User Datagram Protocol");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UdpProtocol::shortName() const
|
|
|
|
{
|
|
|
|
return QString("UDP");
|
|
|
|
}
|
|
|
|
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
quint32 UdpProtocol::protocolId(ProtocolIdType type) const
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case ProtocolIdIp: return 0x11;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AbstractProtocol::protocolId(type);
|
|
|
|
}
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
int UdpProtocol::fieldCount() const
|
|
|
|
{
|
|
|
|
return udp_fieldCount;
|
|
|
|
}
|
|
|
|
|
2009-05-24 09:54:11 -05:00
|
|
|
AbstractProtocol::FieldFlags UdpProtocol::fieldFlags(int index) const
|
|
|
|
{
|
|
|
|
AbstractProtocol::FieldFlags flags;
|
|
|
|
|
|
|
|
flags = AbstractProtocol::fieldFlags(index);
|
|
|
|
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case udp_srcPort:
|
|
|
|
case udp_dstPort:
|
|
|
|
case udp_totLen:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case udp_cksum:
|
|
|
|
flags |= FieldIsCksum;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case udp_isOverrideTotLen:
|
|
|
|
case udp_isOverrideCksum:
|
|
|
|
flags |= FieldIsMeta;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
QVariant UdpProtocol::fieldData(int index, FieldAttrib attrib,
|
|
|
|
int streamIndex) const
|
|
|
|
{
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case udp_srcPort:
|
|
|
|
switch(attrib)
|
|
|
|
{
|
|
|
|
case FieldName:
|
|
|
|
return QString("Source Port");
|
|
|
|
case FieldValue:
|
|
|
|
return data.src_port();
|
|
|
|
case FieldTextValue:
|
|
|
|
return QString("%1").arg(data.src_port());
|
|
|
|
case FieldFrameValue:
|
|
|
|
{
|
|
|
|
QByteArray fv;
|
|
|
|
fv.resize(2);
|
|
|
|
qToBigEndian((quint16) data.src_port(), (uchar*) fv.data());
|
|
|
|
return fv;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case udp_dstPort:
|
|
|
|
switch(attrib)
|
|
|
|
{
|
|
|
|
case FieldName:
|
|
|
|
return QString("Destination Port");
|
|
|
|
case FieldValue:
|
|
|
|
return data.dst_port();
|
|
|
|
case FieldTextValue:
|
|
|
|
return QString("%1").arg(data.dst_port());
|
|
|
|
case FieldFrameValue:
|
|
|
|
{
|
|
|
|
QByteArray fv;
|
|
|
|
fv.resize(2);
|
|
|
|
qToBigEndian((quint16) data.dst_port(), (uchar*) fv.data());
|
|
|
|
return fv;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case udp_totLen:
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
{
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
switch(attrib)
|
|
|
|
{
|
|
|
|
case FieldName:
|
|
|
|
return QString("Datagram Length");
|
|
|
|
case FieldValue:
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
{
|
|
|
|
int totlen;
|
|
|
|
|
|
|
|
totlen = data.is_override_totlen() ?
|
|
|
|
data.totlen() :
|
|
|
|
(protocolFramePayloadSize() + 8);
|
|
|
|
return totlen;
|
|
|
|
}
|
2009-04-27 11:51:44 -05:00
|
|
|
case FieldFrameValue:
|
|
|
|
{
|
|
|
|
QByteArray fv;
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
int totlen;
|
|
|
|
totlen = data.is_override_totlen() ?
|
|
|
|
data.totlen() :
|
|
|
|
(protocolFramePayloadSize() + 8);
|
2009-04-27 11:51:44 -05:00
|
|
|
fv.resize(2);
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
qToBigEndian((quint16) totlen, (uchar*) fv.data());
|
2009-04-27 11:51:44 -05:00
|
|
|
return fv;
|
|
|
|
}
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
case FieldTextValue:
|
|
|
|
{
|
|
|
|
int totlen;
|
|
|
|
totlen = data.is_override_totlen() ?
|
|
|
|
data.totlen() :
|
|
|
|
(protocolFramePayloadSize() + 8);
|
|
|
|
return QString("%1").arg(totlen);
|
|
|
|
}
|
|
|
|
case FieldBitSize:
|
|
|
|
return 16;
|
2009-04-27 11:51:44 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
}
|
2009-04-27 11:51:44 -05:00
|
|
|
case udp_cksum:
|
2009-05-24 09:54:11 -05:00
|
|
|
{
|
|
|
|
quint16 cksum;
|
|
|
|
|
|
|
|
switch(attrib)
|
|
|
|
{
|
|
|
|
case FieldValue:
|
|
|
|
case FieldFrameValue:
|
|
|
|
case FieldTextValue:
|
|
|
|
{
|
|
|
|
if (data.is_override_cksum())
|
|
|
|
cksum = data.cksum();
|
|
|
|
else
|
|
|
|
cksum = protocolFrameCksum(streamIndex, CksumTcpUdp);
|
|
|
|
qDebug("UDP cksum = %hu", cksum);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
switch(attrib)
|
|
|
|
{
|
|
|
|
case FieldName:
|
|
|
|
return QString("Checksum");
|
|
|
|
case FieldValue:
|
2009-05-24 09:54:11 -05:00
|
|
|
return cksum;
|
2009-04-27 11:51:44 -05:00
|
|
|
case FieldFrameValue:
|
|
|
|
{
|
|
|
|
QByteArray fv;
|
2009-05-24 09:54:11 -05:00
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
fv.resize(2);
|
2009-05-24 09:54:11 -05:00
|
|
|
qToBigEndian(cksum, (uchar*) fv.data());
|
2009-04-27 11:51:44 -05:00
|
|
|
return fv;
|
|
|
|
}
|
2009-05-24 09:54:11 -05:00
|
|
|
case FieldTextValue:
|
|
|
|
return QString("0x%1").
|
|
|
|
arg(cksum, 4, BASE_HEX, QChar('0'));;
|
|
|
|
case FieldBitSize:
|
|
|
|
return 16;
|
2009-04-27 11:51:44 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2009-05-24 09:54:11 -05:00
|
|
|
}
|
2009-04-27 11:51:44 -05:00
|
|
|
// Meta fields
|
|
|
|
case udp_isOverrideTotLen:
|
|
|
|
case udp_isOverrideCksum:
|
|
|
|
switch(attrib)
|
|
|
|
{
|
|
|
|
case FieldIsMeta:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AbstractProtocol::fieldData(index, attrib, streamIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UdpProtocol::setFieldData(int index, const QVariant &value,
|
|
|
|
FieldAttrib attrib)
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget* UdpProtocol::configWidget()
|
|
|
|
{
|
|
|
|
return configForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UdpProtocol::loadConfigWidget()
|
|
|
|
{
|
2009-05-24 09:54:11 -05:00
|
|
|
configForm->leUdpSrcPort->setText(fieldData(udp_srcPort, FieldValue).toString());
|
|
|
|
configForm->leUdpDstPort->setText(fieldData(udp_dstPort, FieldValue).toString());
|
2009-04-27 11:51:44 -05:00
|
|
|
|
2009-05-24 09:54:11 -05:00
|
|
|
configForm->leUdpLength->setText(fieldData(udp_totLen, FieldValue).toString());
|
2009-04-27 11:51:44 -05:00
|
|
|
configForm->cbUdpLengthOverride->setChecked(data.is_override_totlen());
|
|
|
|
|
2009-05-24 09:54:11 -05:00
|
|
|
configForm->leUdpCksum->setText(QString("%1").arg(
|
|
|
|
fieldData(udp_cksum, FieldValue).toUInt(), 4, BASE_HEX, QChar('0')));
|
2009-04-27 11:51:44 -05:00
|
|
|
configForm->cbUdpCksumOverride->setChecked(data.is_override_cksum());
|
|
|
|
}
|
|
|
|
|
|
|
|
void UdpProtocol::storeConfigWidget()
|
|
|
|
{
|
|
|
|
bool isOk;
|
|
|
|
|
|
|
|
data.set_src_port(configForm->leUdpSrcPort->text().toULong(&isOk));
|
|
|
|
data.set_dst_port(configForm->leUdpDstPort->text().toULong(&isOk));
|
|
|
|
|
|
|
|
data.set_totlen(configForm->leUdpLength->text().toULong(&isOk));
|
|
|
|
data.set_is_override_totlen(configForm->cbUdpLengthOverride->isChecked());
|
|
|
|
|
2009-05-24 09:54:11 -05:00
|
|
|
data.set_cksum(configForm->leUdpCksum->text().remove(QChar(' ')).toULong(&isOk, BASE_HEX));
|
2009-04-27 11:51:44 -05:00
|
|
|
data.set_is_override_cksum(configForm->cbUdpCksumOverride->isChecked());
|
|
|
|
}
|
|
|
|
|