Tiny Ping
Goal: Write a compact C program that sends a single ICMP Echo Request to a given IPv4 address and prints the measured round-trip time (RTT) in milliseconds.
Requirements:
Use a raw socket (AF_INET, SOCK_RAW, IPPROTO_ICMP).
Construct an ICMP Echo Request packet (struct icmphdr + small payload).
Implement the ICMP checksum (RFC 1071) and set it correctly in the packet.
Send the packet with sendto() and receive the reply with recvfrom().
Measure RTT using gettimeofday() (timestamp before send and after receive).
Validate the reply by checking ICMP type (Echo Reply) and matching id (use getpid() & 0xFFFF).
Program must be small and readable (target: ~20–40 lines).
Inputs: single command line argument — destination IPv4 address (dotted decimal).
Outputs: either Reply from <ip>: RTT=<x.xx> ms or a clear error/timeout message.
Constraints & warnings:
Must run with elevated privileges (explain how).
Must not perform address spoofing or scanning; test only on permitted targets.
Keep payload size small (e.g., ≤32 bytes).
Deliverables: source file tiny_ping.c and a short README describing how to compile and run (compile command and sudo requirement).
Optional extensions (bonus): add a timeout, validate sequence number, send multiple pings and print min/avg/max RTTs.