Coder Social home page Coder Social logo

ping's Introduction

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)

ping's People

Contributors

sryze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ping's Issues

ipv6 timeout

How to reproduce:

  • Tested on Mac Air M1 (arm64)
  • Tested on Linux Ubuntu (x86_64)
  • Clone github repo, compile as instruction (cmake,make), run, nothing else

Sample output (this ping utlity, after the standard os ping6 utility)

Linux (Ubuntu, x86_64)

clodo@clodo-ubuntu2:~/Documents/ping/build$ sudo ./ping -6 google.com
Sent ICMP echo request to 2a00:1450:4002:400::200e
Request timed out
Sent ICMP echo request to 2a00:1450:4002:400::200e
Request timed out
Sent ICMP echo request to 2a00:1450:4002:400::200e
Request timed out
Sent ICMP echo request to 2a00:1450:4002:400::200e
Request timed out
Sent ICMP echo request to 2a00:1450:4002:400::200e
Request timed out
Sent ICMP echo request to 2a00:1450:4002:400::200e
^C
clodo@clodo-ubuntu2:~/Documents/ping/build$ ping6 google.com
PING google.com(mil04s41-in-x0e.1e100.net (2a00:1450:4002:400::200e)) 56 data bytes
64 bytes from mil04s41-in-x0e.1e100.net (2a00:1450:4002:400::200e): icmp_seq=1 ttl=118 time=20.5 ms
64 bytes from mil04s41-in-x0e.1e100.net (2a00:1450:4002:400::200e): icmp_seq=2 ttl=118 time=21.0 ms
64 bytes from mil04s41-in-x0e.1e100.net (2a00:1450:4002:400::200e): icmp_seq=3 ttl=118 time=20.4 ms

macOS (arm64 M1)

% sudo ./ping -6 google.com
Sent ICMP echo request to 2a00:1450:4002:406::200e
Request timed out
Sent ICMP echo request to 2a00:1450:4002:406::200e
Request timed out
Sent ICMP echo request to 2a00:1450:4002:406::200e
Request timed out
Sent ICMP echo request to 2a00:1450:4002:406::200e
Request timed out
^C
% ping6 google.com
PING6(56=40+8+8 bytes) 2001:750:12:3d6:1579:d623:9096:98b --> 2a00:1450:4002:406::200e
16 bytes from 2a00:1450:4002:406::200e, icmp_seq=0 hlim=119 time=23.325 ms
16 bytes from 2a00:1450:4002:406::200e, icmp_seq=1 hlim=119 time=23.716 ms
16 bytes from 2a00:1450:4002:406::200e, icmp_seq=2 hlim=119 time=23.320 ms
^C
--- google.com ping6 statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 23.320/23.454/23.716/0.186 ms

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.