Skip to content

Commit

Permalink
sniffer: fix mangled lines on stdout output
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmouchet committed Jan 6, 2024
1 parent 4764ae4 commit aed264c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 0 additions & 1 deletion apps/caracal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ int main(int argc, char** argv) {
spdlog::set_default_logger(spdlog::stderr_color_st(""));

spdlog::info("Reading from stdin, press CTRL+D to stop...");
std::ios::sync_with_stdio(false);
caracal::Prober::probe(config, std::cin);
} catch (const std::exception& e) {
auto type = caracal::Utilities::demangle(typeid(e).name());
Expand Down
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 aed264c

Please sign in to comment.