1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
9 // gethostname syscall cannot be used because it also returns the domain.
10 // Therefore, hostname is retrieve with uname syscall and the Nodename field.
12 func hostname() (name string, err error) {
14 if errno := syscall.Uname(&u); errno != nil {
15 return "", NewSyscallError("uname", errno)
17 b := make([]byte, len(u.Nodename))
19 for ; i < len(u.Nodename); i++ {
20 if u.Nodename[i] == 0 {
23 b[i] = byte(u.Nodename[i])
25 return string(b[:i]), nil