Skip to content

Soumyo001/cpp-icmp-ping

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raw ICMP Ping Implementation (C++)

Overview

This project is a low-level implementation of an ICMP Echo Request / Echo Reply (ping) mechanism written in modern C++.
It manually constructs, sends, receives, parses, and validates raw IPv4 + ICMP packets using raw sockets.

The goal of this project is deep understanding of network packet structure.


Table of Contents

  1. Features
  2. Installation
  3. Usage
  4. Examples
  5. Development
  6. License

Features

  • Send ICMP Echo (ping) requests to a target IP
  • Receive ICMP replies
  • Specify source IP
  • Configurable ping count (-c option)
  • Continuous ping until Ctrl+C if count is not specified
  • Detailed packet inspection and checksum validation
  • Lightweight, no external dependencies

Installation

  1. Clone the repository:
git clone https://github.com/Soumyo001/cpp-icmp-ping.git
cd cpp-icmp-ping
  1. Build the program:
make clean && make
  1. Run with root privileges (required for raw sockets):
sudo ./ping <args>

Usage

sudo ./ping [--send|--recv] [-c count] <src_ip> <dest_ip>

Options:

Option Description
--send Sends ICMP Echo requests to a target IP
--recv Listens and receives ICMP Echo replies
-c <count> Number of ping requests to send (optional, default: continuous)
<src_ip> Source IP address (optional, system default used if omitted)
<dest_ip> Destination IP address (required in send mode)

Examples

  • Send 5 pings to a target IP:
sudo ./ping --send -c 5 192.168.0.111 192.168.0.107
  • Continuous ping until Ctrl+C:
sudo ./ping --send 192.168.0.107
  • Receive mode (listen for ICMP replies):
sudo ./ping --recv
  • Specify a source IP:
sudo ./ping --send -c 3 192.168.0.111 192.168.0.107

Development Notes

  • Written in C++17, uses raw sockets to handle ICMP packets

  • utils.h contains helper functions for IP conversion, checksum calculation, and packet display

  • Ping class handles packet building and sending/receiving

  • Packet structures:

    • RawIpPacket and RawIcmpPacket for low-level byte access

    • IpPacket and IcmpPacket for higher-level abstraction

  • Checksum validation ensures packet integrity before processing


License

MIT License – free to use, modify, and distribute.

About

A minimal ICMP Ping implementation in C++ featuring raw sockets, checksum calculation, ICMP/IP packet construction. Designed for developers learning low-level networking and system programming.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors