Coverage Report

Created: 2026-06-10 07:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PcapPlusPlus/Packet++/src/CotpLayer.cpp
Line
Count
Source
1
#include "../header/CotpLayer.h"
2
#include "S7CommLayer.h"
3
#include <PayloadLayer.h>
4
5
#include <cstring>
6
7
namespace pcpp
8
{
9
10
  pcpp::CotpLayer::CotpLayer(uint8_t tpduNumber)
11
0
  {
12
0
    const size_t headerLen = sizeof(cotphdr);
13
0
    m_DataLen = headerLen;
14
0
    m_Data = new uint8_t[headerLen];
15
0
    memset(m_Data, 0, headerLen);
16
0
    cotphdr* cotpHdr = getCotpHeader();
17
0
    cotpHdr->length = 0x02;
18
0
    cotpHdr->pduType = 0x0f;
19
0
    cotpHdr->tpduNumber = tpduNumber;
20
0
    m_Protocol = COTP;
21
0
  }
22
23
  std::string CotpLayer::toString() const
24
6.47k
  {
25
6.47k
    return "Cotp Layer";
26
6.47k
  }
27
28
  uint8_t CotpLayer::getLength() const
29
0
  {
30
0
    return getCotpHeader()->length;
31
0
  }
32
33
  uint8_t CotpLayer::getPduType() const
34
0
  {
35
0
    return getCotpHeader()->pduType;
36
0
  }
37
38
  uint8_t CotpLayer::getTpduNumber() const
39
0
  {
40
0
    return getCotpHeader()->tpduNumber;
41
0
  }
42
43
  void CotpLayer::setLength(uint8_t length) const
44
0
  {
45
0
    getCotpHeader()->length = length;
46
0
  }
47
48
  void CotpLayer::setPduType(uint8_t pduType) const
49
0
  {
50
0
    getCotpHeader()->pduType = pduType;
51
0
  }
52
53
  void CotpLayer::setTpduNumber(uint8_t tpduNumber) const
54
0
  {
55
0
    getCotpHeader()->tpduNumber = tpduNumber;
56
0
  }
57
58
  bool CotpLayer::isDataValid(const uint8_t* data, size_t dataSize)
59
25.3k
  {
60
25.3k
    if (!data || dataSize < sizeof(cotphdr))
61
15
      return false;
62
63
25.2k
    return data[1] == 0xf0 && data[0] == 2;
64
25.3k
  }
65
66
  void CotpLayer::parseNextLayer()
67
22.9k
  {
68
22.9k
    size_t headerLen = getHeaderLen();
69
22.9k
    if (m_DataLen <= headerLen)
70
5.63k
      return;
71
72
17.2k
    uint8_t* payload = m_Data + headerLen;
73
17.2k
    size_t payloadLen = m_DataLen - headerLen;
74
75
17.2k
    tryConstructNextLayerWithFallback<S7CommLayer, PayloadLayer>(payload, payloadLen);
76
17.2k
  }
77
}  // namespace pcpp