[icall/GetMachineName] Use sysconf if available to capture the whole host name, fall...
authorMiguel de Icaza <miguel@gnome.org>
Fri, 18 Dec 2015 18:10:37 +0000 (13:10 -0500)
committerMiguel de Icaza <miguel@gnome.org>
Fri, 18 Dec 2015 18:10:46 +0000 (13:10 -0500)
mono/metadata/icall.c

index 93433b6d9b9292bde5389d4be5872c3a65d2e714..f572212d08cb96dab4dbf26d7bbbc4ec2d160d29 100644 (file)
@@ -5830,13 +5830,22 @@ ves_icall_System_Environment_get_MachineName (void)
        g_free (buf);
        return result;
 #elif !defined(DISABLE_SOCKETS)
-       gchar buf [256];
        MonoString *result;
-
-       if (gethostname (buf, sizeof (buf)) == 0)
+       char *buf;
+       int n;
+#if defined _SC_HOST_NAME_MAX
+       n = sysconf (_SC_HOST_NAME_MAX);
+       if (n == -1)
+#endif
+       n = 512;
+       buf = g_malloc (n+1);
+       
+       if (gethostname (buf, n) == 0){
+               buf [n] = 0;
                result = mono_string_new (mono_domain_get (), buf);
-       else
+       else
                result = NULL;
+       g_free (buf);
        
        return result;
 #else