Read the first IPv4 address assigned to a network interface.
(device: &str)
| 380 | |
| 381 | /// Read the first IPv4 address assigned to a network interface. |
| 382 | fn read_tap_host_ip(device: &str) -> Option<String> { |
| 383 | let output = StdCommand::new("ip") |
| 384 | .args(["-4", "-o", "addr", "show", "dev", device]) |
| 385 | .stdin(Stdio::null()) |
| 386 | .stdout(Stdio::piped()) |
| 387 | .stderr(Stdio::null()) |
| 388 | .output() |
| 389 | .ok()?; |
| 390 | let stdout = String::from_utf8_lossy(&output.stdout); |
| 391 | // Format: "28: vmtap-xxx inet 10.0.128.1/30 ..." |
| 392 | for token in stdout.split_whitespace() { |
| 393 | if let Some((ip, _prefix)) = token.split_once('/') |
| 394 | && ip.parse::<std::net::Ipv4Addr>().is_ok() |
| 395 | { |
| 396 | return Some(ip.to_string()); |
| 397 | } |
| 398 | } |
| 399 | None |
| 400 | } |
| 401 | |
| 402 | fn setup_tap_networking(tap_device: &str, host_ip: &str, gateway_port: u16) -> Result<(), String> { |
| 403 | run_cmd("ip", &["tuntap", "add", "dev", tap_device, "mode", "tap"])?; |
no outgoing calls
no test coverage detected