Recreate the ping command in C based on the inetutils-2.0 implementation.
- Be realized in a virtual machine running on Debian (>= 7.0)
- Use C and submit a Makefile
- Authorised to use the libc functions
- Executable must be named
ft_ping - Take as reference the ping implementation from
inetutils-2.0(ping -V) - Manage the -v -? options
- Manage a simple IPv4 (address/hostname) as parameters
- Manage FQDN without doing the DNS resolution in the packet
-v, --verbose
Verbose output. ICMP packets other than ECHO_RESPONSE that are received are listed.
-?, --help
Gives this help list
Here is the output of the original ping command:
$> ping gnu.org
PING gnu.org (209.51.188.116) 56(84) bytes of data.
64 bytes from wildebeest1p.gnu.org (209.51.188.116): icmp_seq=1 ttl=54 time=111 ms
64 bytes from wildebeest1p.gnu.org (209.51.188.116): icmp_seq=2 ttl=54 time=104 ms
64 bytes from wildebeest1p.gnu.org (209.51.188.116): icmp_seq=3 ttl=54 time=106 ms
--- gnu.org ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 103.695/106.628/110.551/2.884 ms
$> Your Machine --> [ICMP Echo Request] --> Internet --> Target Server Your Machine <-- [ICMP Echo Reply] <-- Internet <-- Target Server
Your Machine --> [ICMP Echo Request] --> Internet -X-> (Timeout or Destination Unreachable)
The ping command uses ICMP protocol. ICMP protocol allows devices to exchange messages about various network conditions. It contains three types of messages: errors, queries, and responses.
Error messages are used to inform the sender about a condition or cause that prevents the sender's packets from reaching their destination. Query and response messages are used to exchange information about various network conditions.
Query and response messages are always used in pairs where one device sends a query message and another sends a reply or response to the query message. The ping command uses query-response messages.
ICMP (Internet Control Message Protocol) is a network protocol used for sending error messages and operational information about network conditions. It's commonly used for diagnostic and control purposes within IP networks.
getoptto parse the command line argumentssocketto create a socketsendtoto send the ICMP packetrecvfromto receive the ICMP packetgettimeofdayto get the current timegetaddrinfoto get the IP address of a hostnameselectto wait for a responsesignalto handle signals