natInetAddress.cc (aton): Fix typos.

* java/net/natInetAddress.cc (aton): Fix typos.
        (lookup): Use a bigger buffer size for gethostbyname_r on all
        versions of glibc. Updated FIXME comment explaining this.
        Modified while loops to not set herr = ERANGE to work around glibc
        problems. Use user specified hostname in InetAddress result when
        available (consistent with JDK).

From-SVN: r27484
This commit is contained in:
Bryce McKinlay 1999-06-11 01:38:08 +00:00 committed by Bryce McKinlay
parent b312276f5b
commit 53dfe2970a
2 changed files with 31 additions and 18 deletions

View File

@ -1,3 +1,11 @@
1999-06-10 Bryce McKinlay <bryce@albatross.co.nz>
* java/net/natInetAddress.cc (aton): Fix typos.
(lookup): Use a bigger buffer size for gethostbyname_r on all
versions of glibc. Updated FIXME comment explaining this.
Modified while loops to not set herr = ERANGE to work around glibc
problems. Use user specified hostname in InetAddress result when
available (consistent with JDK).
1999-06-10 Warren Levy <warrenl@cygnus.com>
* java/io/FileDescriptor.java (FileDescriptor(String, int)):

View File

@ -64,14 +64,14 @@ java::net::InetAddress::aton (jstring host)
if (inet_aton (hostname, &laddr))
{
bytes = (char*) &laddr;
len = 4;
blen = 4;
}
#elif defined(HAVE_INET_ADDR)
in_addr_t laddr = inet_addr (hostname);
if (laddr != (in_addr_t)(-1))
{
bytes = (char*) &laddr;
len = 4;
blen = 4;
}
#endif
#ifdef HAVE_INET_PTON
@ -79,12 +79,12 @@ java::net::InetAddress::aton (jstring host)
if (len == 0 && inet_pton (AF_INET6, hostname, inet6_addr) > 0)
{
bytes = inet6_addr;
len = 16;
blen = 16;
}
#endif
if (blen == 0)
return NULL;
jbyteArray result = JvNewByteArray (len);
jbyteArray result = JvNewByteArray (blen);
memcpy (elements (result), bytes, blen);
return result;
}
@ -97,10 +97,11 @@ java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
struct hostent *hptr = NULL;
#if defined (HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYADDR_R)
struct hostent hent_r;
#if defined (__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ == 0
// glibc 2.0.7 has a bug where gethostbyname_r won't return an error
// if the buffer is too small. So in this case we size the buffer
// the same way that glibc does. This is fixed in glibc 2.1.
#if defined (__GLIBC__)
// FIXME: in glibc, gethostbyname_r returns NETDB_INTERNAL to herr and
// ERANGE to errno if the buffer size is too small, rather than what is
// expected here. We work around this by setting a bigger buffer size and
// hoping that it is big enough.
char fixed_buffer[1024];
#else
char fixed_buffer[200];
@ -121,8 +122,8 @@ java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
JvGetStringUTFRegion (host, 0, host->length(), hostname);
buf[len] = '\0';
#ifdef HAVE_GETHOSTBYNAME_R
int herr = ERANGE;
while (hptr == NULL && herr == ERANGE)
int herr = 0;
while (true)
{
int ok;
#ifdef GETHOSTBYNAME_R_RETURNS_INT
@ -137,6 +138,8 @@ java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
size_r *= 2;
buffer_r = (char *) _Jv_AllocBytesChecked (size_r);
}
else
break;
}
#else
// FIXME: this is insufficient if some other piece of code calls
@ -168,8 +171,8 @@ java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
JvFail ("unrecognized size");
#ifdef HAVE_GETHOSTBYADDR_R
int herr = ERANGE;
while (hptr == NULL && herr == ERANGE)
int herr = 0;
while (true)
{
int ok;
#ifdef GETHOSTBYADDR_R_RETURNS_INT
@ -185,6 +188,8 @@ java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
size_r *= 2;
buffer_r = (char *) _Jv_AllocBytesChecked (size_r);
}
else
break;
}
#else /* HAVE_GETHOSTBYADDR_R */
// FIXME: this is insufficient if some other piece of code calls
@ -195,7 +200,8 @@ java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
}
if (hptr != NULL)
{
host = JvNewStringUTF (hptr->h_name);
if (host == NULL)
host = JvNewStringUTF (hptr->h_name);
java::lang::SecurityException *ex = checkConnect (host);
if (ex != NULL)
{
@ -240,13 +246,12 @@ java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
{
if (iaddrs[i] == NULL)
iaddrs[i] = new java::net::InetAddress (NULL, NULL);
if (i == 0)
iaddrs[0]->hostname = host;
iaddrs[i]->hostname = host;
if (iaddrs[i]->address == NULL)
{
char *bytes = hptr->h_addr_list[i];
iaddr->address = JvNewByteArray (hptr->h_length);
memcpy (elements (iaddr->address), bytes, hptr->h_length);
iaddrs[i]->address = JvNewByteArray (hptr->h_length);
memcpy (elements (iaddrs[i]->address), bytes, hptr->h_length);
}
}
return result;