#![allow(unsafe_code)]
#![allow(
clippy::missing_safety_doc,
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
clippy::cast_possible_wrap,
clippy::missing_const_for_fn,
clippy::needless_pass_by_value
)]
#![allow(missing_docs)]
#[cfg(target_os = "macos")]
pub mod block;
#[cfg(target_os = "macos")]
pub mod dispatch;
#[cfg(target_os = "macos")]
pub mod iface_impl;
#[cfg(target_os = "macos")]
pub mod vmnet;
#[cfg(target_os = "macos")]
pub mod xpc;
pub fn kill_pid(pid: u32, signum: i32) -> bool {
let Ok(pid_i32) = i32::try_from(pid) else {
return false;
};
if pid_i32 <= 0 {
return false;
}
let rc = unsafe { libc::kill(pid_i32, signum) };
rc == 0
}
#[repr(u32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum VmnetReturn {
Success = 1000,
Failure = 1001,
MemFailure = 1002,
InvalidArgument = 1003,
SetupIncomplete = 1004,
InvalidAccess = 1005,
PacketTooBig = 1006,
BufferExhausted = 1007,
TooManyPackets = 1008,
SharingServiceBusy = 1009,
Unknown = u32::MAX,
}
impl VmnetReturn {
#[must_use]
pub fn from_raw(raw: u32) -> Self {
match raw {
1000 => Self::Success,
1001 => Self::Failure,
1002 => Self::MemFailure,
1003 => Self::InvalidArgument,
1004 => Self::SetupIncomplete,
1005 => Self::InvalidAccess,
1006 => Self::PacketTooBig,
1007 => Self::BufferExhausted,
1008 => Self::TooManyPackets,
1009 => Self::SharingServiceBusy,
_ => Self::Unknown,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_should_decode_known_vmnet_return_codes() {
assert_eq!(VmnetReturn::from_raw(1000), VmnetReturn::Success);
assert_eq!(VmnetReturn::from_raw(1001), VmnetReturn::Failure);
assert_eq!(VmnetReturn::from_raw(1009), VmnetReturn::SharingServiceBusy);
}
#[test]
fn test_should_preserve_unknown_vmnet_return_codes() {
assert_eq!(VmnetReturn::from_raw(99_999), VmnetReturn::Unknown);
}
}