| 1 | use crate::ffi::OsString; |
| 2 | |
| 3 | /// Returns the system hostname. |
| 4 | /// |
| 5 | /// This can error out in platform-specific error cases; |
| 6 | /// for example, uefi and wasm, where hostnames aren't |
| 7 | /// supported. |
| 8 | /// |
| 9 | /// # Underlying system calls |
| 10 | /// |
| 11 | /// | Platform | System call | |
| 12 | /// |--------------|---------------------------------------------------------------------------------------------------------| |
| 13 | /// | UNIX | [`gethostname`](https://www.man7.org/linux/man-pages/man2/gethostname.2.html) | |
| 14 | /// | Windows (8+) | [`GetHostNameW`](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-gethostnamew) | |
| 15 | /// |
| 16 | /// Note that platform-specific behavior [may change in the future][changes]. |
| 17 | /// |
| 18 | /// [changes]: crate::io#platform-specific-behavior |
| 19 | #[unstable (feature = "gethostname" , issue = "135142" )] |
| 20 | pub fn hostname() -> crate::io::Result<OsString> { |
| 21 | crate::sys::net::hostname() |
| 22 | } |
| 23 | |