Skip to content

Commit

Permalink
sniffer: fix mangled newlines on stdout output (attempt #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmouchet committed Jan 6, 2024
1 parent 4764ae4 commit 4c32f44
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/sniffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <filesystem>
#include <iostream>
#include <optional>
#include <syncstream>
#include <thread>

namespace fs = std::filesystem;
Expand Down Expand Up @@ -70,14 +71,15 @@ void Sniffer::start() noexcept {
std::cout << (Reply::csv_header() + "\n");
auto handler = [this](Tins::Packet &packet) {
auto reply = Parser::parse(packet);
auto stdout = std::osyncstream(std::cout);

if (reply && (!integrity_check_ || reply->is_valid(caracal_id_))) {
spdlog::trace(reply.value());
statistics_.icmp_messages_all.insert(reply->reply_src_addr);
if (reply->is_time_exceeded()) {
statistics_.icmp_messages_path.insert(reply->reply_src_addr);
}
std::cout << (reply->to_csv(meta_round_.value_or("1")) + "\n");
stdout << reply->to_csv(meta_round_.value_or("1")) << "\n";
} else {
auto data = packet.pdu()->serialize();
spdlog::trace("invalid_packet_hex={:02x}", fmt::join(data, ""));
Expand Down

0 comments on commit 4c32f44

Please sign in to comment.