oshostname
Get the current hostname with gethostname(2)
Wraps a native library — check OS Compatibility below for platform-specific linking notes.
Summary
| Latest Version | Unknown |
|---|---|
| License | MIT |
| CI Status | Passing |
| Downloads | 0 |
| Last Indexed | 2026-07-21 05:24 |
Tags
Installation
nimble install oshostname
choosenim install oshostname
git clone https://github.com/jrfondren/nim-oshostname
OS Compatibility
| Platform | Linux | macOS | Windows | FreeBSD | OpenBSD | NetBSD | Android | iOS | WASM | Embedded |
|---|---|---|---|---|---|---|---|---|---|---|
| oshostname | ✓ | ✓ | ✓ | - | - | - | - | - | - | - |
Source
| Repository | https://github.com/jrfondren/nim-oshostname |
|---|---|
| Homepage | https://github.com/jrfondren/nim-oshostname |
| Documentation | View Documentation |
| Registry Source | nimble_official |
README
oshostname
Get the current hostname with gethostname(2)
Support platforms
Currently, just any that support gethostname() similarly to Linux.
Why even use this?
EDIT: don't. I don't know how i missed it, but std/nativeosckets has getHostname() already, for windows and Posix platforms, including macOS.
gethostname() has this gotcha: if the configured hostname is longer than the buffer given to it, then the buffer might not be NUL terminated. This library takes the small amount of care required to avoid this case.
In the future it might also grow support for other platforms.
Usage
Add the following to your .nimble file:
requires "oshostname >= 0.1.0"
Then use the provided hostname() proc:
import oshostname, options
echo hostname().get
In this code, if gethostbyname() fails, that .get will fail with an
UnpackDefect.