提交 0422db50 编写于 作者: N ngmr

7114558: Inet4AddressImpl should use memset (rather than bzero) and NI_MAXHOST...

7114558: Inet4AddressImpl should use memset (rather than bzero) and NI_MAXHOST (rather than MAXHOSTNAMELEN)
Reviewed-by: chegar
Contributed-by: NNeil Richards <neil.richards@ngmr.net>
上级 24937a15
...@@ -65,11 +65,11 @@ Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) { ...@@ -65,11 +65,11 @@ Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
/* Something went wrong, maybe networking is not setup? */ /* Something went wrong, maybe networking is not setup? */
strcpy(hostname, "localhost"); strcpy(hostname, "localhost");
} else { } else {
hostname[NI_MAXHOST] = '\0'; struct addrinfo hints, *res;
struct addrinfo hints, *res;
int error; int error;
bzero(&hints, sizeof(hints)); hostname[NI_MAXHOST] = '\0';
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME; hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
...@@ -79,7 +79,7 @@ Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) { ...@@ -79,7 +79,7 @@ Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
getnameinfo(res->ai_addr, getnameinfo(res->ai_addr,
res->ai_addrlen, res->ai_addrlen,
hostname, hostname,
MAXHOSTNAMELEN, NI_MAXHOST,
NULL, NULL,
0, 0,
NI_NAMEREQD); NI_NAMEREQD);
...@@ -141,7 +141,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, ...@@ -141,7 +141,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
CHECK_NULL_RETURN(hostname, NULL); CHECK_NULL_RETURN(hostname, NULL);
/* Try once, with our static buffer. */ /* Try once, with our static buffer. */
bzero(&hints, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME; hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
...@@ -261,10 +261,9 @@ Java_java_net_Inet4AddressImpl_getHostByAddr(JNIEnv *env, jobject this, ...@@ -261,10 +261,9 @@ Java_java_net_Inet4AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
char host[NI_MAXHOST+1]; char host[NI_MAXHOST+1];
int error = 0; int error = 0;
int len = 0; int len = 0;
jbyte caddr[16]; jbyte caddr[4];
struct sockaddr_in him4; struct sockaddr_in him4;
struct sockaddr_in6 him6;
struct sockaddr *sa; struct sockaddr *sa;
jint addr; jint addr;
......
...@@ -85,7 +85,7 @@ Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) { ...@@ -85,7 +85,7 @@ Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
struct addrinfo hints, *res; struct addrinfo hints, *res;
int error; int error;
bzero(&hints, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME; hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
...@@ -188,7 +188,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, ...@@ -188,7 +188,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
= (*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID); = (*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID);
/* Try once, with our static buffer. */ /* Try once, with our static buffer. */
bzero(&hints, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME; hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册