diff options
Diffstat (limited to 'hostinfo/hostname_macos.go')
| -rw-r--r-- | hostinfo/hostname_macos.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/hostinfo/hostname_macos.go b/hostinfo/hostname_macos.go new file mode 100644 index 000000000..1a67f92e5 --- /dev/null +++ b/hostinfo/hostname_macos.go @@ -0,0 +1,30 @@ +// Copyright (c) Tailscale Inc & AUTHORS +// SPDX-License-Identifier: BSD-3-Clause + +//go:build cgo && darwin && !ios + +package hostinfo + +/* +#cgo CFLAGS: -x objective-c +#cgo LDFLAGS: -framework Foundation +#import <Foundation/Foundation.h> + +const char *getHostname() { + NSString *hostname = [[NSHost currentHost] localizedName]; + if (hostname != nil) { + const char *hostnameCString = [hostname UTF8String]; + if (hostnameCString != NULL) { + return strdup(hostnameCString); + } + } + return NULL; +} +*/ +import "C" + +func GetHostname() string { + chn := C.getHostname() + hostname := C.GoString(chn) + return hostname +} |
