Implementation of the
pingcommand in Rust using raw sockets and ICMP protocol.
ft_ping is a network diagnostic tool that sends ICMP Echo Request packets to a target host and measures the round-trip time (RTT) of the responses. Built from scratch in Rust using low-level system calls via libc.
- DNS Resolution : Resolve hostnames to IPv4 addresses via
libc::getaddrinfo - Raw ICMP Sockets : Send and receive ICMP packets using
SOCK_RAW - RTT Measurement : Measure round-trip time for each packet
- Statistics : Packet loss percentage, min/avg/max RTT
- Configurable : TTL, packet count, interval between packets, verbose mode
ft_ping/
├── src/
│ ├── main.rs # Entry point, argument parsing, ping loop
│ ├── dns.rs # DNS resolution (hostname -> IPv4)
│ ├── socket.rs # Raw socket creation, send/receive
│ ├── icmp.rs # ICMP Echo Request packet construction
│ ├── checksum.rs # ICMP checksum calculation (RFC 1071)
│ └── stats.rs # Ping statistics collection and display
├── Cargo.toml
└── Makefile
- Rust (edition 2024)
- Root privileges (required for raw sockets)
cargo buildsudo ./target/debug/ft_ping [OPTIONS] <destination>Or via Makefile:
make run ARGS="google.com"
make run ARGS="-c 5 -t 128 google.com"| Flag | Long | Default | Description |
|---|---|---|---|
-v |
--verbose |
false |
Verbose output |
-c |
--count |
infinite | Stop after N packets |
-i |
--interval |
1.0 |
Seconds between packets |
-t |
--ttl |
64 |
IP Time to Live |
-h |
--help |
- | Show help |
-V |
--version |
- | Show version |
PING google.com (142.251.209.142) 56(84) bytes of data.
64 bytes from 142.251.209.142: icmp_seq=0 ttl=64 time=12.3 ms
64 bytes from 142.251.209.142: icmp_seq=1 ttl=64 time=11.8 ms
64 bytes from 142.251.209.142: icmp_seq=2 ttl=64 time=13.1 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss
rtt min/avg/max = 11.800/12.400/13.100 ms
| Crate | Version | Usage |
|---|---|---|
libc |
1.0.0-alpha.3 | System calls (socket, sendto, recvfrom, getaddrinfo) |
ctrlc |
3.5.2 | SIGINT handling |
clap |
4.5.60 | Command-line argument parsing |
Documentation complete dans docs/
| Section | Description |
|---|---|
| Architecture | Architecture globale du projet |
| DNS | Resolution DNS |
| Socket | Gestion des raw sockets |
| ICMP | Construction des paquets ICMP |
| Checksum | Calcul du checksum |
| Stats | Collecte des statistiques |
| Commande | Description |
|---|---|
make run ARGS="..." |
Build + execute avec sudo |
make clean |
Supprime les artefacts de build |