NetworkInterface_winXP.c revision 509
/*
* Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
* 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
#include <stdlib.h>
#include <windows.h>
#include <winsock2.h> /* needed for htonl */
#include <iprtrmib.h>
#include <assert.h>
#include "java_net_NetworkInterface.h"
#include "jni_util.h"
#include "NetworkInterface.h"
/*
* Windows implementation of the java.net.NetworkInterface native methods.
* This module provides the implementations of getAll, getByName, getByIndex,
* and getByAddress.
*/
/* IP helper library routines */
#ifdef DEBUG
#ifdef _WIN64
#else
#endif
if (nif->dNameIsUnicode) {
} else {
}
}
}
printf("-----------------\n");
}
#endif
static int bufsize = 1024;
/*
* return an array of IP_ADAPTER_ADDRESSES containing one element
* for each apdapter on the system. Returned in *adapters.
* Buffer is malloc'd and must be freed (unless error returned)
*/
if (adapterInfo == 0) {
return -1;
}
if (ret == ERROR_BUFFER_OVERFLOW) {
if (adapterInfo == 0) {
return -1;
}
}
if (ret != ERROR_SUCCESS) {
free (adapterInfo);
"IP Helper Library GetAdaptersAddresses function failed");
return -1;
}
*adapters = adapterInfo;
return ERROR_SUCCESS;
}
/*
* return an array of IP_ADAPTER_ADDRESSES containing one element
* for each apdapter on the system. Returned in *adapters.
* Buffer is malloc'd and must be freed (unless error returned)
*/
if (adapterInfo == 0) {
return NULL;
}
if (val == ERROR_BUFFER_OVERFLOW) {
if (adapterInfo == 0) {
return NULL;
}
}
if (val != ERROR_SUCCESS) {
free (adapterInfo);
"IP Helper Library GetAdaptersAddresses function failed");
return NULL;
}
ptr = adapterInfo;
// IPv4 interface
}
}
return ret;
}
static int ipinflen = 2048;
/*
*/
{
*netifPP = 0;
/*
* Get the IPv4 interfaces. This information is the same
* as what previous JDK versions would return.
*/
if (ret == -1) {
return -1;
} else {
}
/* locate the loopback (and the last) interface */
}
}
if (ret != ERROR_SUCCESS) {
goto err;
}
/* Now get the IPv6 information. This includes:
* (a) IPv6 information associated with interfaces already found
* (b) IPv6 information for IPv6 only interfaces (probably tunnels)
*
* For compatibility with previous releases we use the naming
* information gotten from enumInterfaces_win() for (a) entries
* However, the index numbers are taken from the new API.
*
* The procedure is to go through the list of adapters returned
* by the new API looking for entries that correspond to IPv4 interfaces
* already found.
*/
int c;
if (c == -1) {
goto err;
}
} else {
if (index != 0) {
/* This entry is associated with an IPv4 interface */
/* found the interface entry
* set the index to the IPv6 index and add the
* IPv6 addresses
*/
break;
}
}
} else {
/* This entry is IPv6 only */
char newname [128];
int c;
/* Windows allocates duplicate adapter entries
* for tunnel interfaces when there are multiple
* physical adapters. Need to check
* if this is a duplicate (ipv6Index is the same)
*/
dup_nif = 0;
if (nif0->hasIpv6Address &&
break;
}
}
if (dup_nif == 0) {
/* new interface */
if (nif == 0) {
goto err;
}
tun ++;
} else {
net ++;
}
goto err;
}
count++;
if (c == -1) {
goto err;
}
} else {
/* add the addresses from this adapter to the
* original (dup_nif)
*/
if (c == -1) {
goto err;
}
}
}
}
}
return count;
err:
if (*netifPP) {
free_netif (*netifPP);
}
if (adapters) {
}
return -1;
}
/* If *netaddrPP is null, then the addresses are allocated and the beginning
* of the allocated chain is returned in *netaddrPP.
* If *netaddrPP is not null, then the addresses allocated here are appended
* to the existing chain.
*
* Returns count of addresses or -1 on error.
*/
int count = 0;
/* If chain passed in, find end */
}
}
/* Unicast */
/* address is only usable if dad state is preferred or deprecated */
if (curr == 0) {
return -1;
}
}
}
}
}
count ++;
}
}
/* Anycast */
if (curr == 0) {
return -1;
}
}
}
count ++;
}
}
return count;
}
/*
* Create a NetworkInterface object, populate the name and index, and
* populate the InetAddress array based on the IP addresses for this
* interface.
*/
{
/*
* Create a NetworkInterface object and populate it
*/
if (ifs->dNameIsUnicode) {
} else {
}
return NULL;
}
/*
* Get the IP addresses for this interface if necessary
* Note that 0 is a valid number of addresses.
*/
if (netaddrCount < 0) {
return NULL;
}
}
return NULL;
}
return NULL;
}
addr_index = 0;
bind_index = 0;
return NULL;
}
/* default ctor will set family to AF_INET */
return NULL;
}
return NULL;
}
} else /* AF_INET6 */ {
int scope;
if (iaObj) {
return NULL;
}
if (scope != 0) { /* zero is default value, no need to set */
}
return NULL;
}
}
}
addr_index++;
}
/*
* Windows doesn't have virtual interfaces, so child array
* is always empty.
*/
return NULL;
}
/* return the NetworkInterface */
return netifObj;
}
{
const char *name_utf;
return NULL;
}
/* get the name as a C string */
/* Search by name */
break;
}
}
/* if found create a NetworkInterface */
}
/* release the UTF string */
/* release the interface list */
return netifObj;
}
/*
* Class: NetworkInterface
* Method: getByIndex0_XP
* Signature: (I)LNetworkInterface;
*/
{
return NULL;
}
/* search by index */
break;
}
}
/* if found create a NetworkInterface */
}
/* release the interface list */
return netifObj;
}
/*
* Class: java_net_NetworkInterface
* Method: getByInetAddress0
* Signature: (Ljava/net/InetAddress;)Ljava/net/NetworkInterface;
*/
{
/* get the list of interfaces */
return NULL;
}
/*
* Enumerate the addresses on each interface until we find a
* matching address.
*/
/* iterate through each address */
break;
}
}
/*
* Address matched so create NetworkInterface for this interface
* and address list.
*/
break;
}
/* on next interface */
}
/* release the interface list */
return netifObj;
}
/*
* Class: java_net_NetworkInterface
* Method: getAll
* Signature: ()[Ljava/net/NetworkInterface;
*/
{
int count;
/*
* Get list of interfaces
*/
if (count < 0) {
return NULL;
}
/* allocate a NetworkInterface array */
return NULL;
}
/*
* Iterate through the interfaces, create a NetworkInterface instance
* for each array element and populate the object.
*/
arr_index = 0;
return NULL;
}
/* put the NetworkInterface into the array */
}
/* release the interface list */
return netIFArr;
}
/*
* Class: java_net_NetworkInterface
* Method: supportsMulticast0
*/
}
return val;
}
/*
* Class: java_net_NetworkInterface
* Method: isUp0
*/
}
return val;
}
/*
* Class: java_net_NetworkInterface
* Method: getMacAddr0
*/
int len;
}
}
return ret;
}
/*
* Class: java_net_NetworkInterface
* Method: getMTU0
*/
}
return ret;
}
/*
* Class: java_net_NetworkInterface
* Method: isLoopback0
*/
}
return val;
}
/*
* Class: java_net_NetworkInterface
* Method: isP2P0
*/
}
}
return val;
}