v/vlib/net/net.v

16 lines
372 B
V
Raw Normal View History

module net
2019-11-24 04:27:02 +01:00
fn C.gethostname() int
// hostname returns the host name reported by the kernel.
pub fn hostname() ?string {
2019-12-21 23:41:42 +01:00
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 {
return error('net.hostname: failed with $res')
}
2019-12-21 23:41:42 +01:00
return tos_clone(name)
}