2019-07-17 13:50:58 +02:00
|
|
|
module net
|
|
|
|
|
2019-10-09 20:01:31 +02:00
|
|
|
const (
|
|
|
|
_ = net.init()
|
|
|
|
)
|
|
|
|
|
2019-07-17 13:50:58 +02:00
|
|
|
// hostname returns the host name reported by the kernel.
|
|
|
|
pub fn hostname() ?string {
|
|
|
|
mut name := [256]byte
|
|
|
|
// 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-07-17 15:51:10 +02:00
|
|
|
return error('net.hostname() cannot get the host name')
|
2019-07-17 13:50:58 +02:00
|
|
|
}
|
|
|
|
return tos_clone(name)
|
|
|
|
}
|
2019-10-09 20:01:31 +02:00
|
|
|
|