- clang format + naming improved
This commit is contained in:
@@ -7,13 +7,13 @@ static const uint32_t HEPID2 = 0x021002;
|
||||
static const uint32_t HEPID3 = 0x48455033;
|
||||
|
||||
|
||||
bool Packet::parseV3(const ByteBuffer& packet)
|
||||
bool Packet::parseV3(const ByteBuffer& packet)
|
||||
{
|
||||
if (packet.size() < 30)
|
||||
return false;
|
||||
|
||||
BufferReader r(packet);
|
||||
char signature[4];
|
||||
char signature[4];
|
||||
r.readBuffer(signature, 4);
|
||||
|
||||
if (signature[0] != 'H' || signature[1] != 'E' || signature[2] != 'P' || signature[3] != '3')
|
||||
@@ -24,12 +24,12 @@ bool Packet::parseV3(const ByteBuffer& packet)
|
||||
l -= 6;
|
||||
|
||||
InternetAddress sourceAddr4, destAddr4, sourceAddr6, destAddr6;
|
||||
uint16_t sourcePort = 0, destPort = 0;
|
||||
uint16_t sourcePort = 0, destPort = 0;
|
||||
while (r.count() < packet.size())
|
||||
{
|
||||
mVendorId = (VendorId)r.readUShort();
|
||||
ChunkType chunkType = (ChunkType)r.readUShort();
|
||||
int chunkLength = r.readUShort();
|
||||
int chunkLength = r.readUShort();
|
||||
|
||||
switch (chunkType)
|
||||
{
|
||||
@@ -102,8 +102,7 @@ bool Packet::parseV3(const ByteBuffer& packet)
|
||||
|
||||
if (!sourceAddr4.isEmpty())
|
||||
mSourceAddress = sourceAddr4;
|
||||
else
|
||||
if (!sourceAddr6.isEmpty())
|
||||
else if (!sourceAddr6.isEmpty())
|
||||
mSourceAddress = sourceAddr6;
|
||||
|
||||
if (!mSourceAddress.isEmpty())
|
||||
@@ -111,8 +110,7 @@ bool Packet::parseV3(const ByteBuffer& packet)
|
||||
|
||||
if (!destAddr4.isEmpty())
|
||||
mDestinationAddress = destAddr4;
|
||||
else
|
||||
if (!destAddr6.isEmpty())
|
||||
else if (!destAddr6.isEmpty())
|
||||
mDestinationAddress = destAddr6;
|
||||
|
||||
if (!mDestinationAddress.isEmpty())
|
||||
@@ -121,7 +119,7 @@ bool Packet::parseV3(const ByteBuffer& packet)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Packet::parseV2(const ByteBuffer &packet)
|
||||
bool Packet::parseV2(const ByteBuffer& packet)
|
||||
{
|
||||
if (packet.size() < 31)
|
||||
return false;
|
||||
@@ -148,16 +146,53 @@ bool Packet::parseV2(const ByteBuffer &packet)
|
||||
return true;
|
||||
}
|
||||
|
||||
#define WRITE_CHUNK_UCHAR(T, V) {w.writeUShort((uint16_t)mVendorId); w.writeUShort((uint16_t)T); w.writeUShort(1); w.writeUChar((uint8_t)V);}
|
||||
#define WRITE_CHUNK_USHORT(T, V) {w.writeUShort((uint16_t)mVendorId); w.writeUShort((uint16_t)T); w.writeUShort(2); w.writeUShort((uint16_t)V);}
|
||||
#define WRITE_CHUNK_UINT(T, V) {w.writeUShort((uint16_t)mVendorId); w.writeUShort((uint16_t)T); w.writeUShort(4); w.writeUInt((uint32_t)V);}
|
||||
#define WRITE_CHUNK_IP4(T, V) {w.writeUShort((uint16_t)mVendorId); w.writeUShort((uint16_t)T); w.writeUShort(4); w.writeIp(V);}
|
||||
#define WRITE_CHUNK_IP6(T, V) {w.writeUShort((uint16_t)mVendorId); w.writeUShort((uint16_t)T); w.writeUShort(8); w.writeIp(V);}
|
||||
#define WRITE_CHUNK_BUFFER(T, V) {w.writeUShort((uint16_t)mVendorId); w.writeUShort((uint16_t)T); w.writeUShort(8); w.writeBuffer(V.data(), V.size());}
|
||||
#define WRITE_CHUNK_UCHAR(T, V) \
|
||||
{ \
|
||||
w.writeUShort((uint16_t)mVendorId); \
|
||||
w.writeUShort((uint16_t)T); \
|
||||
w.writeUShort(1); \
|
||||
w.writeUChar((uint8_t)V); \
|
||||
}
|
||||
#define WRITE_CHUNK_USHORT(T, V) \
|
||||
{ \
|
||||
w.writeUShort((uint16_t)mVendorId); \
|
||||
w.writeUShort((uint16_t)T); \
|
||||
w.writeUShort(2); \
|
||||
w.writeUShort((uint16_t)V); \
|
||||
}
|
||||
#define WRITE_CHUNK_UINT(T, V) \
|
||||
{ \
|
||||
w.writeUShort((uint16_t)mVendorId); \
|
||||
w.writeUShort((uint16_t)T); \
|
||||
w.writeUShort(4); \
|
||||
w.writeUInt((uint32_t)V); \
|
||||
}
|
||||
#define WRITE_CHUNK_IP4(T, V) \
|
||||
{ \
|
||||
w.writeUShort((uint16_t)mVendorId); \
|
||||
w.writeUShort((uint16_t)T); \
|
||||
w.writeUShort(4); \
|
||||
w.writeIp(V); \
|
||||
}
|
||||
#define WRITE_CHUNK_IP6(T, V) \
|
||||
{ \
|
||||
w.writeUShort((uint16_t)mVendorId); \
|
||||
w.writeUShort((uint16_t)T); \
|
||||
w.writeUShort(8); \
|
||||
w.writeIp(V); \
|
||||
}
|
||||
#define WRITE_CHUNK_BUFFER(T, V) \
|
||||
{ \
|
||||
w.writeUShort((uint16_t)mVendorId); \
|
||||
w.writeUShort((uint16_t)T); \
|
||||
w.writeUShort(8); \
|
||||
w.writeBuffer(V.data(), V.size()); \
|
||||
}
|
||||
|
||||
ByteBuffer Packet::buildV3()
|
||||
{
|
||||
ByteBuffer r; r.resize(mBody.size() + 512);
|
||||
ByteBuffer r;
|
||||
r.resize(mBody.size() + 512);
|
||||
BufferWriter w(r);
|
||||
|
||||
// Signature
|
||||
@@ -174,9 +209,8 @@ ByteBuffer Packet::buildV3()
|
||||
{
|
||||
if (mSourceAddress.isV4())
|
||||
WRITE_CHUNK_IP4(ChunkType::IP4SourceAddress, mSourceAddress)
|
||||
else
|
||||
if (mSourceAddress.isV6())
|
||||
WRITE_CHUNK_IP6(ChunkType::IP6SourceAddress, mSourceAddress);
|
||||
else if (mSourceAddress.isV6())
|
||||
WRITE_CHUNK_IP6(ChunkType::IP6SourceAddress, mSourceAddress);
|
||||
|
||||
WRITE_CHUNK_USHORT(ChunkType::SourcePort, mSourceAddress.port());
|
||||
}
|
||||
@@ -186,9 +220,8 @@ ByteBuffer Packet::buildV3()
|
||||
{
|
||||
if (mDestinationAddress.isV4())
|
||||
WRITE_CHUNK_IP4(ChunkType::IP4DestinationAddress, mDestinationAddress)
|
||||
else
|
||||
if (mDestinationAddress.isV6())
|
||||
WRITE_CHUNK_IP6(ChunkType::IP6DestinationAddress, mDestinationAddress);
|
||||
else if (mDestinationAddress.isV6())
|
||||
WRITE_CHUNK_IP6(ChunkType::IP6DestinationAddress, mDestinationAddress);
|
||||
|
||||
WRITE_CHUNK_USHORT(ChunkType::DestinationPort, mDestinationAddress.port());
|
||||
}
|
||||
@@ -216,7 +249,9 @@ ByteBuffer Packet::buildV3()
|
||||
|
||||
r.resize(w.offset());
|
||||
|
||||
w.rewind(); w.skip(4); w.writeUShort((uint16_t)r.size());
|
||||
w.rewind();
|
||||
w.skip(4);
|
||||
w.writeUShort((uint16_t)r.size());
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user