Skip to content

sryze/ping

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ping

Build Status

This is a rather basic implementation of the ping command in C. It was created for learning more about raw sockets and how ping works (and for fun).

Features:

  • Cross-platform: can compile and run on Windows, Linux, macOS, *BSD
  • Supports IPv6
  • Displays time with microsecond precision

Example usage:

$ ./ping google.com
PING google.com (142.250.74.206)
Received reply from 142.250.74.206: seq=0, time=103.307 ms
Received reply from 142.250.74.206: seq=1, time=91.200 ms
Received reply from 142.250.74.206: seq=2, time=103.080 ms
Received reply from 142.250.74.206: seq=3, time=94.531 ms
Received reply from 142.250.74.206: seq=4, time=92.204 ms
^C

ping accepts only one argument - the name of the host to ping.

Building

To build ping you'll need a C89 compiler and CMake. Supported platforms include Linux, Mac OS X, Windows (MSVC, Cygwin, MinGW), FreeBSD, NetBSD, OpenBSD, Solaris.

After you cloned this repo run the following commands to build an executable:

cd ping
mkdir build && cd build
cmake ../ -G "Unix Makefiles"
make

Running

Use of raw sockets usually requires administrative privileges, therefore you will need to run ping as root:

sudo ./ping google.com

There is also a way to make it run without typing sudo every time: set the suid bit on the executable and change its owner to root:

sudo chmod +s ./ping
sudo chown root ./ping

After starting ping, it will run indefinitely until you interrupt it, e.g. by doing Ctrl-C in the terminal.

Scripts

The scripts directory contains a couple of scripts to aid debugging:

  • capture.sh - captures ICMP traffic with tcpdump and saves it to ping.pcap (needs to be run as root)
  • dump.sh - prints the contents of ping.pcap in a nice form (tcpdump may actually display helpful errors there, like a miscalculated checksum)

About

Simple (cross-platform) implementation of the "ping" command

Topics

Resources

License

Stars

Watchers

Forks