How can I get a list of network interfaces including their MTU?

Hello,
I've looked through a bunch of network interface crates. None of them have the letters "MTU" in any docs, issues, or structs. I must be thinking about something incorrectly. I don't know much about libc and less about the Windows equivalent.

Would be great if worked on macos and windows too.

Some examples
https://docs.rs/nix/latest/nix/
_https://docs.rs/pnet/latest/pnet/index.html
_https://docs.rs/network-interface/0.1.2-beta/network_interface/
(forum won't let me post many links as a new user)

This might have something, but it's netlink only
https://docs.rs/neli/latest/neli/

You can do it with neli, but as you said it's netlink only. It's also not trivial — you need to know the netlink protocols. I don't think there's a cross-platform solution.

1 Like

Is the MTU of the local interface really all that useful? I thought one needed to do Path MTU Discovery - Wikipedia to figure it out for a particular endpoint.

1 Like

Thank you.
I hate when this happens. I set out on some small trivial thing and then...

For some applications!

I have a different program, not written in rust, which sets up interfaces. I thought I'd make some integrationy tests and get a little better at rust. MTU is just one of the things to check. I can just punt on MTU for now and do the rest I guess.
The other motivation to use rust is it supports more platforms than some of the other options I'm semi competent in.

The information can be found in /sys/class/net/*/mtu in linux, which I recognise is not the ideal approach you're looking for. A search for the C struct ifreq in Rust projects seems to indicate no standard crate for this, unfortunately.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.