Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hauleth/gen_icmp
ICMP protocol implementation for Erlang without NIFs
https://github.com/hauleth/gen_icmp
erlang icmp icmp-ping ping
Last synced: about 2 months ago
JSON representation
ICMP protocol implementation for Erlang without NIFs
- Host: GitHub
- URL: https://github.com/hauleth/gen_icmp
- Owner: hauleth
- License: apache-2.0
- Created: 2020-05-26T12:51:16.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-02-22T15:32:04.000Z (almost 3 years ago)
- Last Synced: 2024-10-12T23:20:59.253Z (2 months ago)
- Topics: erlang, icmp, icmp-ping, ping
- Language: Erlang
- Homepage:
- Size: 20.5 KB
- Stars: 34
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `gen_icmp`
ICMP implementation for Erlang using `socket` (so for now only Unix support).
## Usage
To send ICMP echo request as unprivileged user (works on macOS and Linux if
user group is within `sysctl net.ipv4.ping_group_range`):```erlang
{ok, Socket} = gen_icmp:open().Addr = {127, 0, 0, 1}.
ok = gen_icmp:echoreq(Socket, Addr, <<1,2,3,4>>).
receive
{icmp, Addr, {echorep, #{data := <<1,2,3,4>>}}} -> ok
end.
```If you want to be sure of message order you can use `seq` option:
```erlang
{ok, Socket} = gen_icmp:open().Addr = {127, 0, 0, 1}.
ok = gen_icmp:echoreq(Socket, Addr, <<1,2,3,4>>, [{seq, 0}]).
ok = gen_icmp:echoreq(Socket, Addr, <<5,6,7,8>>, [{seq, 1}]).receive
{icmp, Addr, {echorep, #{seq := Seq, data := Data}}} ->
io:write("Received reply seq=~B data=~p~n", [Seq, Data])
end.
```## License
See [Apache 2.0](LICENSE).