ityonemo
This is a basic demonstration of how to write an ICMP (‘ping’) server using a NIF in about 100 lines of elixir and 100 lines of Zig.
This might be able to be deployed as a ‘real’ library. Would anyone be interested in using this? I am very happy to put more work into making this a quality release (modulo zig itself being still experimental) if people are interested, as there really isn’t a satisfactory ICMP solution in the BEAM (and the :socket library maintainers have suggested that ICMP is not going to happen)
Trending in Discussions
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Hi there! :wave:
@frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
Other Trending Topics
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hauleth
Actually since OTP 22.3 you can use
socketmodule to have ICMP socket. If you want to userawsocket however you will need to be superuser, but Darwin and Linux supports ICMP overdgramsockets.hauleth
To prove that it is possible:
API is simple:
Tested on macOS, but should work on Linux as well. I am not sure about BSDs.
EDIT:
Just in case, this project seems as a good example of how to use Zigler to write Erlang NIFs, and it is great. However sending ICMP echo requests via
socketis absolutely possible.ityonemo
Lol, I tried this two months ago and support for the :icmp mode wasn’t there!! I think I was on 22.2, and I asked Peter dimitrov at codebeam and he said they weren’t going to do icmp
hauleth
I was trying to implement
gen_icmpearlier viasocketand encountered that problem. So instead I created PR to the core that fixed checks for{type, proto}pairs and now it is possible to create such socket. I think that he meant that they will not implement ICMP helper function directly in OTP, but manual implementation viasocketshould be possible (on supporting OSes, as traditionally ICMP sockets needed to be created as raw sockets which can be created only by superuser).ityonemo
Yeah. We must have been in the same place because I remember looking through the :socket nif code and scratching my head about some dead ends. However I’m not brave enough to figure out how to do full otp/erlang build to make PRs to core. Maybe I should work on that.
I think he must have misinterpreted my question. It was over the vtc after all.
Do you think your code above should be a library?
hauleth
I can clean it up and make it into library later.
ityonemo
Happy to help if you’d like some!
hauleth
I have implemented ICMP, but ICMPv6 is still not done, if you want then I would be glad for PR. It uses slightly different API from what You are using as I wanted something “more basic” so users could build larger functionalities on top of this.
lkuty
From different tests I made on macOS and Linux, it looks like macOS needs us to compute the checksum for the echo request and then give us back the full IP packet of the echo reply, hence your
_::size(160)to skip 20 bytes of IP header. On Linux we do not need to compute the checksum or set an id because the OS will dot it for us and we also only get the ICMP echo reply, not the full IP packet.This is confirmed by the
pingsource code on MacOS. I guess the behaviour of the library regarding a socket created withsocket(PF_INET, SOCK_DGRAM, IPPROTO_ICMP)is quite OS dependent.ityonemo
You might want to try this: API Reference — icmp v0.1.0