E5DC Use IPGlobalProperties on all platforms by iSazonov · Pull Request #9530 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 <time.h>
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct UnixTm
Expand Down
25 changes: 8 additions & 17 deletions src/System.Management.Automation/utils/PsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
0