Coverage Report

Created: 2026-06-30 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PcapPlusPlus/Tests/Fuzzers/ReadParsedPacket.h
Line
Count
Source
1
#pragma once
2
3
#include <Packet.h>
4
#include <IPv4Layer.h>
5
#include <TelnetLayer.h>
6
#include <BgpLayer.h>
7
#include <DhcpLayer.h>
8
#include <DhcpV6Layer.h>
9
#include <DnsLayer.h>
10
#include <IcmpLayer.h>
11
#include <NtpLayer.h>
12
#include <SSLLayer.h>
13
#include <SSLHandshake.h>
14
#include <TcpLayer.h>
15
#include <SdpLayer.h>
16
#include <VrrpLayer.h>
17
#include <Sll2Layer.h>
18
#include <FtpLayer.h>
19
#include <GreLayer.h>
20
#include <GtpLayer.h>
21
#include <SomeIpSdLayer.h>
22
23
// Call some pcpp::Packet methods that are not invoked from general virtual methods
24
// as `pcpp::Packet::toString` or `pcpp::Packet::computeCalculateFields` to trigger possible crashes.
25
// The general rule is the functions do not modify the `parsedPacket`.
26
// If you made changes to PcapPlusPlus and the code doesn't compile - fix the method call as any other unit test
27
static void readParsedPacket(pcpp::Packet parsedPacket, pcpp::Layer* layer)
28
748k
{
29
748k
  if (parsedPacket.isPacketOfType(pcpp::Telnet))
30
6.03k
  {
31
6.03k
    if (auto telnetLayer = dynamic_cast<pcpp::TelnetLayer*>(layer))
32
1.39k
    {
33
1.39k
      telnetLayer->getFirstCommand();
34
1.39k
      telnetLayer->getTotalNumberOfCommands();
35
36
1.39k
      pcpp::TelnetLayer::TelnetCommand commandVal;
37
1.39k
      do
38
16.5k
      {
39
16.5k
        commandVal = telnetLayer->getNextCommand();
40
16.5k
        std::cout << "Telnet command is '" << telnetLayer->getTelnetCommandAsString(commandVal) << "'"
41
16.5k
                  << std::endl;
42
16.5k
        pcpp::TelnetLayer::TelnetOption option = telnetLayer->getOption();
43
16.5k
        std::cout << "Telnet option is '" << telnetLayer->getTelnetOptionAsString(option) << "'" << std::endl;
44
45
16.5k
        telnetLayer->getDataAsString(true);
46
16.5k
        telnetLayer->getNumberOfCommands(commandVal);
47
16.5k
        telnetLayer->getOption(commandVal);
48
16.5k
        size_t length = 0;
49
16.5k
        telnetLayer->getOptionData(length);
50
16.5k
        telnetLayer->getOptionData(commandVal, length);
51
16.5k
      } while (commandVal != pcpp::TelnetLayer::TelnetCommand::TelnetCommandEndOfPacket);
52
1.39k
    }
53
6.03k
  }
54
748k
  if (parsedPacket.isPacketOfType(pcpp::ARP))
55
13.3k
  {
56
13.3k
    if (auto arpLayer = dynamic_cast<pcpp::ArpLayer*>(layer))
57
4.59k
    {
58
4.59k
      arpLayer->isReply();
59
4.59k
      arpLayer->isRequest();
60
4.59k
    }
61
13.3k
  }
62
748k
  if (parsedPacket.isPacketOfType(pcpp::SomeIP))
63
37.7k
  {
64
37.7k
    if (auto someipLayer = dynamic_cast<pcpp::SomeIpSdLayer*>(layer))
65
7.01k
    {
66
7.01k
      auto entries = someipLayer->getEntries();
67
7.01k
      if (!entries.empty())
68
7.01k
      {
69
7.01k
        auto opts = someipLayer->getOptionsFromEntry(0);
70
7.01k
        for (auto opt : opts)
71
4.41k
          delete opt;
72
7.01k
      }
73
74
7.01k
      for (auto entry : entries)
75
7.02k
      {
76
7.02k
        entry->getNumOptions();
77
7.02k
        entry->getServiceId();
78
7.02k
        entry->getInstanceId();
79
7.02k
        entry->getMajorVersion();
80
7.02k
        entry->getMinorVersion();
81
7.02k
        entry->getCounter();
82
7.02k
        entry->getEventgroupId();
83
7.02k
        delete entry;
84
7.02k
      }
85
86
7.01k
      someipLayer->getFlags();
87
7.01k
      auto opts = someipLayer->getOptions();
88
7.01k
      for (auto opt : opts)
89
5.12k
      {
90
5.12k
        opt->getType();
91
5.12k
        if (auto v4opt = dynamic_cast<pcpp::SomeIpSdIPv4Option*>(opt))
92
5.12k
        {
93
5.12k
          v4opt->getIpAddress();
94
5.12k
          v4opt->getPort();
95
5.12k
          v4opt->getProtocol();
96
5.12k
        }
97
0
        else if (auto v6opt = dynamic_cast<pcpp::SomeIpSdIPv6Option*>(opt))
98
0
        {
99
0
          v6opt->getIpAddress();
100
0
          v6opt->getPort();
101
0
          v6opt->getProtocol();
102
0
        }
103
5.12k
        delete opt;
104
5.12k
      }
105
7.01k
    }
106
37.7k
  }
107
748k
  if (parsedPacket.isPacketOfType(pcpp::GTP))
108
9.89k
  {
109
9.89k
    if (auto gtpLayer = dynamic_cast<pcpp::GtpV1Layer*>(layer))
110
985
    {
111
985
      uint16_t value16 = 0;
112
985
      gtpLayer->getSequenceNumber(value16);
113
985
      uint8_t value8;
114
985
      gtpLayer->getNpduNumber(value8);
115
985
      gtpLayer->getMessageType();
116
985
      gtpLayer->getMessageTypeAsString();
117
985
      gtpLayer->isGTPUMessage();
118
985
      gtpLayer->isGTPCMessage();
119
985
      auto ext = gtpLayer->getNextExtension();
120
985
      ext.getExtensionType();
121
985
      ext.getContent();
122
985
      ext.getContentLength();
123
985
      ext.getNextExtension();
124
985
    }
125
9.89k
  }
126
748k
  if (parsedPacket.isPacketOfType(pcpp::GRE))
127
15.2k
  {
128
15.2k
    if (auto greLayer = dynamic_cast<pcpp::GreLayer*>(layer))
129
3.39k
    {
130
3.39k
      uint32_t value32 = 0;
131
3.39k
      greLayer->getSequenceNumber(value32);
132
3.39k
    }
133
15.2k
  }
134
748k
  if (parsedPacket.isPacketOfType(pcpp::GREv0))
135
8.16k
  {
136
8.16k
    if (auto greLayer = dynamic_cast<pcpp::GREv0Layer*>(layer))
137
1.72k
    {
138
1.72k
      uint16_t value16 = 0;
139
1.72k
      greLayer->getChecksum(value16);
140
1.72k
      greLayer->getOffset(value16);
141
1.72k
      uint32_t value32 = 0;
142
1.72k
      greLayer->getKey(value32);
143
1.72k
    }
144
8.16k
  }
145
748k
  if (parsedPacket.isPacketOfType(pcpp::GREv1))
146
7.13k
  {
147
7.13k
    if (auto greLayer = dynamic_cast<pcpp::GREv1Layer*>(layer))
148
1.66k
    {
149
1.66k
      uint32_t value32 = 0;
150
1.66k
      greLayer->getAcknowledgmentNum(value32);
151
1.66k
    }
152
7.13k
  }
153
748k
  if (parsedPacket.isPacketOfType(pcpp::FTP))
154
11.2k
  {
155
11.2k
    if (auto ftpLayer = dynamic_cast<pcpp::FtpRequestLayer*>(layer))
156
741
    {
157
741
      ftpLayer->getCommandOption(false);
158
741
      ftpLayer->getCommandOption(true);
159
741
    }
160
10.5k
    else if (auto ftpLayer = dynamic_cast<pcpp::FtpResponseLayer*>(layer))
161
1.68k
    {
162
1.68k
      ftpLayer->getStatusCode();
163
1.68k
      ftpLayer->getStatusOption(false);
164
1.68k
      ftpLayer->getStatusOption(true);
165
1.68k
    }
166
11.2k
  }
167
748k
  if (parsedPacket.isPacketOfType(pcpp::SLL2))
168
4.80k
  {
169
4.80k
    if (auto sllLayer = dynamic_cast<pcpp::Sll2Layer*>(layer))
170
1.54k
    {
171
1.54k
      sllLayer->getLinkLayerAsMacAddress();
172
1.54k
      sllLayer->getProtocolType();
173
1.54k
      sllLayer->getInterfaceIndex();
174
1.54k
      sllLayer->getArphrdType();
175
1.54k
      sllLayer->getPacketType();
176
1.54k
    }
177
4.80k
  }
178
748k
  if (parsedPacket.isPacketOfType(pcpp::VRRP))
179
18.2k
  {
180
18.2k
    if (auto vrrpLayer = dynamic_cast<pcpp::VrrpLayer*>(layer))
181
5.41k
    {
182
5.41k
      vrrpLayer->getIPAddresses();
183
5.41k
      vrrpLayer->isChecksumCorrect();
184
5.41k
      vrrpLayer->getChecksum();
185
5.41k
      vrrpLayer->getPriorityAsEnum();
186
5.41k
      vrrpLayer->getPriority();
187
5.41k
      vrrpLayer->getType();
188
5.41k
    }
189
18.2k
  }
190
748k
  if (parsedPacket.isPacketOfType(pcpp::VRRPv2))
191
7.03k
  {
192
7.03k
    if (auto vrrpLayer = dynamic_cast<pcpp::VrrpV2Layer*>(layer))
193
1.97k
    {
194
1.97k
      vrrpLayer->getAuthTypeAsEnum();
195
1.97k
      vrrpLayer->getAdvInt();
196
1.97k
    }
197
7.03k
  }
198
748k
  if (parsedPacket.isPacketOfType(pcpp::VRRPv3))
199
11.1k
  {
200
11.1k
    if (auto vrrpLayer = dynamic_cast<pcpp::VrrpV3Layer*>(layer))
201
3.43k
    {
202
3.43k
      vrrpLayer->getMaxAdvInt();
203
3.43k
    }
204
11.1k
  }
205
748k
  if (parsedPacket.isPacketOfType(pcpp::TCP))
206
496k
  {
207
496k
    if (auto tcpLayer = dynamic_cast<pcpp::TcpLayer*>(layer))
208
121k
    {
209
121k
      auto tcpLayer2(*tcpLayer);
210
121k
      tcpLayer2.insertTcpOptionAfter(pcpp::TcpOptionBuilder(pcpp::TcpOptionBuilder::NopEolOptionEnumType::Nop),
211
121k
                                     pcpp::TcpOptionEnumType::Nop);
212
121k
    }
213
496k
  }
214
748k
  if (parsedPacket.isPacketOfType(pcpp::SDP))
215
3.62k
  {
216
3.62k
    if (auto sdpLayer = dynamic_cast<pcpp::SdpLayer*>(layer))
217
645
    {
218
645
      sdpLayer->getOwnerIPv4Address();
219
645
      sdpLayer->getMediaPort("audio");
220
645
      sdpLayer->getFieldCount();
221
222
645
      auto sdpLayer2 = *sdpLayer;
223
645
      std::vector<std::string> audioAttributes;
224
645
      audioAttributes.push_back("rtpmap:8 PCMA/8000");
225
645
      sdpLayer2.addMediaDescription("audio", 6010, "RTP/AVP", "8 96", audioAttributes);
226
645
      sdpLayer2.addField(PCPP_SDP_PROTOCOL_VERSION_FIELD, "0");
227
645
      sdpLayer2.removeField(PCPP_SDP_PROTOCOL_VERSION_FIELD);
228
645
    }
229
3.62k
  }
230
748k
  if (parsedPacket.isPacketOfType(pcpp::SSL))
231
180k
  {
232
180k
    if (auto handshakeLayer = dynamic_cast<pcpp::SSLHandshakeLayer*>(layer))
233
12.7k
    {
234
12.7k
      if (auto clientHelloMessage = handshakeLayer->getHandshakeMessageOfType<pcpp::SSLClientHelloMessage>())
235
6.13k
      {
236
6.13k
        clientHelloMessage->getCompressionMethodsValue();
237
6.13k
        clientHelloMessage->getSessionID();
238
6.13k
        clientHelloMessage->getHandshakeType();
239
6.13k
        clientHelloMessage->getHandshakeVersion();
240
241
6.13k
        pcpp::SSLCipherSuite::getCipherSuiteByName("TLS_RSA_WITH_NULL_MD5");
242
1.48M
        for (int i = 0; i < clientHelloMessage->getCipherSuiteCount(); i++)
243
1.47M
        {
244
1.47M
          clientHelloMessage->getCipherSuite(i);
245
1.47M
          bool valid;
246
1.47M
          clientHelloMessage->getCipherSuiteID(i, valid);
247
1.47M
        }
248
6.13k
        if (auto ext = clientHelloMessage->getExtensionOfType<pcpp::SSLServerNameIndicationExtension>())
249
5.39k
          ext->getHostName();
250
6.13k
        if (auto ext = clientHelloMessage->getExtensionOfType<pcpp::SSLSupportedVersionsExtension>())
251
2.00k
          ext->getSupportedVersions();
252
253
6.13k
        clientHelloMessage->getExtensionOfType(pcpp::SSL_EXT_SERVER_NAME);
254
6.13k
        clientHelloMessage->getExtensionOfType((uint16_t)0);
255
256
6.13k
        auto fingerprint = clientHelloMessage->generateTLSFingerprint();
257
6.13k
        fingerprint.toMD5();
258
6.13k
      }
259
12.7k
      if (auto serverHelloMessage = handshakeLayer->getHandshakeMessageOfType<pcpp::SSLServerHelloMessage>())
260
3.67k
      {
261
3.67k
        serverHelloMessage->getCompressionMethodsValue();
262
3.67k
        serverHelloMessage->getSessionID();
263
3.67k
        serverHelloMessage->getCipherSuite();
264
265
3.67k
        serverHelloMessage->getExtensionOfType<pcpp::SSLServerNameIndicationExtension>();
266
3.67k
        serverHelloMessage->getExtensionOfType(pcpp::SSL_EXT_SERVER_NAME);
267
3.67k
        serverHelloMessage->getExtensionOfType((uint16_t)0);
268
269
3.67k
        serverHelloMessage->getHandshakeVersion();
270
3.67k
        auto fingerprint = serverHelloMessage->generateTLSFingerprint();
271
3.67k
        fingerprint.toMD5();
272
3.67k
      }
273
12.7k
      if (auto handshakeMessage = handshakeLayer->getHandshakeMessageOfType<pcpp::SSLHandshakeMessage>())
274
12.5k
      {
275
12.5k
        handshakeMessage->isMessageComplete();
276
12.5k
      }
277
12.7k
    }
278
180k
  }
279
748k
  if (parsedPacket.isPacketOfType(pcpp::NTP))
280
2.83k
  {
281
2.83k
    if (auto ntpLayer = dynamic_cast<pcpp::NtpLayer*>(layer))
282
504
    {
283
504
      ntpLayer->getLeapIndicator();
284
504
      ntpLayer->getMode();
285
504
      ntpLayer->getModeString();
286
504
      ntpLayer->getStratum();
287
504
      ntpLayer->getPollInterval();
288
504
      ntpLayer->getPrecision();
289
504
      ntpLayer->getRootDelay();
290
504
      ntpLayer->getRootDispersion();
291
504
      ntpLayer->getReferenceIdentifier();
292
504
      ntpLayer->getReferenceIdentifierString();
293
504
      ntpLayer->getReferenceTimestamp();
294
504
      ntpLayer->getOriginTimestamp();
295
504
      ntpLayer->getReceiveTimestamp();
296
504
      ntpLayer->getTransmitTimestamp();
297
298
504
      ntpLayer->getDigest();
299
504
      ntpLayer->getKeyID();
300
301
504
      ntpLayer->getPollIntervalInSecs();
302
504
      ntpLayer->getPrecisionInSecs();
303
504
      ntpLayer->getRootDelayInSecs();
304
504
      ntpLayer->getRootDispersionInSecs();
305
504
      ntpLayer->getReferenceTimestampInSecs();
306
504
      ntpLayer->getOriginTimestampInSecs();
307
504
      ntpLayer->getReceiveTimestampInSecs();
308
504
      ntpLayer->getTransmitTimestampInSecs();
309
310
504
      ntpLayer->getReferenceTimestampAsString();
311
504
      ntpLayer->getOriginTimestampAsString();
312
504
      ntpLayer->getReceiveTimestampAsString();
313
504
      ntpLayer->getTransmitTimestampAsString();
314
315
504
      auto ntpLayer2(*ntpLayer);
316
504
      ntpLayer2.setRootDelayInSecs(0.1);
317
504
      ntpLayer2.setReferenceTimestampInSecs(0.1);
318
504
    }
319
2.83k
  }
320
748k
  if (parsedPacket.isPacketOfType(pcpp::ICMP))
321
10.7k
  {
322
10.7k
    if (auto icmpLayer = dynamic_cast<pcpp::IcmpLayer*>(layer))
323
2.20k
    {
324
2.20k
      auto icmpLayer2(*icmpLayer);
325
326
2.20k
      if (icmpLayer->isMessageOfType(pcpp::ICMP_TIMESTAMP_REPLY))
327
0
      {
328
0
        icmpLayer->getTimestampReplyData();
329
0
        timeval orig = { 16131, 171000 };
330
0
        timeval recv = { 16133, 474000 };
331
0
        timeval tran = { 16133, 474000 };
332
0
        icmpLayer2.setTimestampReplyData(14640, 0, orig, recv, tran);
333
0
      }
334
2.20k
      else if (icmpLayer->isMessageOfType(pcpp::ICMP_ADDRESS_MASK_REQUEST))
335
0
      {
336
0
        icmpLayer->getAddressMaskRequestData();
337
0
        icmpLayer2.setAddressMaskRequestData(45068, 1536, pcpp::IPv4Address::Zero);
338
0
      }
339
2.20k
      else if (icmpLayer->isMessageOfType(pcpp::ICMP_ADDRESS_MASK_REPLY))
340
160
      {
341
160
        icmpLayer->getAddressMaskReplyData();
342
160
        icmpLayer2.setAddressMaskReplyData(45068, 1536, pcpp::IPv4Address::Zero);
343
160
      }
344
2.04k
      else if (icmpLayer->isMessageOfType(pcpp::ICMP_DEST_UNREACHABLE))
345
400
      {
346
400
        icmpLayer->getDestUnreachableData();
347
400
        icmpLayer2.setDestUnreachableData(pcpp::IcmpHostUnreachable, 0, nullptr, nullptr);
348
400
      }
349
1.64k
      else if (icmpLayer->isMessageOfType(pcpp::ICMP_INFO_REPLY))
350
0
      {
351
0
        auto layerData = icmpLayer->getInfoReplyData();
352
0
        icmpLayer2.setInfoReplyData(layerData->id, layerData->sequence);
353
0
      }
354
1.64k
      else if (icmpLayer->isMessageOfType(pcpp::ICMP_INFO_REQUEST))
355
0
      {
356
0
        auto layerData = icmpLayer->getInfoRequestData();
357
0
        icmpLayer2.setInfoRequestData(layerData->id, layerData->sequence);
358
0
      }
359
1.64k
      else if (icmpLayer->isMessageOfType(pcpp::ICMP_PARAM_PROBLEM))
360
64
      {
361
64
        auto layerData = icmpLayer->getParamProblemData();
362
64
        icmpLayer2.setParamProblemData(layerData->code, layerData->pointer, nullptr, nullptr);
363
64
      }
364
1.58k
      else if (icmpLayer->isMessageOfType(pcpp::ICMP_TIME_EXCEEDED))
365
102
      {
366
102
        icmpLayer->getTimeExceededData();
367
102
        icmpLayer2.setTimeExceededData(1, nullptr, nullptr);
368
102
      }
369
1.47k
      else if (icmpLayer->isMessageOfType(pcpp::ICMP_ROUTER_ADV))
370
0
      {
371
0
        icmpLayer->getRouterAdvertisementData();
372
0
        pcpp::icmp_router_address_structure addr1;
373
0
        addr1.setRouterAddress(pcpp::IPv4Address("192.168.144.2"), (uint32_t)0x08000000);
374
0
        std::vector<pcpp::icmp_router_address_structure> routerAddresses;
375
0
        routerAddresses.push_back(addr1);
376
0
        icmpLayer2.setRouterAdvertisementData(16, 200, routerAddresses);
377
0
      }
378
2.20k
    }
379
10.7k
  }
380
748k
  if (parsedPacket.isPacketOfType(pcpp::DHCPv6))
381
1.04k
  {
382
1.04k
    if (auto dhcpLayer = dynamic_cast<pcpp::DhcpV6Layer*>(layer))
383
260
    {
384
260
      dhcpLayer->getTransactionID();
385
260
      if (dhcpLayer->getOptionCount() > 0)
386
252
      {
387
252
        pcpp::DhcpV6Option opt = dhcpLayer->getFirstOptionData();
388
252
        opt.getType();
389
252
        opt.getTotalSize();
390
252
        opt.getValueAsHexString();
391
2.93k
        for (size_t i = 0; i < dhcpLayer->getOptionCount(); i++)
392
2.68k
        {
393
2.68k
          opt = dhcpLayer->getNextOptionData(opt);
394
2.68k
        }
395
252
        dhcpLayer->getOptionData(pcpp::DHCPV6_OPT_CLIENTID);
396
252
      }
397
260
    }
398
1.04k
  }
399
748k
  if (parsedPacket.isPacketOfType(pcpp::DHCP))
400
14.6k
  {
401
14.6k
    if (auto dhcpLayer = dynamic_cast<pcpp::DhcpLayer*>(layer))
402
3.15k
    {
403
3.15k
      dhcpLayer->getOpCode();
404
3.15k
      dhcpLayer->getDhcpHeader();
405
3.15k
      dhcpLayer->getClientIpAddress();
406
3.15k
      dhcpLayer->getYourIpAddress();
407
3.15k
      dhcpLayer->getServerIpAddress();
408
3.15k
      dhcpLayer->getGatewayIpAddress();
409
3.15k
      dhcpLayer->getClientHardwareAddress();
410
3.15k
      if (dhcpLayer->getOptionsCount() > 0)
411
3.10k
      {
412
3.10k
        pcpp::DhcpOption opt = dhcpLayer->getFirstOptionData();
413
3.10k
        opt.getValueAsIpAddr();
414
3.10k
        opt.getValueAsString();
415
236k
        for (size_t i = 0; i < dhcpLayer->getOptionsCount(); i++)
416
233k
        {
417
233k
          opt = dhcpLayer->getNextOptionData(opt);
418
233k
        }
419
3.10k
      }
420
3.15k
      dhcpLayer->getOptionData(pcpp::DHCPOPT_SUBNET_MASK);
421
3.15k
    }
422
14.6k
  }
423
748k
  if (parsedPacket.isPacketOfType(pcpp::BGP))
424
18.1k
  {
425
18.1k
    if (auto bgpLayer = dynamic_cast<pcpp::BgpLayer*>(layer))
426
5.10k
    {
427
5.10k
      bgpLayer->getMessageTypeAsString();
428
5.10k
      if (auto bgpOpenMsgLayer = dynamic_cast<pcpp::BgpOpenMessageLayer*>(bgpLayer))
429
677
      {
430
677
        std::vector<pcpp::BgpOpenMessageLayer::optional_parameter> optionalParams;
431
677
        bgpOpenMsgLayer->getOptionalParameters(optionalParams);
432
677
        std::vector<pcpp::BgpOpenMessageLayer::optional_parameter> optionalParams2(optionalParams);
433
677
        optionalParams2.push_back(pcpp::BgpOpenMessageLayer::optional_parameter(2, "010400010001"));
434
677
        optionalParams2.push_back(pcpp::BgpOpenMessageLayer::optional_parameter(2, "8000"));
435
677
        optionalParams2.push_back(pcpp::BgpOpenMessageLayer::optional_parameter(2, "0200"));
436
677
        optionalParams2.push_back(pcpp::BgpOpenMessageLayer::optional_parameter(2, "4600"));
437
677
        optionalParams2.push_back(pcpp::BgpOpenMessageLayer::optional_parameter(2, "410400000001"));
438
677
        bgpOpenMsgLayer->setOptionalParameters(optionalParams2);
439
677
        bgpOpenMsgLayer->clearOptionalParameters();
440
677
        bgpOpenMsgLayer->setOptionalParameters(optionalParams);
441
677
      }
442
4.42k
      else if (auto bgpUpdateMsgLayer = dynamic_cast<pcpp::BgpUpdateMessageLayer*>(bgpLayer))
443
3.74k
      {
444
3.74k
        std::vector<pcpp::BgpUpdateMessageLayer::prefix_and_ip> withdrawnRoutes;
445
3.74k
        bgpUpdateMsgLayer->getWithdrawnRoutes(withdrawnRoutes);
446
3.74k
        std::vector<pcpp::BgpUpdateMessageLayer::prefix_and_ip> withdrawnRoutes2(withdrawnRoutes);
447
3.74k
        withdrawnRoutes2.push_back(pcpp::BgpUpdateMessageLayer::prefix_and_ip(24, "40.1.1.0"));
448
3.74k
        withdrawnRoutes2.push_back(pcpp::BgpUpdateMessageLayer::prefix_and_ip(24, "40.40.40.0"));
449
3.74k
        withdrawnRoutes2.push_back(pcpp::BgpUpdateMessageLayer::prefix_and_ip(16, "103.103.0.0"));
450
3.74k
        withdrawnRoutes2.push_back(pcpp::BgpUpdateMessageLayer::prefix_and_ip(24, "103.103.40.0"));
451
3.74k
        bgpUpdateMsgLayer->setWithdrawnRoutes(withdrawnRoutes2);
452
3.74k
        bgpUpdateMsgLayer->clearWithdrawnRoutes();
453
3.74k
        bgpUpdateMsgLayer->setWithdrawnRoutes(withdrawnRoutes);
454
455
3.74k
        std::vector<pcpp::BgpUpdateMessageLayer::prefix_and_ip> nlriVec;
456
3.74k
        bgpUpdateMsgLayer->getNetworkLayerReachabilityInfo(nlriVec);
457
3.74k
        std::vector<pcpp::BgpUpdateMessageLayer::prefix_and_ip> nlriVec2(nlriVec);
458
3.74k
        nlriVec2.push_back(pcpp::BgpUpdateMessageLayer::prefix_and_ip(24, "40.1.1.0"));
459
3.74k
        bgpUpdateMsgLayer->setNetworkLayerReachabilityInfo(nlriVec2);
460
3.74k
        bgpUpdateMsgLayer->clearNetworkLayerReachabilityInfo();
461
3.74k
        bgpUpdateMsgLayer->setNetworkLayerReachabilityInfo(nlriVec);
462
463
3.74k
        std::vector<pcpp::BgpUpdateMessageLayer::path_attribute> pathAttributes;
464
3.74k
        bgpUpdateMsgLayer->getPathAttributes(pathAttributes);
465
3.74k
        std::vector<pcpp::BgpUpdateMessageLayer::path_attribute> pathAttributes2(pathAttributes);
466
3.74k
        pathAttributes2.push_back(pcpp::BgpUpdateMessageLayer::path_attribute(0x40, 1, "02"));
467
3.74k
        pathAttributes2.push_back(
468
3.74k
            pcpp::BgpUpdateMessageLayer::path_attribute(0x40, 2, "02030000000a0000001400000028"));
469
3.74k
        pathAttributes2.push_back(pcpp::BgpUpdateMessageLayer::path_attribute(0x40, 3, "1e031e03"));
470
3.74k
        bgpUpdateMsgLayer->setPathAttributes(pathAttributes2);
471
3.74k
        bgpUpdateMsgLayer->clearPathAttributes();
472
3.74k
        bgpUpdateMsgLayer->setPathAttributes(pathAttributes);
473
3.74k
      }
474
684
      else if (auto bgpNotificationMsgLayer = dynamic_cast<pcpp::BgpNotificationMessageLayer*>(bgpLayer))
475
0
      {
476
0
        bgpNotificationMsgLayer->getNotificationDataAsHexString();
477
0
      }
478
5.10k
    }
479
18.1k
  }
480
748k
  if (parsedPacket.isPacketOfType(pcpp::DNS))
481
39.5k
  {
482
39.5k
    if (auto dnsLayer = dynamic_cast<pcpp::DnsLayer*>(layer))
483
9.89k
    {
484
9.89k
      dnsLayer->addQuery("mail-attachment.googleusercontent.com", pcpp::DNS_TYPE_A, pcpp::DNS_CLASS_IN);
485
9.89k
      dnsLayer->removeQuery("a", true);
486
9.89k
      dnsLayer->removeQuery("mail-attachment.googleusercontent.com", false);
487
9.89k
      pcpp::IPv4DnsResourceData ipv4DnsData(std::string("151.249.90.217"));
488
9.89k
      dnsLayer->addAnswer("assets.pinterest.com.cdngc.net", pcpp::DNS_TYPE_A, pcpp::DNS_CLASS_IN, 3,
489
9.89k
                          &ipv4DnsData);
490
9.89k
      dnsLayer->removeAnswer("a", true);
491
9.89k
      dnsLayer->removeAnswer("assets.pinterest.com.cdngc.net", false);
492
9.89k
      dnsLayer->addAuthority("Yaels-iPhone.local", pcpp::DNS_TYPE_A, pcpp::DNS_CLASS_IN, 120, &ipv4DnsData);
493
9.89k
      dnsLayer->removeAuthority("a", true);
494
9.89k
      dnsLayer->removeAuthority("Yaels-iPhone.local", false);
495
9.89k
      pcpp::GenericDnsResourceData genericData("0004000800df581faa4f3f9d");
496
9.89k
      dnsLayer->addAdditionalRecord("abc", pcpp::DNS_TYPE_OPT, 0xa005, 0x1194, &genericData);
497
9.89k
      dnsLayer->removeAdditionalRecord("a", true);
498
9.89k
      dnsLayer->removeAdditionalRecord("abc", false);
499
500
9.89k
      auto add = dnsLayer->getFirstAdditionalRecord();
501
11.0k
      while (add != nullptr)
502
1.19k
      {
503
1.19k
        add = dnsLayer->getNextAdditionalRecord(add);
504
1.19k
      }
505
506
9.89k
      auto answer = dnsLayer->getFirstAnswer();
507
17.4k
      while (answer != nullptr)
508
7.58k
      {
509
7.58k
        answer = dnsLayer->getNextAnswer(answer);
510
7.58k
      }
511
512
9.89k
      auto auth = dnsLayer->getFirstAuthority();
513
10.3k
      while (auth != nullptr)
514
435
      {
515
435
        auth = dnsLayer->getNextAuthority(auth);
516
435
      }
517
518
9.89k
      pcpp::DnsLayer other(*dnsLayer);
519
9.89k
      other = *dnsLayer;
520
9.89k
    }
521
39.5k
  }
522
748k
}