Skip to content

Commit 2270bd7

Browse files
authored
Added ProtocolType to Layer constructor. (#1559)
1 parent 02e73a1 commit 2270bd7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+120
-210
lines changed

Packet++/header/ArpLayer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ namespace pcpp
6767
* @param[in] packet A pointer to the Packet instance where layer will be stored in
6868
*/
6969
ArpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
70-
: Layer(data, dataLen, prevLayer, packet)
70+
: Layer(data, dataLen, prevLayer, packet, ARP)
7171
{
72-
m_Protocol = ARP;
7372
m_DataLen = sizeof(arphdr);
7473
}
7574

Packet++/header/BgpLayer.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,8 @@ namespace pcpp
127127
BgpLayer()
128128
{}
129129
BgpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
130-
: Layer(data, dataLen, prevLayer, packet)
131-
{
132-
m_Protocol = BGP;
133-
}
130+
: Layer(data, dataLen, prevLayer, packet, BGP)
131+
{}
134132

135133
bgp_common_header* getBasicHeader() const
136134
{

Packet++/header/CotpLayer.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ namespace pcpp
3737
* @param[in] packet A pointer to the Packet instance where layer will be stored in
3838
*/
3939
CotpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
40-
: Layer(data, dataLen, prevLayer, packet)
41-
{
42-
m_Protocol = COTP;
43-
}
40+
: Layer(data, dataLen, prevLayer, packet, COTP)
41+
{}
4442

4543
/**
4644
* A constructor that allocates a new COTP header

Packet++/header/EthDot3Layer.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ namespace pcpp
4141
* @param[in] dataLen Size of the data in bytes
4242
* @param[in] packet A pointer to the Packet instance where layer will be stored in
4343
*/
44-
EthDot3Layer(uint8_t* data, size_t dataLen, Packet* packet) : Layer(data, dataLen, nullptr, packet)
45-
{
46-
m_Protocol = EthernetDot3;
47-
}
44+
EthDot3Layer(uint8_t* data, size_t dataLen, Packet* packet)
45+
: Layer(data, dataLen, nullptr, packet, EthernetDot3)
46+
{}
4847

4948
/**
5049
* A constructor that creates the layer from an existing packet raw data
@@ -54,10 +53,8 @@ namespace pcpp
5453
* @param[in] packet A pointer to the Packet instance where layer will be stored in
5554
*/
5655
EthDot3Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
57-
: Layer(data, dataLen, prevLayer, packet)
58-
{
59-
m_Protocol = EthernetDot3;
60-
}
56+
: Layer(data, dataLen, prevLayer, packet, EthernetDot3)
57+
{}
6158

6259
/**
6360
* A constructor that creates a new IEEE 802.3 Ethernet header and allocates the data

Packet++/header/EthLayer.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ namespace pcpp
7878
* @param[in] dataLen Size of the data in bytes
7979
* @param[in] packet A pointer to the Packet instance where layer will be stored in
8080
*/
81-
EthLayer(uint8_t* data, size_t dataLen, Packet* packet) : Layer(data, dataLen, nullptr, packet)
82-
{
83-
m_Protocol = Ethernet;
84-
}
81+
EthLayer(uint8_t* data, size_t dataLen, Packet* packet) : Layer(data, dataLen, nullptr, packet, Ethernet)
82+
{}
8583

8684
/**
8785
* A constructor that creates the layer from an existing packet raw data
@@ -91,10 +89,8 @@ namespace pcpp
9189
* @param[in] packet A pointer to the Packet instance where layer will be stored in
9290
*/
9391
EthLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
94-
: Layer(data, dataLen, prevLayer, packet)
95-
{
96-
m_Protocol = Ethernet;
97-
}
92+
: Layer(data, dataLen, prevLayer, packet, Ethernet)
93+
{}
9894

9995
/**
10096
* A constructor that creates a new Ethernet header and allocates the data

Packet++/header/FtpLayer.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,9 @@ namespace pcpp
1919
{
2020
protected:
2121
FtpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
22-
: SingleCommandTextProtocol(data, dataLen, prevLayer, packet)
23-
{
24-
m_Protocol = FTP;
25-
};
26-
FtpLayer(const std::string& command, const std::string& option) : SingleCommandTextProtocol(command, option)
27-
{
28-
m_Protocol = FTP;
29-
};
22+
: SingleCommandTextProtocol(data, dataLen, prevLayer, packet, FTP) {};
23+
FtpLayer(const std::string& command, const std::string& option)
24+
: SingleCommandTextProtocol(command, option, FTP) {};
3025

3126
public:
3227
/**

Packet++/header/GreLayer.h

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ namespace pcpp
160160
}
161161

162162
protected:
163-
GreLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
164-
: Layer(data, dataLen, prevLayer, packet)
163+
GreLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ProtocolType protocol)
164+
: Layer(data, dataLen, prevLayer, packet, protocol)
165165
{}
166166

167167
GreLayer()
@@ -196,10 +196,8 @@ namespace pcpp
196196
* @param[in] packet A pointer to the Packet instance where layer will be stored in
197197
*/
198198
GREv0Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
199-
: GreLayer(data, dataLen, prevLayer, packet)
200-
{
201-
m_Protocol = GREv0;
202-
}
199+
: GreLayer(data, dataLen, prevLayer, packet, GREv0)
200+
{}
203201

204202
/**
205203
* A constructor that creates a new GREv0 header and allocates the data
@@ -322,10 +320,8 @@ namespace pcpp
322320
* @param[in] packet A pointer to the Packet instance where layer will be stored in
323321
*/
324322
GREv1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
325-
: GreLayer(data, dataLen, prevLayer, packet)
326-
{
327-
m_Protocol = GREv1;
328-
}
323+
: GreLayer(data, dataLen, prevLayer, packet, GREv1)
324+
{}
329325

330326
/**
331327
* A constructor that creates a new GREv1 header and allocates the data
@@ -414,10 +410,8 @@ namespace pcpp
414410
* @param[in] packet A pointer to the Packet instance where layer will be stored in
415411
*/
416412
PPP_PPTPLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
417-
: Layer(data, dataLen, prevLayer, packet)
418-
{
419-
m_Protocol = PPP_PPTP;
420-
}
413+
: Layer(data, dataLen, prevLayer, packet, PPP_PPTP)
414+
{}
421415

422416
/**
423417
* A constructor that allocates a new PPP-PPTP header

Packet++/header/GtpLayer.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,8 @@ namespace pcpp
317317
* @param[in] packet A pointer to the Packet instance where layer will be stored in
318318
*/
319319
GtpV1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
320-
: Layer(data, dataLen, prevLayer, packet)
321-
{
322-
m_Protocol = GTPv1;
323-
}
320+
: Layer(data, dataLen, prevLayer, packet, GTPv1)
321+
{}
324322

325323
/**
326324
* A constructor that creates a new GTPv1 layer and sets the message type and the TEID value

Packet++/header/HttpLayer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ namespace pcpp
100100
}
101101

102102
protected:
103-
HttpMessage(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
104-
: TextBasedProtocolMessage(data, dataLen, prevLayer, packet)
103+
HttpMessage(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ProtocolType protocol)
104+
: TextBasedProtocolMessage(data, dataLen, prevLayer, packet, protocol)
105105
{}
106106
HttpMessage() : TextBasedProtocolMessage()
107107
{}

Packet++/header/IPSecLayer.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ namespace pcpp
5858
* @param[in] packet A pointer to the Packet instance where layer will be stored in
5959
*/
6060
AuthenticationHeaderLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
61-
: Layer(data, dataLen, prevLayer, packet)
62-
{
63-
m_Protocol = AuthenticationHeader;
64-
}
61+
: Layer(data, dataLen, prevLayer, packet, AuthenticationHeader)
62+
{}
6563

6664
/**
6765
* Get a pointer to the raw AH header. Notice this points directly to the data, so every change will change the
@@ -155,14 +153,12 @@ namespace pcpp
155153
* @param[in] packet A pointer to the Packet instance where layer will be stored in
156154
*/
157155
ESPLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
158-
: Layer(data, dataLen, prevLayer, packet)
159-
{
160-
m_Protocol = ESP;
161-
}
156+
: Layer(data, dataLen, prevLayer, packet, ESP)
157+
{}
162158

163159
ipsec_esp* getESPHeader() const
164160
{
165-
return (ipsec_esp*)m_Data;
161+
return reinterpret_cast<ipsec_esp*>(m_Data);
166162
}
167163

168164
/**

0 commit comments

Comments
 (0)