8080990: libdt_socket/socket_md.c(202) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW()
Reviewed-by: erikj, clanger, chegar
This commit is contained in:
parent
2f8f0b23cd
commit
40f004ad8c
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2011, 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
|
||||
@ -918,7 +918,6 @@ AC_DEFUN([FLAGS_SETUP_COMPILER_FLAGS_FOR_JDK_HELPER],
|
||||
-MD -Zc:wchar_t- -W3 -wd4800 \
|
||||
-DWIN32_LEAN_AND_MEAN \
|
||||
-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE \
|
||||
-D_WINSOCK_DEPRECATED_NO_WARNINGS \
|
||||
-DWIN32 -DIAL"
|
||||
if test "x$OPENJDK_$1_CPU" = xx86_64; then
|
||||
$2COMMON_CCXXFLAGS_JDK="[$]$2COMMON_CCXXFLAGS_JDK -D_AMD64_ -Damd64"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 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
|
||||
@ -525,7 +525,7 @@ NET_SocketClose(int fd) {
|
||||
int len = sizeof (l);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&l, &len) == 0) {
|
||||
if (l.l_onoff == 0) {
|
||||
WSASendDisconnect(fd, NULL);
|
||||
shutdown(fd, SD_SEND);
|
||||
}
|
||||
}
|
||||
ret = closesocket (fd);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2017, 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
|
||||
@ -272,7 +272,7 @@ Java_sun_nio_ch_SocketDispatcher_preClose0(JNIEnv *env, jclass clazz,
|
||||
int len = sizeof(l);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&l, &len) == 0) {
|
||||
if (l.l_onoff == 0) {
|
||||
WSASendDisconnect(fd, NULL);
|
||||
shutdown(fd, SD_SEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 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
|
||||
@ -228,6 +228,7 @@ getLocalHostAddress() {
|
||||
// it looks up "localhost" and returns 127.0.0.1 if lookup
|
||||
// fails.
|
||||
struct addrinfo hints, *res = NULL;
|
||||
uint32_t addr;
|
||||
int err;
|
||||
|
||||
// Use portable way to initialize the structure
|
||||
@ -241,7 +242,9 @@ getLocalHostAddress() {
|
||||
|
||||
// getaddrinfo might return more than one address
|
||||
// but we are using first one only
|
||||
return ((struct sockaddr_in *)(res->ai_addr))->sin_addr.s_addr;
|
||||
addr = ((struct sockaddr_in *)(res->ai_addr))->sin_addr.s_addr;
|
||||
freeaddrinfo(res);
|
||||
return addr;
|
||||
}
|
||||
|
||||
static int
|
||||
@ -300,7 +303,7 @@ parseAddress(const char *address, struct sockaddr_in *sa) {
|
||||
char *buf;
|
||||
char *hostname;
|
||||
uint32_t addr;
|
||||
|
||||
int ai;
|
||||
buf = (*callback->alloc)((int)strlen(address) + 1);
|
||||
if (buf == NULL) {
|
||||
RETURN_ERROR(JDWPTRANSPORT_ERROR_OUT_OF_MEMORY, "out of memory");
|
||||
@ -315,16 +318,25 @@ parseAddress(const char *address, struct sockaddr_in *sa) {
|
||||
*/
|
||||
addr = dbgsysInetAddr(hostname);
|
||||
if (addr == 0xffffffff) {
|
||||
struct hostent *hp = dbgsysGetHostByName(hostname);
|
||||
if (hp == NULL) {
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *results = NULL;
|
||||
memset (&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
|
||||
ai = dbgsysGetAddrInfo(hostname, NULL, &hints, &results);
|
||||
|
||||
if (ai != 0) {
|
||||
/* don't use RETURN_IO_ERROR as unknown host is normal */
|
||||
setLastError(0, "gethostbyname: unknown host");
|
||||
setLastError(0, "getaddrinfo: unknown host");
|
||||
(*callback->free)(buf);
|
||||
return JDWPTRANSPORT_ERROR_IO_ERROR;
|
||||
}
|
||||
|
||||
/* lookup was successful */
|
||||
memcpy(&(sa->sin_addr), hp->h_addr_list[0], hp->h_length);
|
||||
sa->sin_addr = ((struct sockaddr_in *)results->ai_addr)->sin_addr;
|
||||
freeaddrinfo(results);
|
||||
} else {
|
||||
sa->sin_addr.s_addr = addr;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 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
|
||||
@ -47,7 +47,7 @@ int dbgsysRecvFrom(int fd, char *buf, size_t nBytes, int flags, struct sockaddr
|
||||
int dbgsysListen(int fd, int backlog);
|
||||
int dbgsysRecv(int fd, char *buf, size_t nBytes, int flags);
|
||||
int dbgsysSend(int fd, char *buf, size_t nBytes, int flags);
|
||||
struct hostent *dbgsysGetHostByName(char *hostname);
|
||||
int dbgsysGetAddrInfo(char *hostname, char *service, struct addrinfo *hints, struct addrinfo **results);
|
||||
int dbgsysSocket(int domain, int type, int protocol);
|
||||
int dbgsysBind(int fd, struct sockaddr *name, socklen_t namelen);
|
||||
int dbgsysSetSocketOption(int fd, jint cmd, jboolean on, jvalue value);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 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
|
||||
@ -126,9 +126,11 @@ dbgsysSend(int fd, char *buf, size_t nBytes, int flags) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
struct hostent *
|
||||
dbgsysGetHostByName(char *hostname) {
|
||||
return gethostbyname(hostname);
|
||||
int
|
||||
dbgsysGetAddrInfo(char *hostname, char *service,
|
||||
struct addrinfo *hints,
|
||||
struct addrinfo **results) {
|
||||
return getaddrinfo(hostname, service, hints, results);
|
||||
}
|
||||
|
||||
unsigned short
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 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
|
||||
@ -24,6 +24,7 @@
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#include "sysSocket.h"
|
||||
#include "socketTransport.h"
|
||||
@ -197,9 +198,11 @@ dbgsysSend(int fd, char *buf, size_t nBytes, int flags) {
|
||||
return send(fd, buf, (int)nBytes, flags);
|
||||
}
|
||||
|
||||
struct hostent *
|
||||
dbgsysGetHostByName(char *hostname) {
|
||||
return gethostbyname(hostname);
|
||||
int
|
||||
dbgsysGetAddrInfo(char *hostname, char *service,
|
||||
struct addrinfo *hints,
|
||||
struct addrinfo **result) {
|
||||
return getaddrinfo(hostname, service, hints, result);
|
||||
}
|
||||
|
||||
unsigned short
|
||||
@ -223,7 +226,7 @@ dbgsysSocketClose(int fd) {
|
||||
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&l, &len) == 0) {
|
||||
if (l.l_onoff == 0) {
|
||||
WSASendDisconnect(fd, NULL);
|
||||
shutdown(fd, SD_SEND);
|
||||
}
|
||||
}
|
||||
return closesocket(fd);
|
||||
@ -239,7 +242,11 @@ dbgsysBind(int fd, struct sockaddr *name, socklen_t namelen) {
|
||||
|
||||
uint32_t
|
||||
dbgsysInetAddr(const char* cp) {
|
||||
return (uint32_t)inet_addr(cp);
|
||||
uint32_t addr;
|
||||
if (inet_pton(AF_INET, cp, &addr) < 1) {
|
||||
return -1;
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
|
Loading…
Reference in New Issue
Block a user