Add some basic cli

This commit is contained in:
2024-08-24 14:48:26 +02:00
parent 57e94d576a
commit b3ec1bf1bf
3 changed files with 135 additions and 11 deletions

View File

@@ -1,3 +1,4 @@
use clap::Parser;
use dhcproto::{
Decodable,
Decoder,
@@ -13,28 +14,30 @@ use dhcproto::{
};
use ipnetwork;
use pnet;
use std::{
env,
net::SocketAddrV6,
};
use std::net::SocketAddrV6;
use tokio::net::UdpSocket;
const ALL_DHCP_RELAY_AGENTS_AND_SERVERS: &str = "ff02::1:2";
const DHCP_CLIENT_PORT: u16 = 546;
const DHCP_RELAY_AGENT_AND_SERVER_PORT: u16 = 547;
/// Requests some simple parameters using DHCPv6 from specified network
#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Cli {
/// Network interface name used for DHCPv6
interface: String,
}
#[tokio::main]
async fn main() {
let mut args = env::args();
args.next(); // Skip executable name
// First argument is interface name
let interface_name = args.next().expect("No interface name specified");
let cli = Cli::parse();
let all_interfaces = pnet::datalink::interfaces();
let selected_interface = all_interfaces
.iter()
.find(|i| i.name == interface_name)
.expect(format!("No interface found with name: {}", interface_name).as_str());
.find(|i| i.name == cli.interface)
.expect(format!("No interface found with name: {}", cli.interface).as_str());
let ipv6_addresses = selected_interface.ips
.iter()