Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mozilla/mtu
Rust crate for obtaining the local network interface name and MTU towards a given IP address
https://github.com/mozilla/mtu
interface mozilla mtu
Last synced: about 1 month ago
JSON representation
Rust crate for obtaining the local network interface name and MTU towards a given IP address
- Host: GitHub
- URL: https://github.com/mozilla/mtu
- Owner: mozilla
- License: apache-2.0
- Created: 2024-08-30T12:27:11.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-10-03T07:59:43.000Z (about 1 month ago)
- Last Synced: 2024-10-05T18:24:08.242Z (about 1 month ago)
- Topics: interface, mozilla, mtu
- Language: Rust
- Homepage: https://crates.io/crates/mtu
- Size: 160 KB
- Stars: 11
- Watchers: 5
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
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 `SocketAddr`s, returns the name and [maximum transmission unit (MTU)](https://en.wikipedia.org/wiki/Maximum_transmission_unit) 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
```rust
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## 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](CODE_OF_CONDUCT.md) beforehand.