Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/z1cheng/c-ping
A very simple and small ping tool that sends ICMP Echo datagram to a host
https://github.com/z1cheng/c-ping
Last synced: 9 days ago
JSON representation
A very simple and small ping tool that sends ICMP Echo datagram to a host
- Host: GitHub
- URL: https://github.com/z1cheng/c-ping
- Owner: z1cheng
- License: mit
- Created: 2022-01-20T07:33:40.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-01-20T14:04:20.000Z (almost 3 years ago)
- Last Synced: 2023-05-19T15:39:20.293Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# c-ping
c-ping is a very simple and small ping tool that sends ICMP Echo datagram to a host.# ICMP Echo or Echo reply message
The structure of ICMP Echo or Echo reply message:
```
0 1 2 3
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 9 A B C D E F
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Code | Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identifier | Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data(Optional)... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+```
1. Type: **8** for echo message, and **0** for echo reply message
2. Code: for echo or echo reply, it should be **0**
3. Checksum: 16 bits, it will be computed by the checksum algorithm
4. Identifier: may be used like a port in TCP or UDP to **identify a session**
5. Sequence Number: may be **incremented** on each echo request sentThe destination returns the **same** Identifier and Sequence Number in the reply.
# Checksum algorithm
This algorithm based on [RFC1071](https://datatracker.ietf.org/doc/html/rfc1071) is below:
1. Set checksum field of request to 0
2. Add each 16 bits from request to sum
3. Add the remaining byte if it’s odd
4. Add the high 16 bits to the low 16 bits util the high 16 bits are 0
5. The complement of sum is the checksumTo check a checksum, just pass the datagram with the checksum to this method, then check if the result is 0
# Example
Ensure that you have installed the go environment first, then just run following commands:```shell
# generate c-ping
go build ping.go# start to ping
./ping github.com
```