Skip to content

Commit

Permalink
sniffer: fix mangled newlines on stdout output
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmouchet committed Dec 19, 2023
1 parent c3c47a8 commit 3935d40
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
1 change: 0 additions & 1 deletion include/caracal/sniffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Sniffer {

private:
Tins::Sniffer sniffer_;
std::unique_ptr<std::ostream> output_csv_;
std::optional<Tins::PacketWriter> output_pcap_;
std::optional<std::string> meta_round_;
std::thread thread_;
Expand Down
5 changes: 2 additions & 3 deletions src/sniffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ Sniffer::Sniffer(const std::string &interface_name,
// they are captured by pcap.
config.set_timeout(100);
sniffer_ = Tins::Sniffer(interface_name, config);
output_csv_ = std::make_unique<std::ostream>(std::cout.rdbuf());
}

Sniffer::~Sniffer() {
Expand All @@ -68,7 +67,7 @@ Sniffer::~Sniffer() {
}

void Sniffer::start() noexcept {
*output_csv_ << Reply::csv_header() << "\n";
std::cout << (Reply::csv_header() + "\n");
auto handler = [this](Tins::Packet &packet) {
auto reply = Parser::parse(packet);

Expand All @@ -78,7 +77,7 @@ void Sniffer::start() noexcept {
if (reply->is_time_exceeded()) {
statistics_.icmp_messages_path.insert(reply->reply_src_addr);
}
*output_csv_ << reply->to_csv(meta_round_.value_or("1")) << "\n";
std::cout << (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 3935d40

Please sign in to comment.