Crates.io | mtu |
lib.rs | mtu |
version | 0.1.3 |
source | src |
created_at | 2024-09-02 10:09:45.490388 |
updated_at | 2024-09-26 09:59:51.228698 |
description | Obtain the local network interface MTU towards a given IP address. |
homepage | https://github.com/mozilla/mtu/ |
repository | https://github.com/mozilla/mtu/ |
max_upload_size | |
id | 1360358 |
size | 61,301 |
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
.
This crate exports a single function interface_and_mtu
that, given a pair of local and remote SocketAddr
s, 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.
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}");
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.
We're happy to receive PRs that improve this crate. Please take a look at our community guidelines beforehand.