diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index d6b4ed8f5ae..bc5770dbad5 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -522,12 +522,6 @@ internal static unsafe bool NonWindowsSetDate(DateTime dateToUse) return Unix.NativeMethods.SetDate(&tm) == 0; } - // Hostname in this context seems to be the FQDN - internal static string NonWindowsGetHostName() - { - return Unix.NativeMethods.GetFullyQualifiedName() ?? string.Empty; - } - internal static bool NonWindowsIsSameFileSystemItem(string pathOne, string pathTwo) { return Unix.NativeMethods.IsSameFileSystemItem(pathOne, pathTwo); @@ -690,10 +684,6 @@ internal static class NativeMethods [DllImport(psLib, CharSet = CharSet.Ansi)] internal static extern uint GetCurrentThreadId(); - [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] - [return: MarshalAs(UnmanagedType.LPStr)] - internal static extern string GetFullyQualifiedName(); - // This is a struct tm from [StructLayout(LayoutKind.Sequential)] internal unsafe struct UnixTm diff --git a/src/System.Management.Automation/utils/PsUtils.cs b/src/System.Management.Automation/utils/PsUtils.cs index c46871ad1c3..ced3c579135 100644 --- a/src/System.Management.Automation/utils/PsUtils.cs +++ b/src/System.Management.Automation/utils/PsUtils.cs @@ -7,6 +7,7 @@ using System.IO; using System.Linq; using System.Management.Automation.Language; +using System.Net.NetworkInformation; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -206,26 +207,16 @@ internal static string GetTemporaryDirectory() internal static string GetHostName() { - // Note: non-windows CoreCLR does not support System.Net yet - if (Platform.IsWindows) - { - return WinGetHostName(); - } - else - { - return Platform.NonWindowsGetHostName(); - } - } - - internal static string WinGetHostName() - { - System.Net.NetworkInformation.IPGlobalProperties ipProperties = - System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties(); + IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties(); string hostname = ipProperties.HostName; - if (!string.IsNullOrEmpty(ipProperties.DomainName)) + string domainName = ipProperties.DomainName; + + // CoreFX on Unix calls GLibc getdomainname() + // which returns "(none)" if a domain name is not set by setdomainname() + if (!string.IsNullOrEmpty(domainName) && !domainName.Equals("(none)", StringComparison.Ordinal)) { - hostname = hostname + "." + ipProperties.DomainName; + hostname = hostname + "." + domainName; } return hostname;