A from-scratch reimplementation of the ping command in C, matching the
inetutils-2.0 reference (ping -V) as required by the 42 ft_ping subject.
It sends ICMP ECHO_REQUEST packets over a raw IPv4 socket, one per second,
and reports round-trip times and loss statistics — output, indentation and
timing are aligned with inetutils.
make # builds ./ft_ping
make re # rebuild from scratch
make clean # remove object files
make fclean # remove objects + binaryft_ping needs raw-socket privileges (CAP_NET_RAW): run it as root, with
sudo, after setcap cap_net_raw+ep ./ft_ping, or inside the provided Docker
container.
sudo ./ft_ping 8.8.8.8
sudo ./ft_ping -c 4 google.com
sudo ./ft_ping -v --ttl 1 8.8.8.8 # force a "Time to live exceeded" errorMandatory (per the subject): -v (verbose) and -? (help).
| Flag | Long | Meaning |
|---|---|---|
-v |
--verbose |
verbose output (shows packet id and error IP-header dumps) |
-? -h |
--help |
help list |
--usage |
short usage synopsis | |
-V |
--version |
version |
-c N |
--count=N |
stop after N packets |
-i N |
--interval=N |
seconds between packets (default 1) |
-s N |
--size=N |
payload size in bytes (default 56) |
-q |
--quiet |
only header + statistics |
-w N |
--timeout=N |
overall deadline in seconds |
-W N |
--linger=N |
seconds to wait for a reply |
-t N |
--ttl=N |
outgoing TTL |
-T N |
--tos=N |
type of service |
-f |
--flood |
flood mode |
-l N |
--preload=N |
send N packets up front |
The subject requires a Debian (>= 7.0) environment with raw-socket privileges.
docker/Dockerfile builds a Debian image that also carries the inetutils
reference ping, used only by the test suite for side-by-side comparison —
ft_ping itself never calls any external ping.
make docker-build # build the Debian image
make docker-shell # interactive shell in the container
make test # build + run the full test suite in the containerpingsends one probe per second until interrupted, then prints statistics.
Resources:
https://networklessons.com/ip-routing/ipv4-packet-header https://sites.uclouvain.be/SystInfo/usr/include/netinet/ip_icmp.h.html https://networklessons.com/ip-routing/icmp-internet-control-message-protocol https://book.huihoo.com/iptables-tutorial/x1078.htm https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xml#icmp-parameters-codes-0 https://datatracker.ietf.org/doc/html/rfc2780 https://support.huawei.com/enterprise/en/doc/EDOC1100174721/9dff3e87/icmp-echo-request-reply-message https://www.rfc-editor.org/info/rfc1071/ https://sites.uclouvain.be/SystInfo/usr/include/netinet/ip.h.html