Inet6AddressImpl.c revision 3909
3909N/A * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A/* Retain this code a little longer to support building in 0N/A * old environments. _MSC_VER is defined as: 0N/A * 1200 for MSVC++ 6.0 0N/A * Class: java_net_Inet6AddressImpl 0N/A * Method: getLocalHostName 0N/A /* get the address preference */ 0N/A /* Try once, with our static buffer. */ 0N/A for (t = 0; t <
16; t++) {
0N/A /* we can't handle other family types */ 0N/A /* we may have memory to free at the end of this */ 0N/A if (
scope != 0) {
/* zero is default value, no need to set */ 0N/A * Class: java_net_Inet6AddressImpl 0N/A * Method: getHostByAddr 0N/A * For IPv4 addresses construct a sockaddr_in structure. 0N/A * For IPv6 address construct a sockaddr_in6 structure. 0N/A * ping implementation. 0N/A * Send a ICMP_ECHO_REQUEST packet every second until either the timeout 0N/A * expires or a answer is received. 0N/A * Returns true is an ECHO_REPLY is received, otherwise, false. 0N/A /* Initialize the sequence number to a suitable random number and 0N/A shift right one place to allow sufficient room for increamenting. */ 0N/A /* icmp_id is a 16 bit data type, therefore down cast the pid */ 0N/A * A TTL was specified, let's set the socket option. 0N/A * A network interface was specified, let's bind to it. 0N/A * Make the socket non blocking 0N/A * send 1 ICMP REQUEST every second until either we get a valid reply 0N/A * or the timeout expired. 0N/A /* let's tag the ECHO packet with our pid so we can identify it */ 0N/A * We shouldn't have to do that as computing the checksum is supposed 0N/A * to be done by the IPv6 stack. Unfortunately windows, here too, is 0N/A * uterly broken, or non compliant, so let's do it. 0N/A * Problem is to compute the checksum I need to know the source address 0N/A * which happens only if I know the interface to be used... 0N/A // Happens when using a "tunnel interface" for instance. 0N/A // Or trying to send a packet on a different scope. 0N/A * For some unknown reason, besides plain stupidity, windows 0N/A * truncates the first 4 bytes of the icmpv6 header some we can't 0N/A * check for the ICMP_ECHOREPLY value. 0N/A * we'll check the other values, though 0N/A * Is that the reply we were expecting? 0N/A#
endif /* AF_INET6 */ 0N/A * Class: java_net_Inet6AddressImpl 0N/A * Method: isReachable0 0N/A * Signature: ([bII[bI)Z 0N/A * If IPv6 is not enable, then we can't reach an IPv6 address, can we? 0N/A * Actually, we probably shouldn't even get here. 0N/A * If it's an IPv4 address, ICMP won't work with IPv4 mapped address, 0N/A * therefore, let's delegate to the Inet4Address method. 0N/A * A network interface was specified, let's convert the address 0N/A * Windows implementation of ICMP & RAW sockets is too unreliable for now. 0N/A * Therefore it's best not to try it at all and rely only on TCP 0N/A * We may revisit and enable this code in the future. 0N/A * Right now, windows doesn't generate the ICMP checksum automatically 0N/A * so we have to compute it, but we can do it only if we know which 0N/A * interface will be used. Therefore, don't try to use ICMP if no 0N/A * interface was specified. 0N/A * When ICMPv6 support improves in windows, we may change this. 0N/A * If we can create a RAW socket, then when can use the ICMP ECHO_REQUEST 0N/A * otherwise we'll try a tcp socket to the Echo port (7). 0N/A * Note that this is empiric, and not connecting could mean it's blocked 0N/A * or the echo servioe has been disabled. 0N/A if (
fd != -
1) {
/* Good to go, let's do a ping */ 0N/A /* No good, let's fall back on TCP */ 0N/A /* note: if you run out of fds, you may not be able to load 0N/A * the exception class, and get a NoClassDefFoundError 0N/A * A TTL was specified, let's set the socket option. 0N/A * A network interface was specified, let's bind to it. 0N/A * Make the socket non blocking. 0N/A /* no need to use NET_Connect as non-blocking */ 0N/A * connection established or refused immediately, either way it means 0N/A * we were able to reach the host! 0N/A /* has connection been established? */ 0N/A#
endif /* AF_INET6 */