--- a/src/java.base/unix/native/libnet/Inet4AddressImpl.c Thu May 03 15:17:27 2018 +0200
+++ b/src/java.base/unix/native/libnet/Inet4AddressImpl.c Fri May 04 14:37:58 2018 +0100
@@ -41,11 +41,6 @@
extern jobjectArray lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6);
#endif
-/* the initial size of our hostent buffers */
-#ifndef NI_MAXHOST
-#define NI_MAXHOST 1025
-#endif
-
#define SET_NONBLOCKING(fd) { \
int flags = fcntl(fd, F_GETFL); \
flags |= O_NONBLOCK; \
@@ -66,10 +61,10 @@
char hostname[NI_MAXHOST + 1];
hostname[0] = '\0';
- if (gethostname(hostname, NI_MAXHOST) != 0) {
+ if (gethostname(hostname, sizeof(hostname)) != 0) {
strcpy(hostname, "localhost");
+ } else {
#if defined(__solaris__)
- } else {
// try to resolve hostname via nameservice
// if it is known but getnameinfo fails, hostname will still be the
// value from gethostname
@@ -82,17 +77,15 @@
hints.ai_family = AF_INET;
if (getaddrinfo(hostname, NULL, &hints, &res) == 0) {
- getnameinfo(res->ai_addr, res->ai_addrlen, hostname, NI_MAXHOST,
+ getnameinfo(res->ai_addr, res->ai_addrlen, hostname, sizeof(hostname),
NULL, 0, NI_NAMEREQD);
freeaddrinfo(res);
}
- }
#else
- } else {
// make sure string is null-terminated
hostname[NI_MAXHOST] = '\0';
+#endif
}
-#endif
return (*env)->NewStringUTF(env, hostname);
}
@@ -248,7 +241,7 @@
sa.sin_family = AF_INET;
if (getnameinfo((struct sockaddr *)&sa, sizeof(struct sockaddr_in),
- host, NI_MAXHOST, NULL, 0, NI_NAMEREQD)) {
+ host, sizeof(host), NULL, 0, NI_NAMEREQD)) {
JNU_ThrowByName(env, "java/net/UnknownHostException", NULL);
} else {
ret = (*env)->NewStringUTF(env, host);