tailscale/hostinfo/hostname.go
Andrea Gottardo 05787423d2 hostinfo: use Foundation APIs to get hostname on macOS
Updates tailscale/corp#22332

This PR changes the way we determine the current hostname on Darwin && !iOS builds. We now use the native NSHost.currentHost API to get the hostname, instead of the os.Hostname() call which in Go uses `sysctl kern.hostname`. In Sequoia, this appears to always return `Mac.home`, (`home` comes from my LAN).

Signed-off-by: Andrea Gottardo <andrea@gottardo.me>
2024-08-14 13:58:58 -07:00

14 lines
214 B
Go

// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
//go:build !(cgo && darwin && !ios)
package hostinfo
import "os"
func GetHostname() string {
h, _ := os.Hostname()
return h
}