2019-07-17 14:50:58 +03:00
|
|
|
module net
|
|
|
|
|
2019-11-24 06:27:02 +03:00
|
|
|
fn C.gethostname() int
|
|
|
|
// hostname returns the host name reported by the kernel.
|
2019-07-17 14:50:58 +03:00
|
|
|
pub fn hostname() ?string {
|
2019-12-22 01:41:42 +03:00
|
|
|
mut name := [256]byte
|
2019-07-17 14:50:58 +03:00
|
|
|
// https://www.ietf.org/rfc/rfc1035.txt
|
|
|
|
// The host name is returned as a null-terminated string.
|
|
|
|
res := C.gethostname(&name, 256)
|
|
|
|
if res != 0 {
|
2019-11-12 19:23:53 +03:00
|
|
|
return error('net.hostname: failed with $res')
|
2019-07-17 14:50:58 +03:00
|
|
|
}
|
2019-12-22 01:41:42 +03:00
|
|
|
return tos_clone(name)
|
2019-07-17 14:50:58 +03:00
|
|
|
}
|
2019-10-09 21:01:31 +03:00
|
|
|
|