Crates.io | brctl |
lib.rs | brctl |
version | 1.0.0 |
source | src |
created_at | 2024-09-22 07:53:36.137764 |
updated_at | 2024-09-22 09:01:01.448272 |
description | A wrapper for brctl(ethernet bridge administration) |
homepage | |
repository | https://github.com/ViniciosLugli/brctl-rs |
max_upload_size | |
id | 1382795 |
size | 58,730 |
This project is a Rust wrapper for the brctl
command-line tool used for Ethernet bridge administration on Linux systems. It provides a clean, programmatic interface for creating, managing, and inspecting network bridges, allowing Rust developers to interact with brctl
and related networking utilities(like ip
) in a more user-friendly manner.
brctl
and ip
utilities are available and properly configured.Linux: This wrapper is designed for Linux systems, as brctl
is a Linux-specific utility.
bridge-utils
package on most Linux distributions.iproute2
.Ensure both utilities are installed on your system for full functionality of this wrapper.
You can find this example on examples/basic.rs.
use brctl::{BridgeController, CommandError};
fn main() -> Result<(), CommandError> {
// Initialize logging, if you want to see logs, set the RUST_LOG environment variable
env_logger::init();
// Check if the system is ready for bridge operations
match BridgeController::check() {
Ok((brctl_version, interfaces)) => {
println!("brctl version: {}", brctl_version);
println!("Available interfaces: {:?}", interfaces);
}
Err(e) => eprintln!("System not ready: {}", e),
}
// Create a new bridge
let mybridge = BridgeController::create_bridge("mybridge")?;
mybridge.add_interface("eth0")?;
mybridge.add_interface("eth1")?;
// List all bridges
let bridges = BridgeController::list_bridges()?;
println!("Available bridges:");
for bridge in bridges {
println!(" - {}", bridge);
}
// Retrieve bridge details
let bridge_name = mybridge.get_name();
println!("Bridge Name: {}", bridge_name);
println!("Bridge ID: {}", mybridge.get_id()?);
println!("Spanning Tree Protocol: {}", mybridge.get_stp()?);
// Delete the bridge
mybridge.delete()?;
println!("Bridge deleted successfully");
Ok(())
}
Add the following to your Cargo.toml
file:
[dependencies]
brctl = "1.0.0"
now you can use the crate in your project 🦀!
This project is licensed under the GPL-3.0. For more information, see the LICENSE file.
Contributions are welcome! Please submit issues or pull requests to the repository at: GitHub - ViniciosLugli/brctl-rs