-
Notifications
You must be signed in to change notification settings - Fork 683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port tutorial codes to C++11, fixing issue #977 partially #1358
Conversation
d0b42cd
to
298e60e
Compare
columnLengths.push_back(15); | ||
columnLengths.push_back(15); | ||
columnLengths.push_back(15); | ||
std::vector<std::string> columnNames = {" ", "Total Packets", "Packets/sec", "Bytes", "Bits/sec"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good.
@@ -74,7 +72,7 @@ struct PacketStats | |||
static void onPacketArrives(pcpp::RawPacket* packet, pcpp::PcapLiveDevice* dev, void* cookie) | |||
{ | |||
// extract the stats object form the cookie | |||
PacketStats* stats = (PacketStats*)cookie; | |||
auto* stats = static_cast<PacketStats*>(cookie); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto
here make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, the sensible thing here is to use static casting instead of c-style casting.
|
||
if (dev->getDnsServers().size() > 0) | ||
std::cout << " DNS server: " << dev->getDnsServers().at(0) << std::endl; | ||
if (!dev->getDnsServers().empty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice.
{ | ||
workersCoreMask = workersCoreMask | (1 << i); | ||
} | ||
int workersCoreMask = 0x06; // Binary 110, using cores 1 and 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is cleaner but I'm not sure it is more beginner friendly. The for-loop implementation shows that people might set mask by using bit shifting but the updated version only shows as a constant. Since this is a tutorial code, I'm not sure which one is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
92e80a7
to
41db8c4
Compare
@merttozer thank you so much for working on it, much appreciated! 🙏 ❤️ |
This pull request introduces updates to the PcapPlusPlus tutorial codes, transitioning them to utilize C++11 features for improved performance and readability. The changes align with modern C++ standards and address the requirements specified in Issue #977.
Key Changes:
Testing: