darkerseid
I am trying to get low level socket programming in elixir
{:ok, socket} = :socket.open(:inet, :raw, :icmp)
:socket.bind(socket, %{:family => :inet, :port => 0})
:socket.ioctl(socket, :gifconf)
Gives me
{:ok, [%{addr: %{addr: {127, 0, 0, 1}, family: :inet, port: 0}, name: 'lo'}]}
But ip link gives me
#ip link
#1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
# link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
#2: veth0a@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default #qlen 1000
# link/ether 5e:c8:38:a3:e6:50 brd ff:ff:ff:ff:ff:ff link-netns netns_br0
How do you get these two interfaces?
For testing, you can create execute this script, A bunch of helper functions to create Linux bridges, network namespaces, and interconnect everything using veth pairs. · GitHub
Trending in Questions
One of my LiveView view’s has a very heavy javascript dependency so I want to avoid loading it for every page on the site, while still us...
New
Hello everyone!
I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++.
Does anyone ...
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
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
(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
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #elixirconf-us
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #security
- #processes
- #api
- #forms
- #hex










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
moogle19
With which user to you run this?
When you are on Linux you normally need to be
rootto access raw ICMP sockets.darkerseid
I created a new linux namespace with the help of attached gist.
moogle19
If I understand
nsentercorrectly, it just spawns a new shell inside the network namespace, but you probably still needrootpriviliges or theCAP_NET_RAWcapability to access raw sockets (but I never worked with these namespaces).hauleth
Not really, you can run ICMP socket as a regular user if your user ID is within
sysctl net.ipv4.ping_group_range. However that will require you to use datagram socket instead of raw socket:It also has slightly reduced API, as for example on Linux you cannot specify
idandseqfields for ICMP packet, as these will be always set for you.There is library that I have created in the past that provide slightly higher API for ICMP sockets (still quite limited):
It can be used in form of (to match the top message):
And about the question of “how to get list of interfaces in the system”. Instead of playing with
socketdirectly (especially as you are doing network namespacing, so obviously your view on interfaces will be limited) you should use:That will return data like that:
That describe all interfaces available in your system and do not require any special privileges like being able to create ICMP raw socket.
darkerseid
To add some context, I was trying to replicate Networking Lab: Ethernet Broadcast Domains in elixir, the code in there uses python
hauleth
But in this case you should not use ICMP protocol, but “just raw socket”, aka:
So this is pretty much different from your original question where you ask for the fetching list of the interfaces from raw ICMP socket.
Will will return you only the configuration for the interface the socket is listening right now, not all that are available in the system.
Also I see the problem with your code - you define address map like
%{:family => :inet, :port => 0}which is incorrect (weird thatsocketdo not scream about it, or maybe it does, but you do not check the value returned by:socket.bind/2). It should be%{:family => :inet, :port => 0, :addr => address}as:addrfield is mandatory according to the specs.BradS2S
I’m learning a ton about low level socket work from @whatyouhide’s protohacker YouTube videos.
Definitely worth a watch