knetstat: checking socket options on Linux

published 2017-06-11

A few weeks ago I was debugging network code, and I needed to check if some sockets were bound with `SO_REUSEADDR` and/or `SO_REUSEPORT`. I researched how I could inspect that, and was surprised to find out that the Linux kernel did not expose those options to userland.

Thankfully, there is a kernel module called knetstat [1] which lets you do this very easily by adding new files into `procfs`. When I found it it only supported TCP, but I needed the information for UDP as well so I contributed the code [2] to support it.

If you write networking code on Linux or just run servers, I encourage you to check it out. It is a nice little tool that can come very handy in some situations, including when you need to check options like `SO_{RCV,SND}BUF`.

1: https://github.com/veithen/knetstat

2: https://github.com/veithen/knetstat/pull/11

Proxied content from gemini://separateconcerns.com/2017-06-11-knetstat.gmi (external content)

Gemini request details:

Original URL
gemini://separateconcerns.com/2017-06-11-knetstat.gmi
Status code
Success
Meta
text/gemini;lang=en_US
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.