diff options
| author | diogo464 <[email protected]> | 2025-10-27 11:05:04 +0000 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-10-27 11:05:04 +0000 |
| commit | 13e689f6079697336ce3ae93099be059faa6d57b (patch) | |
| tree | c202ce86388c74091b314e029a53a48893b2f960 | |
| parent | 7b639f02cae0ed1684c837c27e5d2a5a65ec2b6b (diff) | |
added --interface flag
| -rw-r--r-- | src/main.rs | 20 |
1 files changed, 15 insertions, 5 deletions
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 { | |||
| 24 | #[clap(long)] | 24 | #[clap(long)] |
| 25 | hostname: Option<String>, | 25 | hostname: Option<String>, |
| 26 | 26 | ||
| 27 | #[clap(long)] | ||
| 28 | interface: Option<String>, | ||
| 29 | |||
| 27 | #[clap(long, default_value = "0.0.0.0")] | 30 | #[clap(long, default_value = "0.0.0.0")] |
| 28 | listen_address: Ipv4Addr, | 31 | listen_address: Ipv4Addr, |
| 29 | 32 | ||
| @@ -58,7 +61,14 @@ fn main() { | |||
| 58 | .expect("unable to convert local machine's hostname to utf-8 string") | 61 | .expect("unable to convert local machine's hostname to utf-8 string") |
| 59 | } | 62 | } |
| 60 | }; | 63 | }; |
| 61 | let local_ip_address = if cli.listen_address == Ipv4Addr::UNSPECIFIED { | 64 | let local_ip_address = if let Some(interface_name) = cli.interface { |
| 65 | let interfaces = list_network_interfaces().expect("unable to list network interfaces"); | ||
| 66 | let interface = interfaces | ||
| 67 | .iter() | ||
| 68 | .find(|i| i.interface == interface_name) | ||
| 69 | .expect("interface not found"); | ||
| 70 | interface.address | ||
| 71 | } else if cli.listen_address == Ipv4Addr::UNSPECIFIED { | ||
| 62 | let interfaces = list_network_interfaces().expect("unable to list network interfaces"); | 72 | let interfaces = list_network_interfaces().expect("unable to list network interfaces"); |
| 63 | let mut chosen = None; | 73 | let mut chosen = None; |
| 64 | for interface in interfaces { | 74 | for interface in interfaces { |
| @@ -238,10 +248,10 @@ fn handle_packet_4011(context: &Context, buf: &[u8], socket: &UdpSocket, sender_ | |||
| 238 | if let DhcpOption::VendorClassIdentifier(vendor_class) = option | 248 | if let DhcpOption::VendorClassIdentifier(vendor_class) = option |
| 239 | && let Ok(dhcp::PxeClassIdentifier::Client(class)) = | 249 | && let Ok(dhcp::PxeClassIdentifier::Client(class)) = |
| 240 | dhcp::PxeClassIdentifier::try_from(vendor_class.as_slice()) | 250 | dhcp::PxeClassIdentifier::try_from(vendor_class.as_slice()) |
| 241 | { | 251 | { |
| 242 | println!("{class}"); | 252 | println!("{class}"); |
| 243 | client_class = Some(class); | 253 | client_class = Some(class); |
| 244 | } | 254 | } |
| 245 | } | 255 | } |
| 246 | let client_class = match client_class { | 256 | let client_class = match client_class { |
| 247 | Some(class) => class, | 257 | Some(class) => class, |
