From: Mads Pultz Date: Wed, 2 Oct 2002 11:14:38 +0000 (-0000) Subject: Fix for GetHostName. Now relies on native gethostname. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=e7dd68d618c35859f9b737594adc9082dde49202;p=mono.git Fix for GetHostName. Now relies on native gethostname. svn path=/trunk/mcs/; revision=7935 --- diff --git a/mcs/class/System/System.Net/Dns.cs b/mcs/class/System/System.Net/Dns.cs index c52c797508b..c6677c03927 100644 --- a/mcs/class/System/System.Net/Dns.cs +++ b/mcs/class/System/System.Net/Dns.cs @@ -63,6 +63,9 @@ namespace System.Net { [MethodImplAttribute(MethodImplOptions.InternalCall)] private extern static bool GetHostByAddr_internal(string addr, out string h_name, out string[] h_aliases, out string[] h_addr_list); + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern static bool GetHostName_internal(string addr); + private static IPHostEntry hostent_to_IPHostEntry(string h_name, string[] h_aliases, string[] h_addrlist) { IPHostEntry he = new IPHostEntry(); IPAddress[] addrlist = new IPAddress[h_addrlist.Length]; @@ -122,15 +125,16 @@ namespace System.Net { /// /// This method returns the host name associated with the local host. /// - [MonoTODO] public static string GetHostName() { - // - // This should really PInvoke into `gethostname', which is not the - // same thing as `127.0.0.1' which will be most likely localhost - // - IPHostEntry h = GetHostByAddress("127.0.0.1"); - return h.HostName; + string hostName = ""; + + bool ret = GetHostName_internal(hostName); + + if (ret == false) + throw new SocketException(11001); + + return hostName; } ///