From afe7e53e5b2addb7bab78f0938cbb0e729dce9d9 Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Thu, 19 Mar 2026 01:45:21 +0100 Subject: [PATCH] doc: update README and LICENSE --- LICENSE | 2 +- README.md | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 94 insertions(+), 5 deletions(-) diff --git a/LICENSE b/LICENSE index d9114c7..c1fa60f 100644 --- a/LICENSE +++ b/LICENSE @@ -631,7 +631,7 @@ to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - ft_ping - TODO + net-tools - ICMPv4 network utilities Copyright (C) 2026 This program is free software: you can redistribute it and/or modify diff --git a/README.md b/README.md index f6cd6d4..3207ad6 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,99 @@ -# ft_ping +# net-tools -TODO +A collection of ICMPv4 network utilities as an alternative to standard +system commands (ping, ...). -### Code Style +## Code Style -TODO +- Allman braces: opening and closing braces each on their own line +- Yoda conditions: constant on the left (e.g. 0 == val, NULL != ptr) +- C99 compliant +- Tabs only, width 4 +- snake_case for functions and variables, SCREAMING_SNAKE_CASE for macros +- System includes, then a blank line, then local includes +- Variable declarations aligned with tabs within the function body +- Static helper functions are forward-declared at the top of the file and + defined after the main public function +- Function definitions (not forward declarations or prototypes) have a newline + between the return type and the function name +- Line continuations are indented 2 tabs past the base scope indentation + +## Dependencies + +- clang (C99) +- make +- bash (configure script) +- POSIX-compliant OS +- libc + +For tests only: +- criterion + +## Binaries + +### ft_ping + +Alternative to inetutils ping. Sends ICMPv4 ECHO_REQUEST packets to network +hosts and reports RTT statistics. Requires root (raw socket). + +``` +ft_ping - Send ICMP ECHO_REQUEST to network hosts +Usage: ft_ping [options] + +Options: + -h, --help Display this help and exit + -V, --version Display version information and exit + -v, --verbose Verbose output + -q, --quiet Quiet mode (only show summary) + -c, --count Stop after sending N packets + -i, --interval Wait N seconds between packets + -t, --ttl Set Time To Live + -s, --size Packet size in bytes + -W, --timeout Timeout for replies in seconds + -w, --deadline Exit after N seconds regardless of packets sent/received + -f, --flood Flood mode + -M, --dont-fragment Set the Don't Fragment bit +``` + +## Modules + +### libicmp +Handles everything ICMP at the socket level: open a raw socket, build and +send echo requests, receive and parse replies. No loop, no display. Just a +clean interface over the kernel socket. + +### src/cli +Shared CLI parsing layer used by all binaries. Provides a generic getopt +wrapper and primitive parsers (int, float) that each binary plugs into. + +### src//cli +Per-binary argument parsing. Defines the accepted options, validates them, +and fills the binary-specific config struct. + +### src/ping/core +Drives the ping session for one destination. ping_run() creates the socket +and calls ping_one() for each destination. ping_one() sets up state, runs +the loop, and prints the summary. ping_loop() uses select() to wait for +packets and reacts to send/stop flags. ping_send_one() builds the payload +and calls libicmp. ping_callback() handles incoming replies and errors. + +### src/ping/scheduler +Manages timing and signals. Installs SIGALRM (triggers send) and SIGINT +(triggers stop). Arms a one-shot timer via setitimer() after each send. +Signal handlers only write a flag -- the loop does the actual work. + +### src/ping/tracker +A 128-slot circular buffer indexed by (seq % 128). Records when each +packet was sent and marks it when a reply arrives. Used to compute RTT +and detect duplicates. + +### src/ping/stats +Accumulates RTT samples (min, max, sum, sum of squares) in nanoseconds. +Computes min/avg/max/mdev in milliseconds on demand. + +### src/ping/output +All user-facing output: the opening line, per-packet lines, ICMP error +messages, the final statistics summary, and flood mode dots. ## License