| 1 |
[](https://codecov.io/gh/mozilla/mtu) |
| 2 |
[](https://isitmaintained.com/project/mozilla/mtu "Average time to resolve an issue") |
| 3 |
[](https://isitmaintained.com/project/mozilla/mtu "Percentage of issues still open") |
| 4 |
 |
| 5 |
|
| 6 |
# mtu |
| 7 |
|
| 8 |
A crate to return the name and maximum transmission unit (MTU) of the local network interface |
| 9 |
towards a given destination `SocketAddr`, optionally from a given local `SocketAddr`. |
| 10 |
|
| 11 |
## Usage |
| 12 |
|
| 13 |
This crate exports a single function `interface_and_mtu` that returns the name and |
| 14 |
[maximum transmission unit (MTU)](https://en.wikipedia.org/wiki/Maximum_transmission_unit) |
| 15 |
of the outgoing network interface towards a remote destination identified by an `IpAddr`. |
| 16 |
|
| 17 |
## Example |
| 18 |
```rust |
| 19 |
let destination = IpAddr::V4(Ipv4Addr::LOCALHOST); |
| 20 |
let (name, mtu): (String, usize) = mtu::interface_and_mtu(destination).unwrap(); |
| 21 |
println!("MTU towards {destination} is {mtu} on {name}"); |
| 22 |
``` |
| 23 |
|
| 24 |
## Supported Platforms |
| 25 |
|
| 26 |
* Linux |
| 27 |
* macOS |
| 28 |
* Windows |
| 29 |
* FreeBSD |
| 30 |
* NetBSD |
| 31 |
* OpenBSD |
| 32 |
* Solaris |
| 33 |
|
| 34 |
## Notes |
| 35 |
|
| 36 |
The returned MTU may exceed the maximum IP packet size of 65,535 bytes on some platforms for |
| 37 |
some remote destinations. (For example, loopback destinations on Windows.) |
| 38 |
|
| 39 |
The returned interface name is obtained from the operating system. |
| 40 |
|
| 41 |
## Contributing |
| 42 |
|
| 43 |
We're happy to receive PRs that improve this crate. Please take a look at our [community |
| 44 |
guidelines](CODE_OF_CONDUCT.md) beforehand. |
| 45 |
|
| 46 |
License: MIT OR Apache-2.0 |