Skip to content

Commit 695b1cd

Browse files
authored
c++ migration (#1959)
1 parent 3c37937 commit 695b1cd

File tree

21 files changed

+91
-82
lines changed

21 files changed

+91
-82
lines changed

Common++/src/IpUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,11 @@ int inet_pton(int af, const char* src, void* dst)
443443
{
444444
# ifdef AF_INET
445445
case AF_INET:
446-
return (inet_pton4(src, (uint8_t*)dst));
446+
return (inet_pton4(src, static_cast<uint8_t*>(dst)));
447447
# endif
448448
# ifdef AF_INET6
449449
case AF_INET6:
450-
return (inet_pton6(src, (uint8_t*)dst));
450+
return (inet_pton6(src, static_cast<uint8_t*>(dst)));
451451
# endif
452452
default:
453453
return (-1);

Examples/DnsSpoofing/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ bool stringCountComparer(const std::pair<std::string, int>& first, const std::pa
264264
void onApplicationInterrupted(void* cookie)
265265
{
266266
DnsSpoofingArgs* args = (DnsSpoofingArgs*)cookie;
267-
if (args->stats.spoofedHosts.size() == 0)
267+
if (args->stats.spoofedHosts.empty())
268268
{
269269
std::cout << std::endl << "Application closing. No hosts were spoofed." << std::endl;
270270
}

Examples/DpdkExample-FilterTraffic/Common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
exit(1); \
3232
} while (0)
3333

34-
typedef std::unordered_map<pcpp::DpdkDevice*, std::vector<int>> InputDataConfig;
34+
using InputDataConfig = std::unordered_map<pcpp::DpdkDevice*, std::vector<int>>;
3535

3636
/**
3737
* Contains all the configuration needed for the worker thread including:

Examples/DpdkExample-FilterTraffic/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void prepareCoreConfiguration(std::vector<pcpp::DpdkDevice*>& dpdkDevicesToUse,
221221
}
222222
std::cout << std::endl;
223223
}
224-
if (workerConfigArr[i].inDataCfg.size() == 0)
224+
if (workerConfigArr[i].inDataCfg.empty())
225225
{
226226
std::cout << " None" << std::endl;
227227
}

Examples/TLSFingerprinting/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ void printStats(const TLSFingerprintingStats& stats, bool chFP, bool shFP)
297297
// write a table of the 10 most common TLS fingerprints
298298

299299
// if user requested to extract ClientHello TLS fingerprints and there is data to show
300-
if (chFP && stats.chFingerprints.size() > 0)
300+
if (chFP && !stats.chFingerprints.empty())
301301
{
302302
if (stats.chFingerprints.size() > 10)
303303
std::cout << "Top 10 ";
@@ -309,7 +309,7 @@ void printStats(const TLSFingerprintingStats& stats, bool chFP, bool shFP)
309309
}
310310

311311
// if user requested to extract ServerHello TLS fingerprints and there is data to show
312-
if (shFP && stats.shFingerprints.size() > 0)
312+
if (shFP && !stats.shFingerprints.empty())
313313
{
314314
if (stats.shFingerprints.size() > 10)
315315
std::cout << "Top 10 ";

Examples/TcpReassembly/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ struct TcpReassemblyData
276276
}
277277
};
278278

279-
// typedef representing the connection manager
280-
typedef std::unordered_map<uint32_t, TcpReassemblyData> TcpReassemblyConnMgr;
279+
// using declaration representing the connection manager
280+
using TcpReassemblyConnMgr = std::unordered_map<uint32_t, TcpReassemblyData>;
281281

282282
/**
283283
* Print application usage

Packet++/src/DnsLayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace pcpp
101101
dnshdr* DnsLayer::getDnsHeader() const
102102
{
103103
uint8_t* ptr = m_Data + m_OffsetAdjustment;
104-
return (dnshdr*)ptr;
104+
return reinterpret_cast<dnshdr*>(ptr);
105105
}
106106

107107
bool DnsLayer::extendLayer(int offsetInLayer, size_t numOfBytesToExtend, IDnsResource* resource)

Packet++/src/HttpLayer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ namespace pcpp
118118
if (size <= maxLengthToPrint)
119119
{
120120
char* firstLine = new char[size + 1];
121-
strncpy(firstLine, (char*)m_Data, size);
121+
strncpy(firstLine, reinterpret_cast<char*>(m_Data), size);
122122
firstLine[size] = 0;
123123
result += std::string(firstLine);
124124
delete[] firstLine;
125125
}
126126
else
127127
{
128128
char firstLine[maxLengthToPrint + 1];
129-
strncpy(firstLine, (char*)m_Data, maxLengthToPrint - 3);
129+
strncpy(firstLine, reinterpret_cast<char*>(m_Data), maxLengthToPrint - 3);
130130
firstLine[maxLengthToPrint - 3] = '.';
131131
firstLine[maxLengthToPrint - 2] = '.';
132132
firstLine[maxLengthToPrint - 1] = '.';
@@ -743,15 +743,15 @@ namespace pcpp
743743
if (size <= maxLengthToPrint)
744744
{
745745
char* firstLine = new char[size + 1];
746-
strncpy(firstLine, (char*)m_Data, size);
746+
strncpy(firstLine, reinterpret_cast<char*>(m_Data), size);
747747
firstLine[size] = 0;
748748
result += std::string(firstLine);
749749
delete[] firstLine;
750750
}
751751
else
752752
{
753753
char firstLine[maxLengthToPrint + 1];
754-
strncpy(firstLine, (char*)m_Data, maxLengthToPrint - 3);
754+
strncpy(firstLine, reinterpret_cast<char*>(m_Data), maxLengthToPrint - 3);
755755
firstLine[maxLengthToPrint - 3] = '.';
756756
firstLine[maxLengthToPrint - 2] = '.';
757757
firstLine[maxLengthToPrint - 1] = '.';

Packet++/src/IPReassembly.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ namespace pcpp
1414
{
1515
ScalarBuffer<uint8_t> vec[3];
1616

17-
vec[0].buffer = (uint8_t*)&ipv4Layer->getIPv4Header()->ipSrc;
17+
vec[0].buffer = reinterpret_cast<uint8_t*>(&ipv4Layer->getIPv4Header()->ipSrc);
1818
vec[0].len = 4;
19-
vec[1].buffer = (uint8_t*)&ipv4Layer->getIPv4Header()->ipDst;
19+
vec[1].buffer = reinterpret_cast<uint8_t*>(&ipv4Layer->getIPv4Header()->ipDst);
2020
vec[1].len = 4;
21-
vec[2].buffer = (uint8_t*)&ipv4Layer->getIPv4Header()->ipId;
21+
vec[2].buffer = reinterpret_cast<uint8_t*>(&ipv4Layer->getIPv4Header()->ipId);
2222
vec[2].len = 2;
2323

2424
return pcpp::fnvHash(vec, 3);
@@ -32,11 +32,11 @@ namespace pcpp
3232
uint32_t ipSrcAsInt = ipSrc.toInt();
3333
uint32_t ipDstAsInt = ipDst.toInt();
3434

35-
vec[0].buffer = (uint8_t*)&ipSrcAsInt;
35+
vec[0].buffer = reinterpret_cast<uint8_t*>(&ipSrcAsInt);
3636
vec[0].len = 4;
37-
vec[1].buffer = (uint8_t*)&ipDstAsInt;
37+
vec[1].buffer = reinterpret_cast<uint8_t*>(&ipDstAsInt);
3838
vec[1].len = 4;
39-
vec[2].buffer = (uint8_t*)&ipIdNetworkOrder;
39+
vec[2].buffer = reinterpret_cast<uint8_t*>(&ipIdNetworkOrder);
4040
vec[2].len = 2;
4141

4242
return pcpp::fnvHash(vec, 3);
@@ -104,11 +104,11 @@ namespace pcpp
104104
{
105105
ScalarBuffer<uint8_t> vec[3];
106106

107-
vec[0].buffer = (uint8_t*)&m_IPLayer->getIPv4Header()->ipSrc;
107+
vec[0].buffer = reinterpret_cast<uint8_t*>(&m_IPLayer->getIPv4Header()->ipSrc);
108108
vec[0].len = 4;
109-
vec[1].buffer = (uint8_t*)&m_IPLayer->getIPv4Header()->ipDst;
109+
vec[1].buffer = reinterpret_cast<uint8_t*>(&m_IPLayer->getIPv4Header()->ipDst);
110110
vec[1].len = 4;
111-
vec[2].buffer = (uint8_t*)&m_IPLayer->getIPv4Header()->ipId;
111+
vec[2].buffer = reinterpret_cast<uint8_t*>(&m_IPLayer->getIPv4Header()->ipId);
112112
vec[2].len = 2;
113113

114114
return pcpp::fnvHash(vec, 3);
@@ -198,7 +198,7 @@ namespace pcpp
198198
vec[0].len = 16;
199199
vec[1].buffer = m_IPLayer->getIPv6Header()->ipDst;
200200
vec[1].len = 16;
201-
vec[2].buffer = (uint8_t*)&m_FragHeader->getFragHeader()->id;
201+
vec[2].buffer = reinterpret_cast<uint8_t*>(&m_FragHeader->getFragHeader()->id);
202202
vec[2].len = 4;
203203

204204
return pcpp::fnvHash(vec, 3);
@@ -238,11 +238,11 @@ namespace pcpp
238238
uint32_t ipSrcAsInt = m_SrcIP.toInt();
239239
uint32_t ipDstAsInt = m_DstIP.toInt();
240240

241-
vec[0].buffer = (uint8_t*)&ipSrcAsInt;
241+
vec[0].buffer = reinterpret_cast<uint8_t*>(&ipSrcAsInt);
242242
vec[0].len = 4;
243-
vec[1].buffer = (uint8_t*)&ipDstAsInt;
243+
vec[1].buffer = reinterpret_cast<uint8_t*>(&ipDstAsInt);
244244
vec[1].len = 4;
245-
vec[2].buffer = (uint8_t*)&ipIdNetworkOrder;
245+
vec[2].buffer = reinterpret_cast<uint8_t*>(&ipIdNetworkOrder);
246246
vec[2].len = 2;
247247

248248
return pcpp::fnvHash(vec, 3);
@@ -262,7 +262,7 @@ namespace pcpp
262262
vec[0].len = 16;
263263
vec[1].buffer = ipDstAsByteArr;
264264
vec[1].len = 16;
265-
vec[2].buffer = (uint8_t*)&fragIdNetworkOrder;
265+
vec[2].buffer = reinterpret_cast<uint8_t*>(&fragIdNetworkOrder);
266266
vec[2].len = 4;
267267

268268
return pcpp::fnvHash(vec, 3);

Packet++/src/ModbusLayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace pcpp
2727

2828
modbus_header* ModbusLayer::getModbusHeader() const
2929
{
30-
return (modbus_header*)m_Data;
30+
return reinterpret_cast<modbus_header*>(m_Data);
3131
}
3232

3333
uint16_t ModbusLayer::getTransactionId() const

0 commit comments

Comments
 (0)