Skip to content

Commit fe0ba56

Browse files
author
Marian Krivos
committed
backport initialisation of _seq member and some static checking for ICMP packet
1 parent 672d475 commit fe0ba56

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Net/include/Poco/Net/ICMPv4PacketImpl.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "Poco/Foundation.h"
4444
#include "Poco/Net/Socket.h"
4545
#include "Poco/Net/ICMPPacketImpl.h"
46+
#include <cstddef>
4647

4748

4849
namespace Poco {
@@ -67,6 +68,12 @@ class Net_API ICMPv4PacketImpl : public ICMPPacketImpl
6768
Poco::UInt16 seq;
6869
};
6970

71+
// compile-time shield against misalignment
72+
poco_static_assert (offsetof(Header, code) == 0x01);
73+
poco_static_assert (offsetof(Header, checksum) == 0x02);
74+
poco_static_assert (offsetof(Header, id) == 0x04);
75+
poco_static_assert (offsetof(Header, seq) == 0x06);
76+
7077
enum MessageType
7178
{
7279
ECHO_REPLY,
@@ -175,7 +182,7 @@ class Net_API ICMPv4PacketImpl : public ICMPPacketImpl
175182
static const std::string REDIRECT_MESSAGE_CODE[REDIRECT_MESSAGE_LENGTH];
176183
static const std::string TIME_EXCEEDED_CODE[TIME_EXCEEDED_LENGTH];
177184
static const std::string PARAMETER_PROBLEM_CODE[PARAMETER_PROBLEM_LENGTH];
178-
185+
179186
Poco::UInt16 _seq;
180187
};
181188

Net/src/ICMPv4PacketImpl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ const std::string ICMPv4PacketImpl::PARAMETER_PROBLEM_CODE[] =
125125
};
126126

127127

128-
ICMPv4PacketImpl::ICMPv4PacketImpl(int dataSize):
129-
ICMPPacketImpl(dataSize)
128+
ICMPv4PacketImpl::ICMPv4PacketImpl(int dataSize)
129+
: ICMPPacketImpl(dataSize),
130+
_seq(0)
130131
{
131132
initPacket();
132133
}

0 commit comments

Comments
 (0)