From ac3cb7fc727a63c5e547c96950ada32bf83a7bd2 Mon Sep 17 00:00:00 2001 From: Dominik Hassler Date: Fri, 28 Jun 2024 16:40:46 +0000 Subject: [PATCH] add illumos support --- Cargo.toml | 3 +++ README.md | 9 ++++++++- src/lib.rs | 19 ++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 558b8fe..5bc9f36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,9 @@ Get os native machine id without root permission. [target.'cfg(windows)'.dependencies] winreg = "0.51" +[target.'cfg(target_os = "illumos")'.dependencies] +libc = "0.2.155" + # [target.'cfg(windows)'.build-dependencies] [build-dependencies] cc = "1.0" diff --git a/README.md b/README.md index be3eca3..11fb914 100644 --- a/README.md +++ b/README.md @@ -63,15 +63,22 @@ Windows: (Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography).MachineGuid ``` +illumos: + +```Bash +gethostid(3C) +``` + ### Supported Platform I have tested in following platform: - Debian 8 - OS X 10.6 -- FeeBSD 10.4 +- FreeBSD 10.4 - Fedora 28 - Windows 10 +- OmniOS r151050 ### Changelog diff --git a/src/lib.rs b/src/lib.rs index 2062aee..e0b39d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,15 +50,22 @@ //! (Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography).MachineGuid //! ``` //! +//! illumos: +//! +//! ```Bash +//! gethostid(3C) +//! ``` +//! //! ## Supported Platform //! //! I have tested in following platform: //! //! - Debian 8 //! - OS X 10.6 -//! - FeeBSD 10.4 +//! - FreeBSD 10.4 //! - Fedora 28 //! - Windows 10 +//! - OmniOS r151050 //! use std::error::Error; @@ -180,4 +187,14 @@ pub mod machine_id { } } +#[cfg(target_os = "illumos")] +pub mod machine_id { + use std::error::Error; + + /// Return machine id + pub fn get_machine_id() -> Result> { + Ok(format!("{:x}", unsafe { libc::gethostid() })) + } +} + pub use machine_id::get_machine_id as get;