Fix for GetHostName. Now relies on native gethostname.
authorMads Pultz <mpultz@mono-cvs.ximian.com>
Wed, 2 Oct 2002 11:14:38 +0000 (11:14 -0000)
committerMads Pultz <mpultz@mono-cvs.ximian.com>
Wed, 2 Oct 2002 11:14:38 +0000 (11:14 -0000)
svn path=/trunk/mcs/; revision=7935

mcs/class/System/System.Net/Dns.cs

index c52c797508b92f32a6a6eb27d895b605a04b3cae..c6677c039277f14f69fdd78258825cb5c5e9a944 100644 (file)
@@ -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 {
                 /// <summary>
                 /// This method returns the host name associated with the local host.
                 /// </summary>
-               [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;
                 }
                 
                 /// <summary>