From 13e689f6079697336ce3ae93099be059faa6d57b Mon Sep 17 00:00:00 2001 From: diogo464 Date: Mon, 27 Oct 2025 11:05:04 +0000 Subject: added --interface flag --- src/main.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 819d656..277d8ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,9 @@ struct Cli { #[clap(long)] hostname: Option, + #[clap(long)] + interface: Option, + #[clap(long, default_value = "0.0.0.0")] listen_address: Ipv4Addr, @@ -58,7 +61,14 @@ fn main() { .expect("unable to convert local machine's hostname to utf-8 string") } }; - let local_ip_address = if cli.listen_address == Ipv4Addr::UNSPECIFIED { + let local_ip_address = if let Some(interface_name) = cli.interface { + let interfaces = list_network_interfaces().expect("unable to list network interfaces"); + let interface = interfaces + .iter() + .find(|i| i.interface == interface_name) + .expect("interface not found"); + interface.address + } else if cli.listen_address == Ipv4Addr::UNSPECIFIED { let interfaces = list_network_interfaces().expect("unable to list network interfaces"); let mut chosen = None; for interface in interfaces { @@ -238,10 +248,10 @@ fn handle_packet_4011(context: &Context, buf: &[u8], socket: &UdpSocket, sender_ if let DhcpOption::VendorClassIdentifier(vendor_class) = option && let Ok(dhcp::PxeClassIdentifier::Client(class)) = dhcp::PxeClassIdentifier::try_from(vendor_class.as_slice()) - { - println!("{class}"); - client_class = Some(class); - } + { + println!("{class}"); + client_class = Some(class); + } } let client_class = match client_class { Some(class) => class, -- cgit