Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add illumos support #11

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 18 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Box<dyn Error>> {
Ok(format!("{:x}", unsafe { libc::gethostid() }))
}
}

pub use machine_id::get_machine_id as get;
Loading