Recreating the inettools-2.0 ping in C, one ICMP ECHO_REQUEST packet at a time xD.
.
├── Makefile # Makefile for building and managing the project
├── README.md # This file
├── include/ # Header files
│ └── my_ping.h # Main header file for my_ping
├── obj/ # Compiled object files (generated during build)
└── src/ # Source code files
├── icmp_messages.c # Handles ICMP message creation and parsing
├── initialization.c # Initializes the ping utility
├── main.c # Entry point of the program
├── message_record.c # Tracks sent and received messages
├── parse.c # Parses command-line arguments
├── print.c # Handles output and logging
├── signal.c # Manages signal handling (e.g., Ctrl+C)
├── socket.c # Manages socket creation and communication
└── validation.c # Validates input and network parameters-
GNU-compliant CLI: Uses parse_argp to provide a standard command-line interface.
-
Cli Options:
-c, --count=NUMBER Stop after sending NUMBER packets
-d, --debug Set the SO_DEBUG option
-i, --interval=NUMBER Wait NUMBER seconds between sending each packet
-t, --ttl=N specify N as time-to-live
-v, --verbose Verbose output
-W, --linger=N Number of seconds to wait for response
-?, --help Give this help list
--usage Give a short usage message
-V, --version Print program version-
ICMP Protocol Implementation: Handles ICMP ECHO_REQUEST, ECHO_REPLY, and ICMP_TIMXCEED messages.
-
Signal Handling: Gracefully handles interruptions (e.g., Ctrl+C).
-
Final metrics: min, max and average round trip time (rtt) measurement, as well as standard deviation.
- Ping a host 5 times:
sudo ./my_ping -c 5 google.com- Set a custom interval between packets
sudo ./my_ping -i 2 google.com- Enable verbose output
sudo ./my_ping -v google.com- The program parses command-line arguments and validates the target host.
- A raw socket is created to send and receive ICMP packets.
- The hostname is resolved with DNS or validated (in case of an ipaddr input).
-
ICMP ECHO_REQUEST packets are constructed and sent to the target host.
-
The program listens for ECHO_REPLY packets and calculates round-trip times.
- The program handles interruptions (e.g., Ctrl+C) and displays statistics before exiting.
- The program prints detailed information about each packet, including sequence numbers, round-trip times, and TTL values.
- getaddrinfo: dns/name host ip validation
- getnameinfo: reverse dns
Inspired by the inettools 2.0 ping utility.
Built with 💖 and a healthy amount of coffee.
