Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ft_ping

A custom, low-level implementation of the classic network utility ping, written in C. This project explores raw sockets, network protocols, the Internet Control Message Protocol (ICMP), and precise packet parsing, benchmarking its output and behavior against the inetutils-2.0 standard.

🚀 Key Features

  • Network Diagnosis: Sends ICMP ECHO_REQUEST packets to network hosts (IPv4 addresses or FQDNs) and reports the round-trip time (RTT).
  • Raw Socket Integration: Directly interfaces with the network layer to craft, send, and intercept network packets.
  • Robust Packet Parsing: Validates incoming IP headers and ICMP ECHO_REPLY payloads, handling network errors gracefully without crashing.
  • DNS Resolution: Fully resolves domain names and handles Fully Qualified Domain Names (FQDN) seamlessly without delaying the packet response flow.

🛠️ Technical Overview & Architecture

The program operates at a system-level depth, interacting directly with network layers.

1. Networking & Raw Sockets

To send and receive ICMP packets, the program initializes a raw network socket using:

socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);

Note: Due to the use of raw sockets, the binary requires superuser privileges (sudo) or specific capabilities (CAP_NET_RAW) to run.

2. Packet Flow & Mechanics

  • Constructing the Request: The program builds an IP packet payload enclosing an ICMP header structure with type = ICMP_ECHO and a valid internet checksum.
  • The Event Loop: A periodic interval loop dispatches a packet per second, initiating a precise structural timer to track the exact departure time.
  • Interception & Verification: Incoming packets are intercepted. The program strips the IP header, isolates the ICMP response, checks if the sequence ID matches its own process, and calculates the elapsed Round-Trip Time (RTT).

📋 Command Line Interface

The application supports standard target arguments along with specific diagnostic flags designed to align identically with inetutils-2.0.

Arguments

  • <destination>: Accepts either an IPv4 address (e.g., 8.8.8.8) or a hostname/FQDN (e.g., google.com).

Supported Flags

  • -v (Verbose): Enhances output transparency by printing detailed error logs, anomalies, or descriptive telemetry whenever network packets encounter issues (such as an expired TTL).
  • -? (Help): Outputs a detailed usage summary outlining command line syntax.

📦 Installation & Usage

Prerequisites

The codebase is designed for environments running a Linux kernel (>= 3.14), optimized specifically for Debian systems.

Compilation

Compile the project using the provided Makefile:

make

Execution

Run the binary with root privileges, targeting a network host:

sudo ./ft_ping google.com

To run with verbose output:

sudo ./ft_ping -v 1.1.1.1

⚠️ Error Handling & Resilience

  • Zero-Crash Policy: Built to absorb volatile network anomalies. Malformed packets, lost connections, dropped packets, or host unreachable errors are caught and logged cleanly without triggering segmentation faults or memory leaks.
  • Resource Cleanup: All opened sockets, allocated network structures, and memory maps are systematically freed upon termination (e.g., when receiving an interrupt signal like Ctrl+C), ensuring a clean exit state.

About

This project is about recoding the ping command.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages