[Patch] java.net.NetworkInterface
Michael Koch
konqueror@gmx.de
Fri Apr 29 22:12:00 GMT 2005
Hi list,
I just commited the attached patch to merge java.net.NetworkInterface
with GNU classpath and to split off the native methods into
VMNetworkInterface.
Michael
2005-04-29 Michael Koch <konqueror@gmx.de>
* java/net/NetworkInterface.java
(static): Removed.
(NetworkInterface(String,InetAddress)): Made package-private.
(NetworkInterface(String,InetAddress[])): New constructor.
(getRealNetworkInterfaces): Removed.
(getByName): Use VMNetworkInterface.getInterfaces().
(getByInetAddress): Likewise.
(getNetworkInterfaces): Likewise.
* java/net/VMNetworkInterface.java,
java/net/natVMNetworkInterfaceNoNet.cc,
java/net/natVMNetworkInterfacePosix.c,c
java/net/natVMNetworkInterfaceWin32.cc: New files.
* java/net/natNetworkInterfaceNoNet.cc,
java/net/natNetworkInterfacePosix.cc,
java/net/natNetworkInterfaceWin32.cc: Removed.
* configure.ac
* Makefile.am
* configure, Makefile.in: Regenerated.
-------------- next part --------------
Index: java/net/NetworkInterface.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/NetworkInterface.java,v
retrieving revision 1.14
diff -u -r1.14 NetworkInterface.java
--- java/net/NetworkInterface.java 17 Feb 2005 07:48:35 -0000 1.14
+++ java/net/NetworkInterface.java 29 Apr 2005 22:07:43 -0000
@@ -38,8 +38,6 @@
package java.net;
-import gnu.classpath.Configuration;
-
import java.util.Enumeration;
import java.util.Vector;
@@ -55,24 +53,24 @@
*/
public final class NetworkInterface
{
- static
- {
- if (Configuration.INIT_LOAD_LIBRARY)
- System.loadLibrary("javanet");
- }
-
private String name;
private Vector inetAddresses;
- private NetworkInterface(String name, InetAddress address)
+ NetworkInterface(String name, InetAddress address)
{
this.name = name;
this.inetAddresses = new Vector(1, 1);
this.inetAddresses.add(address);
}
- private static native Vector getRealNetworkInterfaces()
- throws SocketException;
+ NetworkInterface(String name, InetAddress[] addresses)
+ {
+ this.name = name;
+ this.inetAddresses = new Vector(addresses.length, 1);
+
+ for (int i = 0; i < addresses.length; i++)
+ this.inetAddresses.add(addresses[i]);
+ }
/**
* Returns the name of the network interface
@@ -145,7 +143,7 @@
public static NetworkInterface getByName(String name)
throws SocketException
{
- Vector networkInterfaces = getRealNetworkInterfaces();
+ Vector networkInterfaces = VMNetworkInterface.getInterfaces();
for (Enumeration e = networkInterfaces.elements(); e.hasMoreElements();)
{
@@ -172,7 +170,7 @@
public static NetworkInterface getByInetAddress(InetAddress addr)
throws SocketException
{
- Vector networkInterfaces = getRealNetworkInterfaces();
+ Vector networkInterfaces = VMNetworkInterface.getInterfaces();
for (Enumeration interfaces = networkInterfaces.elements();
interfaces.hasMoreElements();)
@@ -199,7 +197,7 @@
*/
public static Enumeration getNetworkInterfaces() throws SocketException
{
- Vector networkInterfaces = getRealNetworkInterfaces();
+ Vector networkInterfaces = VMNetworkInterface.getInterfaces();
if (networkInterfaces.isEmpty())
return null;
Index: java/net/VMNetworkInterface.java
===================================================================
RCS file: java/net/VMNetworkInterface.java
diff -N java/net/VMNetworkInterface.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/net/VMNetworkInterface.java 29 Apr 2005 22:07:43 -0000
@@ -0,0 +1,66 @@
+/* VMNetworkInterface.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.net;
+
+import gnu.classpath.Configuration;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * This class models a network interface on the host computer. A network
+ * interface contains a name (typically associated with a specific
+ * hardware adapter) and a list of addresses that are bound to it.
+ * For example, an ethernet interface may be named "eth0" and have the
+ * address 192.168.1.101 assigned to it.
+ *
+ * @author Michael Koch (konqueror@gmx.de)
+ * @since 1.4
+ */
+final class VMNetworkInterface
+{
+ static
+ {
+ if (Configuration.INIT_LOAD_LIBRARY)
+ System.loadLibrary("javanet");
+ }
+
+ public static native Vector getInterfaces()
+ throws SocketException;
+}
Index: java/net/natVMNetworkInterfaceNoNet.cc
===================================================================
RCS file: java/net/natVMNetworkInterfaceNoNet.cc
diff -N java/net/natVMNetworkInterfaceNoNet.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/net/natVMNetworkInterfaceNoNet.cc 29 Apr 2005 22:07:43 -0000
@@ -0,0 +1,21 @@
+/* Copyright (C) 2003, 2005 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+#include <platform.h>
+
+#include <java/net/SocketException.h>
+#include <java/net/VMNetworkInterface.h>
+#include <java/util/Vector.h>
+
+::java::util::Vector*
+java::net::VMNetworkInterface::getInterfaces ()
+{
+ throw new SocketException (
+ JvNewStringLatin1 ("VMNetworkInterface.getInterfaces: unimplemented"));
+}
Index: java/net/natVMNetworkInterfacePosix.cc
===================================================================
RCS file: java/net/natVMNetworkInterfacePosix.cc
diff -N java/net/natVMNetworkInterfacePosix.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/net/natVMNetworkInterfacePosix.cc 29 Apr 2005 22:07:43 -0000
@@ -0,0 +1,116 @@
+/* Copyright (C) 2003, 2005 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+#include <platform.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include <sys/param.h>
+#include <sys/types.h>
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
+#define BSD_COMP /* Get FIONREAD on Solaris2. */
+#include <sys/ioctl.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+
+#include <gcj/cni.h>
+#include <jvm.h>
+#include <java/net/Inet4Address.h>
+#include <java/net/NetworkInterface.h>
+#include <java/net/SocketException.h>
+#include <java/net/VMNetworkInterface.h>
+#include <java/util/Vector.h>
+
+::java::util::Vector*
+java::net::VMNetworkInterface::getInterfaces ()
+{
+ int fd;
+ int num_interfaces = 0;
+ struct ifconf if_data;
+ struct ifreq* if_record;
+ ::java::util::Vector* ht = new ::java::util::Vector ();
+
+ if_data.ifc_len = 0;
+ if_data.ifc_buf = NULL;
+
+ // Open a (random) socket to have a file descriptor for the ioctl calls.
+ fd = _Jv_socket (PF_INET, SOCK_DGRAM, htons (IPPROTO_IP));
+
+ if (fd < 0)
+ throw new ::java::net::SocketException;
+
+ // Get all interfaces. If not enough buffers are available try it
+ // with a bigger buffer size.
+ do
+ {
+ num_interfaces += 16;
+
+ if_data.ifc_len = sizeof (struct ifreq) * num_interfaces;
+ if_data.ifc_buf =
+ (char*) _Jv_Realloc (if_data.ifc_buf, if_data.ifc_len);
+
+ // Try to get all local interfaces.
+ if (::ioctl (fd, SIOCGIFCONF, &if_data) < 0)
+ throw new java::net::SocketException;
+ }
+ while (if_data.ifc_len >= (sizeof (struct ifreq) * num_interfaces));
+
+ // Get addresses of all interfaces.
+ if_record = if_data.ifc_req;
+
+ for (int n = 0; n < if_data.ifc_len; n += sizeof (struct ifreq))
+ {
+ struct ifreq ifr;
+
+ memset (&ifr, 0, sizeof (ifr));
+ strcpy (ifr.ifr_name, if_record->ifr_name);
+
+ // Try to get the IPv4-address of the local interface
+ if (::ioctl (fd, SIOCGIFADDR, &ifr) < 0)
+ throw new java::net::SocketException;
+
+ int len = 4;
+ struct sockaddr_in sa = *((sockaddr_in*) &(ifr.ifr_addr));
+
+ jbyteArray baddr = JvNewByteArray (len);
+ memcpy (elements (baddr), &(sa.sin_addr), len);
+ jstring if_name = JvNewStringLatin1 (if_record->ifr_name);
+ Inet4Address* address =
+ new java::net::Inet4Address (baddr, JvNewStringLatin1 (""));
+ ht->add (new NetworkInterface (if_name, address));
+ if_record++;
+ }
+
+#ifdef HAVE_INET6
+ // FIXME: read /proc/net/if_inet6 (on Linux 2.4)
+#endif
+
+ _Jv_Free (if_data.ifc_buf);
+
+ if (fd >= 0)
+ _Jv_close (fd);
+
+ return ht;
+}
Index: java/net/natVMNetworkInterfaceWin32.cc
===================================================================
RCS file: java/net/natVMNetworkInterfaceWin32.cc
diff -N java/net/natVMNetworkInterfaceWin32.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/net/natVMNetworkInterfaceWin32.cc 29 Apr 2005 22:07:43 -0000
@@ -0,0 +1,143 @@
+/* Copyright (C) 2003, 2005 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+#include <platform.h>
+
+#undef STRICT
+
+#include <java/net/NetworkInterface.h>
+#include <java/net/Inet4Address.h>
+#include <java/net/SocketException.h>
+#include <java/util/Vector.h>
+
+/* As of this writing, NetworkInterface.java has
+ getName() == getDisplayName() and only one IP address
+ per interface. If this changes, we'll need to use
+ iphlpapi (not supported on Win95) to retrieve richer
+ adapter information via GetAdaptersInfo(). In this
+ module, we provide the necessary hooks to detect the
+ presence of iphlpapi and use it if necessary, but
+ comment things out for now to avoid compiler warnings. */
+
+enum {MAX_INTERFACES = 50};
+
+typedef int
+(*PfnGetRealNetworkInterfaces) (jstring* pjstrName,
+ java::net::InetAddress** ppAddress);
+
+static int
+winsock2GetRealNetworkInterfaces (jstring* pjstrName,
+ java::net::InetAddress** ppAddress)
+{
+ // FIXME: Add IPv6 support.
+
+ INTERFACE_INFO arInterfaceInfo[MAX_INTERFACES];
+
+ // Open a (random) socket to have a file descriptor for the WSAIoctl call.
+ SOCKET skt = ::socket (AF_INET, SOCK_DGRAM, 0);
+ if (skt == INVALID_SOCKET)
+ _Jv_ThrowSocketException ();
+
+ DWORD dwOutBufSize;
+ int nRetCode = ::WSAIoctl (skt, SIO_GET_INTERFACE_LIST,
+ NULL, 0, &arInterfaceInfo, sizeof(arInterfaceInfo),
+ &dwOutBufSize, NULL, NULL);
+
+ if (nRetCode == SOCKET_ERROR)
+ {
+ DWORD dwLastErrorCode = WSAGetLastError ();
+ ::closesocket (skt);
+ _Jv_ThrowSocketException (dwLastErrorCode);
+ }
+
+ // Get addresses of all interfaces.
+ int nNbInterfaces = dwOutBufSize / sizeof(INTERFACE_INFO);
+ int nCurETHInterface = 0;
+ for (int i=0; i < nNbInterfaces; ++i)
+ {
+ int len = 4;
+ jbyteArray baddr = JvNewByteArray (len);
+ SOCKADDR_IN* pAddr = (SOCKADDR_IN*) &arInterfaceInfo[i].iiAddress;
+ memcpy (elements (baddr), &(pAddr->sin_addr), len);
+
+ // Concoct a name for this interface. Since we don't
+ // have access to the real name under Winsock 2, we use
+ // "lo" for the loopback interface and ethX for the
+ // real ones.
+ TCHAR szName[30];
+ u_long lFlags = arInterfaceInfo[i].iiFlags;
+
+ if (lFlags & IFF_LOOPBACK)
+ _tcscpy (szName, _T("lo"));
+ else
+ {
+ _tcscpy (szName, _T("eth"));
+ wsprintf(szName+3, _T("%d"), nCurETHInterface++);
+ }
+
+ jstring if_name = _Jv_Win32NewString (szName);
+ java::net::Inet4Address* address =
+ new java::net::Inet4Address (baddr, JvNewStringLatin1 (""));
+ pjstrName[i] = if_name;
+ ppAddress[i] = address;
+ }
+
+ ::closesocket (skt);
+
+ return nNbInterfaces;
+}
+
+/*
+static int
+iphlpapiGetRealNetworkInterfaces (jstring* pjstrName,
+ java::net::InetAddress** ppAddress)
+{
+ return 0;
+}
+*/
+
+static PfnGetRealNetworkInterfaces
+determineGetRealNetworkInterfacesFN ()
+{
+ /* FIXME: Try to dynamically load iphlpapi.dll and
+ detect the presence of GetAdaptersInfo() using
+ GetProcAddress(). If successful, return
+ iphlpapiGetRealNetworkInterfaces; if not,
+ return winsock2GetRealNetworkInterfaces */
+ return &winsock2GetRealNetworkInterfaces;
+}
+
+::java::util::Vector*
+java::net::VMNetworkInterface::getInterfaces ()
+{
+ // This next declaration used to be a static local,
+ // but this introduced a dependency on libsupc++ due
+ // to _cxa_guard_acquire and _cxa_guard_release.
+ // When Win95 is gone and we eventually get rid of
+ // winsock2GetRealNetworkInterfaces, we can rework
+ // all of this. Alternatively, we could move this all
+ // to win32.cc and initialize this at startup time,
+ // but that seems more trouble than it's worth at
+ // the moment.
+ PfnGetRealNetworkInterfaces pfn =
+ determineGetRealNetworkInterfacesFN ();
+
+ jstring arIFName[MAX_INTERFACES];
+ InetAddress* arpInetAddress[MAX_INTERFACES];
+ ::java::util::Vector* ht = new ::java::util::Vector ();
+
+ int nNbInterfaces = (*pfn) (arIFName, arpInetAddress);
+ for (int i=0; i < nNbInterfaces; ++i)
+ {
+ ht->add (new java::net::NetworkInterface (arIFName[i],
+ arpInetAddress[i]));
+ }
+
+ return ht;
+}
Index: java/net/natNetworkInterfaceNoNet.cc
===================================================================
RCS file: java/net/natNetworkInterfaceNoNet.cc
diff -N java/net/natNetworkInterfaceNoNet.cc
--- java/net/natNetworkInterfaceNoNet.cc 18 Mar 2003 06:01:16 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,21 +0,0 @@
-/* Copyright (C) 2003 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-#include <config.h>
-#include <platform.h>
-
-#include <java/net/NetworkInterface.h>
-#include <java/net/SocketException.h>
-#include <java/util/Vector.h>
-
-::java::util::Vector*
-java::net::NetworkInterface::getRealNetworkInterfaces ()
-{
- throw new SocketException (
- JvNewStringLatin1 ("NetworkInterface.getrealNetworkInterfaces: unimplemented"));
-}
Index: java/net/natNetworkInterfacePosix.cc
===================================================================
RCS file: java/net/natNetworkInterfacePosix.cc
diff -N java/net/natNetworkInterfacePosix.cc
--- java/net/natNetworkInterfacePosix.cc 18 Mar 2003 06:01:16 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,115 +0,0 @@
-/* Copyright (C) 2003 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-#include <config.h>
-#include <platform.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
-
-#include <sys/param.h>
-#include <sys/types.h>
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-#ifdef HAVE_SYS_IOCTL_H
-#define BSD_COMP /* Get FIONREAD on Solaris2. */
-#include <sys/ioctl.h>
-#endif
-#ifdef HAVE_NET_IF_H
-#include <net/if.h>
-#endif
-
-#include <gcj/cni.h>
-#include <jvm.h>
-#include <java/net/NetworkInterface.h>
-#include <java/net/Inet4Address.h>
-#include <java/net/SocketException.h>
-#include <java/util/Vector.h>
-
-::java::util::Vector*
-java::net::NetworkInterface::getRealNetworkInterfaces ()
-{
- int fd;
- int num_interfaces = 0;
- struct ifconf if_data;
- struct ifreq* if_record;
- ::java::util::Vector* ht = new ::java::util::Vector ();
-
- if_data.ifc_len = 0;
- if_data.ifc_buf = NULL;
-
- // Open a (random) socket to have a file descriptor for the ioctl calls.
- fd = _Jv_socket (PF_INET, SOCK_DGRAM, htons (IPPROTO_IP));
-
- if (fd < 0)
- throw new ::java::net::SocketException;
-
- // Get all interfaces. If not enough buffers are available try it
- // with a bigger buffer size.
- do
- {
- num_interfaces += 16;
-
- if_data.ifc_len = sizeof (struct ifreq) * num_interfaces;
- if_data.ifc_buf =
- (char*) _Jv_Realloc (if_data.ifc_buf, if_data.ifc_len);
-
- // Try to get all local interfaces.
- if (::ioctl (fd, SIOCGIFCONF, &if_data) < 0)
- throw new java::net::SocketException;
- }
- while (if_data.ifc_len >= (sizeof (struct ifreq) * num_interfaces));
-
- // Get addresses of all interfaces.
- if_record = if_data.ifc_req;
-
- for (int n = 0; n < if_data.ifc_len; n += sizeof (struct ifreq))
- {
- struct ifreq ifr;
-
- memset (&ifr, 0, sizeof (ifr));
- strcpy (ifr.ifr_name, if_record->ifr_name);
-
- // Try to get the IPv4-address of the local interface
- if (::ioctl (fd, SIOCGIFADDR, &ifr) < 0)
- throw new java::net::SocketException;
-
- int len = 4;
- struct sockaddr_in sa = *((sockaddr_in*) &(ifr.ifr_addr));
-
- jbyteArray baddr = JvNewByteArray (len);
- memcpy (elements (baddr), &(sa.sin_addr), len);
- jstring if_name = JvNewStringLatin1 (if_record->ifr_name);
- Inet4Address* address =
- new java::net::Inet4Address (baddr, JvNewStringLatin1 (""));
- ht->add (new NetworkInterface (if_name, address));
- if_record++;
- }
-
-#ifdef HAVE_INET6
- // FIXME: read /proc/net/if_inet6 (on Linux 2.4)
-#endif
-
- _Jv_Free (if_data.ifc_buf);
-
- if (fd >= 0)
- _Jv_close (fd);
-
- return ht;
-}
Index: java/net/natNetworkInterfaceWin32.cc
===================================================================
RCS file: java/net/natNetworkInterfaceWin32.cc
diff -N java/net/natNetworkInterfaceWin32.cc
--- java/net/natNetworkInterfaceWin32.cc 5 Sep 2004 03:36:19 -0000 1.6
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,143 +0,0 @@
-/* Copyright (C) 2003 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-#include <config.h>
-#include <platform.h>
-
-#undef STRICT
-
-#include <java/net/NetworkInterface.h>
-#include <java/net/Inet4Address.h>
-#include <java/net/SocketException.h>
-#include <java/util/Vector.h>
-
-/* As of this writing, NetworkInterface.java has
- getName() == getDisplayName() and only one IP address
- per interface. If this changes, we'll need to use
- iphlpapi (not supported on Win95) to retrieve richer
- adapter information via GetAdaptersInfo(). In this
- module, we provide the necessary hooks to detect the
- presence of iphlpapi and use it if necessary, but
- comment things out for now to avoid compiler warnings. */
-
-enum {MAX_INTERFACES = 50};
-
-typedef int
-(*PfnGetRealNetworkInterfaces) (jstring* pjstrName,
- java::net::InetAddress** ppAddress);
-
-static int
-winsock2GetRealNetworkInterfaces (jstring* pjstrName,
- java::net::InetAddress** ppAddress)
-{
- // FIXME: Add IPv6 support.
-
- INTERFACE_INFO arInterfaceInfo[MAX_INTERFACES];
-
- // Open a (random) socket to have a file descriptor for the WSAIoctl call.
- SOCKET skt = ::socket (AF_INET, SOCK_DGRAM, 0);
- if (skt == INVALID_SOCKET)
- _Jv_ThrowSocketException ();
-
- DWORD dwOutBufSize;
- int nRetCode = ::WSAIoctl (skt, SIO_GET_INTERFACE_LIST,
- NULL, 0, &arInterfaceInfo, sizeof(arInterfaceInfo),
- &dwOutBufSize, NULL, NULL);
-
- if (nRetCode == SOCKET_ERROR)
- {
- DWORD dwLastErrorCode = WSAGetLastError ();
- ::closesocket (skt);
- _Jv_ThrowSocketException (dwLastErrorCode);
- }
-
- // Get addresses of all interfaces.
- int nNbInterfaces = dwOutBufSize / sizeof(INTERFACE_INFO);
- int nCurETHInterface = 0;
- for (int i=0; i < nNbInterfaces; ++i)
- {
- int len = 4;
- jbyteArray baddr = JvNewByteArray (len);
- SOCKADDR_IN* pAddr = (SOCKADDR_IN*) &arInterfaceInfo[i].iiAddress;
- memcpy (elements (baddr), &(pAddr->sin_addr), len);
-
- // Concoct a name for this interface. Since we don't
- // have access to the real name under Winsock 2, we use
- // "lo" for the loopback interface and ethX for the
- // real ones.
- TCHAR szName[30];
- u_long lFlags = arInterfaceInfo[i].iiFlags;
-
- if (lFlags & IFF_LOOPBACK)
- _tcscpy (szName, _T("lo"));
- else
- {
- _tcscpy (szName, _T("eth"));
- wsprintf(szName+3, _T("%d"), nCurETHInterface++);
- }
-
- jstring if_name = _Jv_Win32NewString (szName);
- java::net::Inet4Address* address =
- new java::net::Inet4Address (baddr, JvNewStringLatin1 (""));
- pjstrName[i] = if_name;
- ppAddress[i] = address;
- }
-
- ::closesocket (skt);
-
- return nNbInterfaces;
-}
-
-/*
-static int
-iphlpapiGetRealNetworkInterfaces (jstring* pjstrName,
- java::net::InetAddress** ppAddress)
-{
- return 0;
-}
-*/
-
-static PfnGetRealNetworkInterfaces
-determineGetRealNetworkInterfacesFN ()
-{
- /* FIXME: Try to dynamically load iphlpapi.dll and
- detect the presence of GetAdaptersInfo() using
- GetProcAddress(). If successful, return
- iphlpapiGetRealNetworkInterfaces; if not,
- return winsock2GetRealNetworkInterfaces */
- return &winsock2GetRealNetworkInterfaces;
-}
-
-::java::util::Vector*
-java::net::NetworkInterface::getRealNetworkInterfaces ()
-{
- // This next declaration used to be a static local,
- // but this introduced a dependency on libsupc++ due
- // to _cxa_guard_acquire and _cxa_guard_release.
- // When Win95 is gone and we eventually get rid of
- // winsock2GetRealNetworkInterfaces, we can rework
- // all of this. Alternatively, we could move this all
- // to win32.cc and initialize this at startup time,
- // but that seems more trouble than it's worth at
- // the moment.
- PfnGetRealNetworkInterfaces pfn =
- determineGetRealNetworkInterfacesFN ();
-
- jstring arIFName[MAX_INTERFACES];
- InetAddress* arpInetAddress[MAX_INTERFACES];
- ::java::util::Vector* ht = new ::java::util::Vector ();
-
- int nNbInterfaces = (*pfn) (arIFName, arpInetAddress);
- for (int i=0; i < nNbInterfaces; ++i)
- {
- ht->add (new java::net::NetworkInterface (arIFName[i],
- arpInetAddress[i]));
- }
-
- return ht;
-}
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.481
diff -u -r1.481 Makefile.am
--- Makefile.am 27 Apr 2005 20:10:06 -0000 1.481
+++ Makefile.am 29 Apr 2005 22:07:44 -0000
@@ -3555,6 +3555,7 @@
java/net/URLStreamHandlerFactory.java \
java/net/UnknownHostException.java \
java/net/UnknownServiceException.java \
+java/net/VMNetworkInterface.java \
java/nio/Buffer.java \
java/nio/BufferOverflowException.java \
java/nio/BufferUnderflowException.java \
@@ -3935,7 +3936,7 @@
java/lang/reflect/natField.cc \
java/lang/reflect/natMethod.cc \
java/lang/reflect/natProxy.cc \
-java/net/natNetworkInterface.cc \
+java/net/natVMNetworkInterface.cc \
java/net/natInetAddress.cc \
java/nio/channels/natChannels.cc \
java/nio/natDirectByteBufferImpl.cc \
Index: configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/libjava/configure.ac,v
retrieving revision 1.27
diff -u -r1.27 configure.ac
--- configure.ac 5 Apr 2005 23:46:04 -0000 1.27
+++ configure.ac 29 Apr 2005 22:07:44 -0000
@@ -456,10 +456,10 @@
AC_CONFIG_LINKS(java/lang/ConcreteProcess.java:java/lang/${PLATFORM}Process.java)
AC_CONFIG_LINKS(java/lang/natConcreteProcess.cc:java/lang/nat${PLATFORM}Process.cc)
-# Likewise for natInetAddress.cc and natNetworkInterface.cc.
+# Likewise for natInetAddress.cc and natVMNetworkInterface.cc.
test -d java/net || mkdir java/net
AC_CONFIG_LINKS(java/net/natInetAddress.cc:java/net/natInetAddress${PLATFORMNET}.cc)
-AC_CONFIG_LINKS(java/net/natNetworkInterface.cc:java/net/natNetworkInterface${PLATFORMNET}.cc)
+AC_CONFIG_LINKS(java/net/natVMNetworkInterface.cc:java/net/natVMNetworkInterface${PLATFORMNET}.cc)
# Likewise for natPlainSocketImpl.cc and natPlainDatagramSocketImpl.cc.
test -d gnu/java || mkdir gnu/java
More information about the Java-patches
mailing list