提交 d826f57a 编写于 作者: C clanger

8169865: Downport minor fixes in java.net native code from JDK 9 to JDK 8

Reviewed-by: chegar
上级 95dff3b9
/* /*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -75,18 +75,14 @@ Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) { ...@@ -75,18 +75,14 @@ Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
} else { } else {
// ensure null-terminated // ensure null-terminated
hostname[NI_MAXHOST] = '\0'; hostname[NI_MAXHOST] = '\0';
#if defined(__linux__) || defined(_ALLBSD_SOURCE)
/* On Linux/FreeBSD gethostname() says "host.domain.sun.com". On
* Solaris gethostname() says "host", so extra work is needed.
*/
#else
/* Solaris doesn't want to give us a fully qualified domain name. /* Solaris doesn't want to give us a fully qualified domain name.
* We do a reverse lookup to try and get one. This works * We do a reverse lookup to try and get one. This works
* if DNS occurs before NIS in /etc/resolv.conf, but fails * if DNS occurs before NIS in /etc/resolv.conf, but fails
* if NIS comes first (it still gets only a partial name). * if NIS comes first (it still gets only a partial name).
* We use thread-safe system calls. * We use thread-safe system calls.
*/ */
#ifdef AF_INET6 #if defined(__solaris__) && defined(AF_INET6)
struct addrinfo hints, *res; struct addrinfo hints, *res;
int error; int error;
...@@ -111,8 +107,7 @@ Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) { ...@@ -111,8 +107,7 @@ Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
freeaddrinfo(res); freeaddrinfo(res);
} }
#endif /* AF_INET6 */ #endif
#endif /* __linux__ || _ALLBSD_SOURCE */
} }
return (*env)->NewStringUTF(env, hostname); return (*env)->NewStringUTF(env, hostname);
} }
......
...@@ -333,6 +333,7 @@ jint IPv6_supported() ...@@ -333,6 +333,7 @@ jint IPv6_supported()
if (getsockname(0, (struct sockaddr *)&sa, &sa_len) == 0) { if (getsockname(0, (struct sockaddr *)&sa, &sa_len) == 0) {
struct sockaddr *saP = (struct sockaddr *)&sa; struct sockaddr *saP = (struct sockaddr *)&sa;
if (saP->sa_family != AF_INET6) { if (saP->sa_family != AF_INET6) {
close(fd);
return JNI_FALSE; return JNI_FALSE;
} }
} }
...@@ -1207,16 +1208,10 @@ NET_GetSockOpt(int fd, int level, int opt, void *result, ...@@ -1207,16 +1208,10 @@ NET_GetSockOpt(int fd, int level, int opt, void *result,
int *len) int *len)
{ {
int rv; int rv;
socklen_t socklen = *len;
#ifdef __solaris__ rv = getsockopt(fd, level, opt, result, &socklen);
rv = getsockopt(fd, level, opt, result, len); *len = socklen;
#else
{
socklen_t socklen = *len;
rv = getsockopt(fd, level, opt, result, &socklen);
*len = socklen;
}
#endif
if (rv < 0) { if (rv < 0) {
return rv; return rv;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册