TAP device name from sandbox ID (fits `IFNAMSIZ=16`).
(sandbox_id: &str)
| 251 | |
| 252 | /// TAP device name from sandbox ID (fits `IFNAMSIZ=16`). |
| 253 | pub fn tap_device_name(sandbox_id: &str) -> String { |
| 254 | let mut end = sandbox_id.len().min(8); |
| 255 | // Walk back to a UTF-8 char boundary (str::floor_char_boundary requires |
| 256 | // Rust 1.91 — we still build on older toolchains). |
| 257 | while end > 0 && !sandbox_id.is_char_boundary(end) { |
| 258 | end -= 1; |
| 259 | } |
| 260 | let prefix = &sandbox_id[..end]; |
| 261 | format!("vmtap-{prefix}") |
| 262 | } |
| 263 | |
| 264 | #[cfg(test)] |
| 265 | mod tests { |