1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/net/net.v

17 lines
402 B
V
Raw Normal View History

module net
2019-11-24 06:27:02 +03:00
fn C.gethostname() int
// 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.
2020-05-18 22:38:06 +03:00
namebp := byteptr(name)
res := C.gethostname(namebp, 256)
if res != 0 {
return error('net.hostname: failed with $res')
}
2020-05-18 22:38:06 +03:00
return tos_clone(namebp)
}