Inet6AddressImpl.c revision 3334
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <windows.h>
#include <winsock2.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <process.h>
#include "java_net_InetAddress.h"
#include "java_net_Inet4AddressImpl.h"
#include "java_net_Inet6AddressImpl.h"
#include "net_util.h"
#include "icmp.h"
#ifdef WIN32
#ifndef _WIN64
/* Retain this code a little longer to support building in
* old environments. _MSC_VER is defined as:
* 1200 for MSVC++ 6.0
* 1310 for Vc7
*/
#define sockaddr_in6 SOCKADDR_IN6
#endif
#endif
#endif
/*
* Inet6AddressImpl
*/
/*
* Class: java_net_Inet6AddressImpl
* Method: getLocalHostName
*/
char hostname [256];
}
}
static jmethodID ni_ia4ctrID;
static jmethodID ni_ia6ctrID;
static jfieldID ni_iaaddressID;
static jfieldID ni_iahostID;
static jfieldID ni_iafamilyID;
static jfieldID ni_ia6ipaddressID;
static int initialized = 0;
const char *hostname;
jobjectArray ret = 0;
int retLen = 0;
int error=0;
if (!initialized) {
initialized = 1;
}
return 0;
}
if (NET_addrtransAvailable()) {
static jfieldID ia_preferIPv6AddressID;
if (ia_preferIPv6AddressID == NULL) {
if (c) {
}
if (ia_preferIPv6AddressID == NULL) {
return NULL;
}
}
/* get the address preference */
/* Try once, with our static buffer. */
if (error) {
/* report error */
(char *)hostname);
return NULL;
} else {
int i = 0;
int skip = 0;
skip = 1;
break;
}
} else {
int t;
for (t = 0; t < 16; t++) {
break;
}
}
if (t < 16) {
continue;
} else {
skip = 1;
break;
}
}
/* we can't handle other family types */
skip = 1;
break;
}
}
if (!skip) {
if (!next) {
goto cleanupAndReturn;
}
} else {
}
i++;
inetCount ++;
inet6Count ++;
}
}
}
retLen = i;
i = 0;
/* we may have memory to free at the end of this */
goto cleanupAndReturn;
}
if (preferIPv6Address) {
inet6Index = 0;
} else {
inetIndex = 0;
}
goto cleanupAndReturn;
}
inetIndex ++;
goto cleanupAndReturn;
}
goto cleanupAndReturn;
}
if (scope != 0) { /* zero is default value, no need to set */
}
inet6Index ++;
}
}
}
}
{
}
}
if (NET_addrtransAvailable())
(*freeaddrinfo_ptr)(res);
return ret;
}
/*
* Class: java_net_Inet6AddressImpl
* Method: getHostByAddr
*/
int error = 0;
int len = 0;
if (NET_addrtransAvailable()) {
struct sockaddr_in him4;
struct sockaddr_in6 him6;
/*
* For IPv4 addresses construct a sockaddr_in structure.
*/
} else {
/*
* For IPv6 address construct a sockaddr_in6 structure.
*/
}
if (!error) {
}
}
}
return ret;
}
#ifdef AF_INET6
/**
* ping implementation.
* Send a ICMP_ECHO_REQUEST packet every second until either the timeout
* expires or a answer is received.
* Returns true is an ECHO_REPLY is received, otherwise, false.
*/
static jboolean
char sendbuf[1500];
char auxbuf[1500];
unsigned char recvbuf[1500];
struct SOCKADDR_IN6 sa_recv;
int read_rv = 0;
struct ip6_pseudo_hdr *pseudo_ip6;
int timestamp;
int tmout2;
/* Initialize the sequence number to a suitable random number and
shift right one place to allow sufficient room for increamenting. */
/* icmp_id is a 16 bit data type, therefore down cast the pid */
/**
* A TTL was specified, let's set the socket option.
*/
if (ttl > 0) {
}
/**
* A network interface was specified, let's bind to it.
*/
return JNI_FALSE;
}
}
/*
* Make the socket non blocking
*/
hEvent = WSACreateEvent();
/**
* send 1 ICMP REQUEST every second until either we get a valid reply
* or the timeout expired.
*/
do {
/* let's tag the ECHO packet with our pid so we can identify it */
timestamp = GetCurrentTime();
icmp6->icmp6_code = 0;
icmp6->icmp6_cksum = 0;
/**
* We shouldn't have to do that as computing the checksum is supposed
* to be done by the IPv6 stack. Unfortunately windows, here too, is
* uterly broken, or non compliant, so let's do it.
* Problem is to compute the checksum I need to know the source address
* which happens only if I know the interface to be used...
*/
}
/**
* Ping!
*/
// Happens when using a "tunnel interface" for instance.
// Or trying to send a packet on a different scope.
return JNI_FALSE;
}
if (n < 0 && WSAGetLastError() != WSAEWOULDBLOCK) {
return JNI_FALSE;
}
do {
if (tmout2 >= 0) {
/**
* For some unknown reason, besides plain stupidity, windows
* truncates the first 4 bytes of the icmpv6 header some we can't
* check for the ICMP_ECHOREPLY value.
* we'll check the other values, though
*/
/**
* Is that the reply we were expecting?
*/
return JNI_TRUE;
}
}
} while (tmout2 > 0);
timeout -= 1000;
seq++;
} while (timeout > 0);
return JNI_FALSE;
}
#endif /* AF_INET6 */
/*
* Class: java_net_Inet6AddressImpl
* Method: isReachable0
* Signature: ([bII[bI)Z
*/
#ifdef AF_INET6
struct sockaddr_in6 him6;
struct sockaddr_in6 inf6;
int len = 0;
int connect_rv = -1;
/*
* If IPv6 is not enable, then we can't reach an IPv6 address, can we?
* Actually, we probably shouldn't even get here.
*/
if (!ipv6_available()) {
return JNI_FALSE;
}
/*
* If it's an IPv4 address, ICMP won't work with IPv4 mapped address,
* therefore, let's delegate to the Inet4Address method.
*/
if (sz == 4) {
}
if (scope > 0) {
}
len = sizeof(struct sockaddr_in6);
/**
* A network interface was specified, let's convert the address
*/
}
#if 0
/*
* Windows implementation of ICMP & RAW sockets is too unreliable for now.
* Therefore it's best not to try it at all and rely only on TCP
* We may revisit and enable this code in the future.
*/
/*
* Right now, windows doesn't generate the ICMP checksum automatically
* so we have to compute it, but we can do it only if we know which
* interface will be used. Therefore, don't try to use ICMP if no
* interface was specified.
* When ICMPv6 support improves in windows, we may change this.
*/
/*
* If we can create a RAW socket, then when can use the ICMP ECHO_REQUEST
* otherwise we'll try a tcp socket to the Echo port (7).
* Note that this is empiric, and not connecting could mean it's blocked
* or the echo servioe has been disabled.
*/
}
}
#endif
/* No good, let's fall back on TCP */
if (fd == JVM_IO_ERR) {
/* note: if you run out of fds, you may not be able to load
* the exception class, and get a NoClassDefFoundError
* instead.
*/
return JNI_FALSE;
}
/**
* A TTL was specified, let's set the socket option.
*/
if (ttl > 0) {
}
/**
* A network interface was specified, let's bind to it.
*/
return JNI_FALSE;
}
}
/**
* Make the socket non blocking.
*/
hEvent = WSACreateEvent();
/* no need to use NET_Connect as non-blocking */
/**
* connection established or refused immediately, either way it means
* we were able to reach the host!
*/
return JNI_TRUE;
} else {
int optlen;
switch (WSAGetLastError()) {
case WSAEHOSTUNREACH: /* Host Unreachable */
case WSAENETUNREACH: /* Network Unreachable */
case WSAENETDOWN: /* Network is down */
case WSAEPFNOSUPPORT: /* Protocol Family unsupported */
return JNI_FALSE;
}
if (WSAGetLastError() != WSAEWOULDBLOCK) {
"connect failed");
return JNI_FALSE;
}
if (timeout >= 0) {
/* has connection been established? */
optlen = sizeof(connect_rv);
&optlen) <0) {
}
return JNI_TRUE;
}
}
}
#endif /* AF_INET6 */
return JNI_FALSE;
}