diff --git a/CHANGELOG.md b/CHANGELOG.md index 77e4c0cb..dea721a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.36.2](https://github.com/open-amt-cloud-toolkit/rpc-go/compare/v2.36.1...v2.36.2) (2024-08-06) + + +### Bug Fixes + +* **cli:** Resolve FQDN on Linux machines with short hostnames ([#600](https://github.com/open-amt-cloud-toolkit/rpc-go/issues/600)) ([a2df614](https://github.com/open-amt-cloud-toolkit/rpc-go/commit/a2df61462461028ce32e0270029bb54a725f66af)), closes [#189](https://github.com/open-amt-cloud-toolkit/rpc-go/issues/189) + ## [2.36.1](https://github.com/open-amt-cloud-toolkit/rpc-go/compare/v2.36.0...v2.36.1) (2024-07-17) diff --git a/internal/amt/linux.go b/internal/amt/linux.go index d7dc9dd0..dc90673a 100644 --- a/internal/amt/linux.go +++ b/internal/amt/linux.go @@ -9,18 +9,42 @@ package amt import ( + "net" "os" "strings" ) func (amt AMTCommand) GetOSDNSSuffix() (string, error) { - hostname, err := os.Hostname() + fqdn, err := getFQDN() if err != nil { return "", err } - splitName := strings.SplitAfterN(hostname, ".", 2) + splitName := strings.SplitAfterN(fqdn, ".", 2) if len(splitName) == 2 { return splitName[1], nil } - return hostname, err + return fqdn, err +} + +func getFQDN() (string, error) { + hostname, err := os.Hostname() + if err != nil { + return "", err + } + + if strings.Contains(hostname, ".") { + return hostname, nil + } + + addrs, err := net.LookupHost(hostname) + if err != nil { + return "", err + } + + names, err := net.LookupAddr(addrs[0]) + if err != nil { + return "", err + } + + return strings.TrimSuffix(names[0], "."), nil }