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