MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / read_tap_host_ip

Function read_tap_host_ip

crates/openshell-driver-vm/src/runtime.rs:382–400  ·  view source on GitHub ↗

Read the first IPv4 address assigned to a network interface.

(device: &str)

Source from the content-addressed store, hash-verified

380
381/// Read the first IPv4 address assigned to a network interface.
382fn 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
402fn 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"])?;

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected