ft_ping is a custom reimplementation of the Unix ping command written in C. It sends ICMP Echo Request packets to a specified IPv4 address or hostname and measures round-trip time (RTT) for each response. Inspired by the behavior of ping from GNU inetutils-2.0, it handles basic options like -v and -?, provides error feedback, and reports network statistics while operating at the raw socket level.
At its core, ping
:
- sends ICMP echo request packets to a target.
- waits for ICMP echo reply packets.
- measures the round-trip time (RTT).
- reports statistics like packet loss, min/avg/max RTT.
ICMP (Internet Control Message Protocol) is used for diagnostics, not for regular data transfer like TCP/UDP.
+--------------------------------+
| type | code | checksum |
+--------------------------------+
| id | seq. number |
+--------------------------------+
| data |
+--------------------------------+
FIELD | LENGTH | DESCRIPTION |
---|---|---|
type | 1 byte | 8 for echo request, 0 for echo reply |
code | 1 byte | always 0 for echo messages |
checksum | 2 bytes | 16-bit checksum of the ICMP message (header + data) |
identifier | 2 bytes | identifies the request; often the process id |
sequence number | 2 bytes | incremented with each request to match replies |
data | variable | optional payload; must be echoed in the reply |