mtu

Crates.iomtu
lib.rsmtu
version0.1.3
sourcesrc
created_at2024-09-02 10:09:45.490388
updated_at2024-09-26 09:59:51.228698
descriptionObtain the local network interface MTU towards a given IP address.
homepagehttps://github.com/mozilla/mtu/
repositoryhttps://github.com/mozilla/mtu/
max_upload_size
id1360358
size61,301
Martin Thomson (martinthomson)

documentation

README

MTU

A crate to return the name and maximum transmission unit (MTU) of the local network interface towards a given destination SocketAddr, optionally from a given local SocketAddr.

Usage

This crate exports a single function interface_and_mtu that, given a pair of local and remote SocketAddrs, returns the name and maximum transmission unit (MTU) of the local network interface used by a socket bound to the local address and connected towards the remote destination.

If the local address is None, the function will let the operating system choose the local address based on the given remote address. If the remote address is None, the function will return the name and MTU of the local network interface with the given local address.

Example

let saddr = "127.0.0.1:443".parse().unwrap();
let (name, mtu) = mtu::interface_and_mtu(&(None, saddr)).unwrap();
println!("MTU for {saddr:?} is {mtu} on {name}");

Supported Platforms

  • Linux
  • macOS
  • Windows
  • FreeBSD
  • NetBSD
  • OpenBSD

Notes

The returned MTU may exceed the maximum IP packet size of 65,535 bytes on some platforms for some remote destinations. (For example, loopback destinations on Windows.)

The returned interface name is obtained from the operating system.

Contributing

We're happy to receive PRs that improve this crate. Please take a look at our community guidelines beforehand.

Commit count: 92

cargo fmt