Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r850 committed - Fix issue with Prefer IPv6 checkbox....

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r850 committed - Fix issue with Prefer IPv6 checkbox....


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r850 committed - Fix issue with Prefer IPv6 checkbox....
  • Date: Fri, 18 Oct 2013 08:04:54 +0000

Revision: 850
Author:

Date: Fri Oct 18 08:04:31 2013 UTC
Log: Fix issue with Prefer IPv6 checkbox.
Instead of setting system properties the java applet will try to find IPv6 address from all addresses available from the given host name. If a user deselect the checkbox or the applet can not find IPv6 address then first available address will be used.
http://code.google.com/p/ndt/source/detail?r=850

Modified:
/branches/applet_54/Applet/Tcpbw100.java

=======================================
--- /branches/applet_54/Applet/Tcpbw100.java Fri Oct 18 06:48:19 2013 UTC
+++ /branches/applet_54/Applet/Tcpbw100.java Fri Oct 18 08:04:31 2013 UTC
@@ -210,6 +210,7 @@
boolean _bIsApplication = false;
boolean _bTestInProgress = false;
String sHostName = null;
+ InetAddress hostAddress = null;
String _sTestResults, _sMidBoxTestResult;
byte _yTests = NDTConstants.TEST_MID | NDTConstants.TEST_C2S
| NDTConstants.TEST_S2C | NDTConstants.TEST_SFW
@@ -289,13 +290,13 @@
}
});
applet._bIsApplication = true;
- applet.sHostName = args[0];
if (args.length > 1) {
applet._sClient = args[1];
}
frame.getContentPane().add(applet);
frame.setSize(700, 320);
applet.init();
+ applet.setsHostName(args[0]);
applet.start();
frame.setVisible(true);
}
@@ -878,6 +879,7 @@
_chkboxPreferIPv6 = new JCheckBox(
_resBundDisplayMsgs.getString("preferIPv6"));
_chkboxPreferIPv6.setSelected(true);
+ _chkboxPreferIPv6.addActionListener(this);
// 2. Conduct default tests?
_chkboxDefaultTest = new JCheckBox(

_resBundDisplayMsgs.getString("defaultTests"));
@@ -1152,6 +1154,10 @@
_buttonStatsCopy.setEnabled(true);
}
}
+ // prefer IPv6 checkbox
+ else if (source == _chkboxPreferIPv6) {
+ setHostAddress(sHostName);
+ }
// mail to functionality
else if (source == _buttonMailTo) {
// int i; //did'nt need it
@@ -1286,7 +1292,7 @@
// connect to server using port obtained above
Socket midSrvrSockObj = null;
try {
- midSrvrSockObj = new Socket(sHostName,
midport);
+ midSrvrSockObj = new Socket(hostAddress,
midport);
} catch (UnknownHostException e) {
System.err.println("Don't know about host: "
+ sHostName);
_sErrMsg =
_resBundDisplayMsgs.getString("unknownServer")
@@ -1565,7 +1571,7 @@
Socket sfwSocket = new Socket();
try {
// create socket to ephemeral port. testTime
now specified in mS
- sfwSocket.connect(new
InetSocketAddress(sHostName, iSrvPort),
+ sfwSocket.connect(new
InetSocketAddress(hostAddress, iSrvPort),
iTestTime *
NDTConstants.KILO);

Protocol sfwCtl = new Protocol(sfwSocket);
@@ -1700,7 +1706,7 @@
// client connects to this port
final Socket outSocket;
try {
- outSocket = new Socket(sHostName, iC2sport);
+ outSocket = new Socket(hostAddress, iC2sport);
} catch (UnknownHostException e) {
System.err.println("Don't know about host: "
+ sHostName);
_sErrMsg =
_resBundDisplayMsgs.getString("unknownServer")
@@ -1948,7 +1954,7 @@
// Create socket and bind to port as instructed by
server
Socket inSocket;
try {
- inSocket = new Socket(sHostName, iS2cport);
+ inSocket = new Socket(hostAddress, iS2cport);
} catch (UnknownHostException e) {
System.err.println("Don't know about host: "
+ sHostName);
_sErrMsg = "unknown server\n";
@@ -2316,13 +2322,14 @@
// are
// potentially accessing a server outside the source
domain.
//
- sHostName = getParameter("testingServer");
+ String sTestingServer = getParameter("testingServer");

// fall back to the old behavior if the APPLET tag is
not set
- if (sHostName == null) {
- sHostName = getCodeBase().getHost();
+ if (sTestingServer == null) {
+ sTestingServer = getCodeBase().getHost();
}

+ setsHostName(sTestingServer);
pub_host = sHostName;
}

@@ -2349,24 +2356,11 @@
+ " '"
+ sHostName
+ "' ["
- + InetAddress.getByName(sHostName)
+ + hostAddress
+ "] "
+ _resBundDisplayMsgs.getString("toRunTest") +
"\n");
- // If IPv6 is preferred by Applet user, set property
for any further
- // use
- try {
- System.setProperty("java.net.preferIPv6Addresses",
- _chkboxPreferIPv6.isSelected() ? "true" : "false");
-
- System.setProperty("java.net.preferIPv4Stack",
- _chkboxPreferIPv6.isSelected() ? "false" : "true");
- } catch (SecurityException e) {
- System.err
- .println("Couldn't set system property. Check your security settings.");
- // retain this way for now
- }
// create socket to host specified by user and the
default port
- ctlSocket = new Socket(sHostName, ctlport);
+ ctlSocket = new Socket(hostAddress, ctlport);
} catch (UnknownHostException e) {
System.err.println("Don't know about host: " +
sHostName);
_sErrMsg = _resBundDisplayMsgs.getString("unknownServer") +
"\n";
@@ -3626,7 +3620,7 @@
// 1456, thus preserved
if(_iTimestampsEnabled == NDTConstants.RFC_1323_ENABLED)
iMss += 12;
-
+
if (iMss == NDTConstants.ETHERNET_MTU_SIZE)
_txtStatistics.append(_resBundDisplayMsgs
.getString("packetSizePreserved") +
"\n");
@@ -3895,4 +3889,34 @@
return null;
}

+ private void setsHostName(String sHostName) {
+ this.sHostName = sHostName;
+ setHostAddress(sHostName);
+ }
+
+ private void setHostAddress(String sHostName) {
+ InetAddress[] addresses;
+ InetAddress found = null;
+
+ try {
+ addresses = InetAddress.getAllByName(sHostName);
+
+ if (_chkboxPreferIPv6.isSelected()) {
+ for(int k = 0; k < addresses.length; ++k) {
+ if (addresses[k] instanceof
Inet6Address) {
+ found = addresses[k];
+ break;
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+
+ if (null != found) {
+ this.hostAddress = found;
+ } else if (addresses.length > 0) {
+ this.hostAddress = addresses[0];
+ }
+ }
} // class: Tcpbw100


  • [ndt-dev] [ndt] r850 committed - Fix issue with Prefer IPv6 checkbox...., ndt, 10/18/2013

Archive powered by MHonArc 2.6.16.

Top of Page