38 |
|
|
39 |
package java.net; |
package java.net; |
40 |
|
|
|
import gnu.classpath.Configuration; |
|
|
|
|
41 |
import java.util.Enumeration; |
import java.util.Enumeration; |
42 |
import java.util.Vector; |
import java.util.Vector; |
43 |
|
|
53 |
*/ |
*/ |
54 |
public final class NetworkInterface |
public final class NetworkInterface |
55 |
{ |
{ |
|
static |
|
|
{ |
|
|
if (Configuration.INIT_LOAD_LIBRARY) |
|
|
System.loadLibrary("javanet"); |
|
|
} |
|
|
|
|
56 |
private String name; |
private String name; |
57 |
private Vector inetAddresses; |
private Vector inetAddresses; |
58 |
|
|
59 |
private NetworkInterface(String name, InetAddress address) |
NetworkInterface(String name, InetAddress address) |
60 |
{ |
{ |
61 |
this.name = name; |
this.name = name; |
62 |
this.inetAddresses = new Vector(1, 1); |
this.inetAddresses = new Vector(1, 1); |
63 |
this.inetAddresses.add(address); |
this.inetAddresses.add(address); |
64 |
} |
} |
65 |
|
|
66 |
private static native Vector getRealNetworkInterfaces() |
NetworkInterface(String name, InetAddress[] addresses) |
67 |
throws SocketException; |
{ |
68 |
|
this.name = name; |
69 |
|
this.inetAddresses = new Vector(addresses.length, 1); |
70 |
|
|
71 |
|
for (int i = 0; i < addresses.length; i++) |
72 |
|
this.inetAddresses.add(addresses[i]); |
73 |
|
} |
74 |
|
|
75 |
/** |
/** |
76 |
* Returns the name of the network interface |
* Returns the name of the network interface |
143 |
public static NetworkInterface getByName(String name) |
public static NetworkInterface getByName(String name) |
144 |
throws SocketException |
throws SocketException |
145 |
{ |
{ |
146 |
Vector networkInterfaces = getRealNetworkInterfaces(); |
Vector networkInterfaces = VMNetworkInterface.getInterfaces(); |
147 |
|
|
148 |
for (Enumeration e = networkInterfaces.elements(); e.hasMoreElements();) |
for (Enumeration e = networkInterfaces.elements(); e.hasMoreElements();) |
149 |
{ |
{ |
170 |
public static NetworkInterface getByInetAddress(InetAddress addr) |
public static NetworkInterface getByInetAddress(InetAddress addr) |
171 |
throws SocketException |
throws SocketException |
172 |
{ |
{ |
173 |
Vector networkInterfaces = getRealNetworkInterfaces(); |
Vector networkInterfaces = VMNetworkInterface.getInterfaces(); |
174 |
|
|
175 |
for (Enumeration interfaces = networkInterfaces.elements(); |
for (Enumeration interfaces = networkInterfaces.elements(); |
176 |
interfaces.hasMoreElements();) |
interfaces.hasMoreElements();) |
197 |
*/ |
*/ |
198 |
public static Enumeration getNetworkInterfaces() throws SocketException |
public static Enumeration getNetworkInterfaces() throws SocketException |
199 |
{ |
{ |
200 |
Vector networkInterfaces = getRealNetworkInterfaces(); |
Vector networkInterfaces = VMNetworkInterface.getInterfaces(); |
201 |
|
|
202 |
if (networkInterfaces.isEmpty()) |
if (networkInterfaces.isEmpty()) |
203 |
return null; |
return null; |