changeset 50312:a838e3707f3a

8201369: Inet4AddressImpl_getLocalHostName reverse lookup on Solaris only Reviewed-by: clanger, chegar Contributed-by: sshamaia@in.ibm.com
author clanger
date Mon, 16 Apr 2018 12:50:10 +0530
parents a3e79f97e86b
children e57e6addb978 0540b802b24e
files src/java.base/unix/native/libnet/Inet4AddressImpl.c
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/unix/native/libnet/Inet4AddressImpl.c	Wed Apr 18 10:39:40 2018 -0400
+++ b/src/java.base/unix/native/libnet/Inet4AddressImpl.c	Mon Apr 16 12:50:10 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -68,6 +68,7 @@
     hostname[0] = '\0';
     if (gethostname(hostname, NI_MAXHOST) != 0) {
         strcpy(hostname, "localhost");
+#if defined(__solaris__)
     } else {
         // try to resolve hostname via nameservice
         // if it is known but getnameinfo fails, hostname will still be the
@@ -86,6 +87,12 @@
             freeaddrinfo(res);
         }
     }
+#else
+    } else {
+        // make sure string is null-terminated
+        hostname[NI_MAXHOST] = '\0';
+    }
+#endif
     return (*env)->NewStringUTF(env, hostname);
 }