Skip to content

Conversation

@tkjaer
Copy link
Owner

@tkjaer tkjaer commented Dec 13, 2025

Summary

This PR introduces cleanups across the codebase and refactors code for readability.

Details

Program flow and signal handling:

  • Refactored main.go to move program logic into a run() function, improving signal handling for interrupts (Ctrl+C). Now, the program exits gracefully on the first interrupt and immediately on a second interrupt. This also simplifies error handling and resource cleanup. [1] [2] [3]
  • Improved the shutdown sequence by extracting logic into a new waitForCompletion function and using a sentinel error for forced exit.

Argument parsing and CLI improvements:

  • Reorganized and grouped CLI flags in ParseArgs for better usability, added missing short flags in help examples, and ensured the help text matches the actual flags. [1] [2]

ICMP probe decoding and packet handling:

  • Refactored ICMPv4 and ICMPv6 probe decoding logic for clarity and correctness: replaced nested and repetitive code with helper methods, improved error handling for truncated packets, and consolidated IP/port matching logic. [1] [2] [3]
  • Added a helper method innerIPsMatch to centralize IP address validation in decoded packets.
  • Improved extraction of metadata (network layer and timestamp) in packet decoding.

Code clarity and cleanup:

  • Removed excessive debug logging from ARP table lookup code on BSD systems for cleaner logs. [1] [2]
  • Removed unused or commented-out code related to statistics aggregation and summary generation in ProbeManager. [1] [2]
  • Minor variable renaming for consistency (e.g., ttl_exceeded to ttlExceeded) in BPF filter setup. [1] [2]

Bug fixes and minor improvements:

  • Fixed integer overflow bug in infinite probe count assignment.
  • Added clarifying comments and minor documentation improvements in shared types.
  • Improved comments in probe run output to clarify timestamp handling.

@tkjaer tkjaer self-assigned this Dec 13, 2025
@tkjaer tkjaer merged commit b192da4 into main Dec 13, 2025
5 checks passed
@tkjaer tkjaer deleted the tkjaer/misc-cleanup-and-refactoring branch December 13, 2025 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants