Skip to content
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

sniffer: fix mangled newlines on stdout #61

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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