Skip to content
/ Ping Public

A C++ raw ICMP ping utility that sends ICMP Echo Requests to a host, measures round-trip time, and prints results. Uses threads to receive replies, calculates checksums, handles timeouts, and shows statistics including min/avg/max RTT and packet loss. Supports -c for count.

Notifications You must be signed in to change notification settings

mohe22/Ping

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

ping – Minimal C++ ICMP Ping Tool

A lightweight, educational ping implementation in C++ using raw sockets.

Usage

sudo ./ping [-c count] <host>
  • -c count: Number of pings (default: 4)
  • <host>: Hostname or IP (IPv4 only)

Requires sudo due to SOCK_RAW.

How It Works

  1. Resolves host to IPv4 address via getaddrinfo.
  2. Creates raw ICMP socket (IPPROTO_ICMP).
  3. Sends Echo Request (type 8) with:
    • Process ID as identifier
    • Sequence number
    • 56-byte payload
    • Correct ICMP checksum
  4. Receives reply, verifies:
    • Type 0 (Echo Reply)
    • Matching ID and sequence
  5. Measures RTT and prints stats.

TODO

  • Add IPv6 support (AF_INET6, ICMPv6)
  • Implement traceroute (-I style with TTL)

Full technical breakdown:
Read the blog post

About

A C++ raw ICMP ping utility that sends ICMP Echo Requests to a host, measures round-trip time, and prints results. Uses threads to receive replies, calculates checksums, handles timeouts, and shows statistics including min/avg/max RTT and packet loss. Supports -c for count.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages