Get mac addr for tap interface.
(&self)
| 394 | |
| 395 | /// Get mac addr for tap interface. |
| 396 | pub fn get_mac_addr(&self) -> Result<MacAddr> { |
| 397 | let sock = create_unix_socket().map_err(Error::NetUtil)?; |
| 398 | |
| 399 | let ifreq = self.get_ifreq(); |
| 400 | |
| 401 | // SAFETY: ioctl is safe. Called with a valid sock fd, and we check the return. |
| 402 | unsafe { Self::ioctl_with_ref(&sock, libc::SIOCGIFHWADDR as c_ulong, &ifreq)? }; |
| 403 | |
| 404 | let addr = { |
| 405 | let bytes: Vec<u8> = |
| 406 | // SAFETY: The `ioctl_with_ref` ensures accessing `ifru_hwaddr` is valid. |
| 407 | unsafe { ifreq.ifr_ifru.ifru_hwaddr.sa_data[0..MAC_ADDR_LEN].iter() } |
| 408 | .map(|byte| { |
| 409 | // On some architectures, `c_char` is already a `u8`. |
| 410 | #[allow(clippy::unnecessary_cast)] |
| 411 | { |
| 412 | *byte as u8 |
| 413 | } |
| 414 | }) |
| 415 | .collect(); |
| 416 | MacAddr::from_bytes(&bytes).map_err(Error::MacParsing)? |
| 417 | }; |
| 418 | Ok(addr) |
| 419 | } |
| 420 | |
| 421 | #[cfg(not(fuzzing))] |
| 422 | pub fn mtu(&self) -> Result<i32> { |
no test coverage detected