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.
- Send ICMP Echo (ping) requests to a target IP
- Receive ICMP replies
- Specify source IP
- Configurable ping count (
-coption) - Continuous ping until Ctrl+C if count is not specified
- Detailed packet inspection and checksum validation
- Lightweight, no external dependencies
- Clone the repository:
git clone https://github.com/Soumyo001/cpp-icmp-ping.git
cd cpp-icmp-ping- Build the program:
make clean && make- Run with root privileges (required for raw sockets):
sudo ./ping <args>sudo ./ping [--send|--recv] [-c count] <src_ip> <dest_ip>| 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) |
- 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-
Written in C++17, uses raw sockets to handle ICMP packets
-
utils.hcontains helper functions for IP conversion, checksum calculation, and packet display -
Pingclass handles packet building and sending/receiving -
Packet structures:
-
RawIpPacketandRawIcmpPacketfor low-level byte access -
IpPacketandIcmpPacketfor higher-level abstraction
-
-
Checksum validation ensures packet integrity before processing
MIT License – free to use, modify, and distribute.