|
From: <hag...@us...> - 2006-12-22 09:56:54
|
Revision: 2953
http://jnode.svn.sourceforge.net/jnode/?rev=2953&view=rev
Author: hagar-wize
Date: 2006-12-22 01:56:52 -0800 (Fri, 22 Dec 2006)
Log Message:
-----------
Moved the printing of the dns servers to the command. Also using the out PrintStream to send output instead of System.out.
Modified Paths:
--------------
trunk/net/src/net/org/jnode/net/command/ResolverCommand.java
trunk/net/src/net/org/jnode/net/ipv4/util/ResolverImpl.java
Modified: trunk/net/src/net/org/jnode/net/command/ResolverCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/ResolverCommand.java 2006-12-22 07:43:57 UTC (rev 2952)
+++ trunk/net/src/net/org/jnode/net/command/ResolverCommand.java 2006-12-22 09:56:52 UTC (rev 2953)
@@ -23,6 +23,7 @@
import java.io.InputStream;
import java.io.PrintStream;
+import java.util.Collection;
import org.jnode.net.help.argument.HostArgument;
import org.jnode.net.ipv4.IPv4Address;
@@ -75,9 +76,16 @@
if (cmdLine.size() == 0)
{
- System.out.println("DNS servers");
- ResolverImpl.printDnsServers();
+ Collection<String> resolvers = ResolverImpl.getDnsServers();
+ if( resolvers == null )
+ out.println("No DNS servers found.");
+ else {
+ out.println("DNS servers");
+ for (String dnsServer : resolvers) {
+ out.println(dnsServer);
}
+ }
+ }
else
{
String func = ARG_FUNCTION.getValue(cmdLine);
@@ -93,7 +101,6 @@
}
}
- System.out.println();
-
+ out.println();
}
}
Modified: trunk/net/src/net/org/jnode/net/ipv4/util/ResolverImpl.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ipv4/util/ResolverImpl.java 2006-12-22 07:43:57 UTC (rev 2952)
+++ trunk/net/src/net/org/jnode/net/ipv4/util/ResolverImpl.java 2006-12-22 09:56:52 UTC (rev 2953)
@@ -28,6 +28,7 @@
import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
+import java.util.Collection;
import org.jnode.driver.net.NetworkException;
import org.jnode.net.ProtocolAddress;
@@ -88,17 +89,10 @@
}
/**
- * List all the dns servers
+ * Get list all the dns servers
*/
-
- public static void printDnsServers() {
- if (resolvers == null) {
- return;
- }
-
- for (String dnsServer : resolvers.keySet()) {
- System.out.println(dnsServer);
- }
+ public static Collection getDnsServers() {
+ return resolvers.keySet();
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-01-03 19:58:12
|
Revision: 2976
http://jnode.svn.sourceforge.net/jnode/?rev=2976&view=rev
Author: lsantha
Date: 2007-01-03 11:58:08 -0800 (Wed, 03 Jan 2007)
Log Message:
-----------
Moved shell related classes to shell project. Avoid fragmentation.
Modified Paths:
--------------
trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java
trunk/net/src/net/org/jnode/net/command/ResolverCommand.java
trunk/net/src/net/org/jnode/net/command/RouteCommand.java
trunk/net/src/net/org/jnode/net/command/TftpCommand.java
Removed Paths:
-------------
trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java
trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java
Modified: trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java 2007-01-02 19:34:53 UTC (rev 2975)
+++ trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java 2007-01-03 19:58:08 UTC (rev 2976)
@@ -29,7 +29,7 @@
import org.jnode.driver.net.NetDeviceAPI;
import org.jnode.naming.InitialNaming;
import org.jnode.net.ethernet.EthernetConstants;
-import org.jnode.net.help.argument.HostArgument;
+import org.jnode.shell.help.argument.HostArgument;
import org.jnode.net.ipv4.IPv4Address;
import org.jnode.net.ipv4.config.IPv4ConfigurationService;
import org.jnode.shell.Command;
Modified: trunk/net/src/net/org/jnode/net/command/ResolverCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/ResolverCommand.java 2007-01-02 19:34:53 UTC (rev 2975)
+++ trunk/net/src/net/org/jnode/net/command/ResolverCommand.java 2007-01-03 19:58:08 UTC (rev 2976)
@@ -25,7 +25,7 @@
import java.io.PrintStream;
import java.util.Collection;
-import org.jnode.net.help.argument.HostArgument;
+import org.jnode.shell.help.argument.HostArgument;
import org.jnode.net.ipv4.IPv4Address;
import org.jnode.net.ipv4.util.ResolverImpl;
import org.jnode.shell.Command;
Modified: trunk/net/src/net/org/jnode/net/command/RouteCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/RouteCommand.java 2007-01-02 19:34:53 UTC (rev 2975)
+++ trunk/net/src/net/org/jnode/net/command/RouteCommand.java 2007-01-03 19:58:08 UTC (rev 2976)
@@ -27,8 +27,8 @@
import org.jnode.driver.Device;
import org.jnode.naming.InitialNaming;
import org.jnode.net.ethernet.EthernetConstants;
-import org.jnode.net.help.argument.HostArgument;
-import org.jnode.net.help.argument.NetworkArgument;
+import org.jnode.shell.help.argument.HostArgument;
+import org.jnode.shell.help.argument.NetworkArgument;
import org.jnode.net.ipv4.IPv4Address;
import org.jnode.net.ipv4.config.IPv4ConfigurationService;
import org.jnode.net.ipv4.layer.IPv4NetworkLayer;
Modified: trunk/net/src/net/org/jnode/net/command/TftpCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/TftpCommand.java 2007-01-02 19:34:53 UTC (rev 2975)
+++ trunk/net/src/net/org/jnode/net/command/TftpCommand.java 2007-01-03 19:58:08 UTC (rev 2976)
@@ -24,7 +24,7 @@
import java.io.InputStream;
import java.io.PrintStream;
-import org.jnode.net.help.argument.HostArgument;
+import org.jnode.shell.help.argument.HostArgument;
import org.jnode.net.ipv4.tftp.TFTPClient;
import org.jnode.shell.Command;
import org.jnode.shell.CommandLine;
Deleted: trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java
===================================================================
--- trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java 2007-01-02 19:34:53 UTC (rev 2975)
+++ trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java 2007-01-03 19:58:08 UTC (rev 2976)
@@ -1,49 +0,0 @@
-/*
- * $Id: HostArgument.java 2224 2006-01-01 12:49:03Z epr $
- *
- * JNode.org
- * Copyright (C) 2003-2006 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library 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 Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.net.help.argument;
-
-import org.jnode.net.ipv4.IPv4Address;
-import org.jnode.shell.help.Argument;
-import org.jnode.shell.help.ParsedArguments;
-
-/**
- * @author qades
- */
-public class HostArgument extends Argument {
-
- public HostArgument(String name, String description, boolean multi) {
- super(name, description, multi);
- }
-
- public HostArgument(String name, String description) {
- super(name, description);
- }
-
- // here the specific command line completion would be implemented
-
- public IPv4Address getAddress(ParsedArguments args) {
- String value = getValue(args);
- if( value == null )
- return null;
- return new IPv4Address(value);
- }
-}
Deleted: trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java
===================================================================
--- trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java 2007-01-02 19:34:53 UTC (rev 2975)
+++ trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java 2007-01-03 19:58:08 UTC (rev 2976)
@@ -1,49 +0,0 @@
-/*
- * $Id: NetworkArgument.java 2224 2006-01-01 12:49:03Z epr $
- *
- * JNode.org
- * Copyright (C) 2003-2006 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library 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 Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.net.help.argument;
-
-import org.jnode.net.ipv4.IPv4Address;
-import org.jnode.shell.help.Argument;
-import org.jnode.shell.help.ParsedArguments;
-
-/**
- * @author qades
- */
-public class NetworkArgument extends Argument {
-
- public NetworkArgument(String name, String description, boolean multi) {
- super(name, description, multi);
- }
-
- public NetworkArgument(String name, String description) {
- super(name, description);
- }
-
- // here the specific command line completion would be implemented
-
- public IPv4Address getAddress(ParsedArguments args) {
- String value = getValue(args);
- if( "default".equals(value) )
- value = "0.0.0.0";
- return new IPv4Address(value);
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-01-03 20:24:28
|
Revision: 2979
http://jnode.svn.sourceforge.net/jnode/?rev=2979&view=rev
Author: lsantha
Date: 2007-01-03 12:24:27 -0800 (Wed, 03 Jan 2007)
Log Message:
-----------
Undoing last chenge.
Modified Paths:
--------------
trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java
trunk/net/src/net/org/jnode/net/command/ResolverCommand.java
trunk/net/src/net/org/jnode/net/command/RouteCommand.java
trunk/net/src/net/org/jnode/net/command/TftpCommand.java
Added Paths:
-----------
trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java
trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java
Modified: trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java 2007-01-03 20:23:46 UTC (rev 2978)
+++ trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java 2007-01-03 20:24:27 UTC (rev 2979)
@@ -29,7 +29,7 @@
import org.jnode.driver.net.NetDeviceAPI;
import org.jnode.naming.InitialNaming;
import org.jnode.net.ethernet.EthernetConstants;
-import org.jnode.shell.help.argument.HostArgument;
+import org.jnode.net.help.argument.HostArgument;
import org.jnode.net.ipv4.IPv4Address;
import org.jnode.net.ipv4.config.IPv4ConfigurationService;
import org.jnode.shell.Command;
Modified: trunk/net/src/net/org/jnode/net/command/ResolverCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/ResolverCommand.java 2007-01-03 20:23:46 UTC (rev 2978)
+++ trunk/net/src/net/org/jnode/net/command/ResolverCommand.java 2007-01-03 20:24:27 UTC (rev 2979)
@@ -25,7 +25,7 @@
import java.io.PrintStream;
import java.util.Collection;
-import org.jnode.shell.help.argument.HostArgument;
+import org.jnode.net.help.argument.HostArgument;
import org.jnode.net.ipv4.IPv4Address;
import org.jnode.net.ipv4.util.ResolverImpl;
import org.jnode.shell.Command;
Modified: trunk/net/src/net/org/jnode/net/command/RouteCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/RouteCommand.java 2007-01-03 20:23:46 UTC (rev 2978)
+++ trunk/net/src/net/org/jnode/net/command/RouteCommand.java 2007-01-03 20:24:27 UTC (rev 2979)
@@ -27,8 +27,8 @@
import org.jnode.driver.Device;
import org.jnode.naming.InitialNaming;
import org.jnode.net.ethernet.EthernetConstants;
-import org.jnode.shell.help.argument.HostArgument;
-import org.jnode.shell.help.argument.NetworkArgument;
+import org.jnode.net.help.argument.HostArgument;
+import org.jnode.net.help.argument.NetworkArgument;
import org.jnode.net.ipv4.IPv4Address;
import org.jnode.net.ipv4.config.IPv4ConfigurationService;
import org.jnode.net.ipv4.layer.IPv4NetworkLayer;
Modified: trunk/net/src/net/org/jnode/net/command/TftpCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/TftpCommand.java 2007-01-03 20:23:46 UTC (rev 2978)
+++ trunk/net/src/net/org/jnode/net/command/TftpCommand.java 2007-01-03 20:24:27 UTC (rev 2979)
@@ -24,7 +24,7 @@
import java.io.InputStream;
import java.io.PrintStream;
-import org.jnode.shell.help.argument.HostArgument;
+import org.jnode.net.help.argument.HostArgument;
import org.jnode.net.ipv4.tftp.TFTPClient;
import org.jnode.shell.Command;
import org.jnode.shell.CommandLine;
Copied: trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java (from rev 2977, trunk/shell/src/shell/org/jnode/shell/help/argument/HostArgument.java)
===================================================================
--- trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java (rev 0)
+++ trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java 2007-01-03 20:24:27 UTC (rev 2979)
@@ -0,0 +1,49 @@
+/*
+ * $Id: HostArgument.java 2224 2006-01-01 12:49:03Z epr $
+ *
+ * JNode.org
+ * Copyright (C) 2003-2006 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.net.help.argument;
+
+import org.jnode.net.ipv4.IPv4Address;
+import org.jnode.shell.help.Argument;
+import org.jnode.shell.help.ParsedArguments;
+
+/**
+ * @author qades
+ */
+public class HostArgument extends Argument {
+
+ public HostArgument(String name, String description, boolean multi) {
+ super(name, description, multi);
+ }
+
+ public HostArgument(String name, String description) {
+ super(name, description);
+ }
+
+ // here the specific command line completion would be implemented
+
+ public IPv4Address getAddress(ParsedArguments args) {
+ String value = getValue(args);
+ if( value == null )
+ return null;
+ return new IPv4Address(value);
+ }
+}
Copied: trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java (from rev 2977, trunk/shell/src/shell/org/jnode/shell/help/argument/NetworkArgument.java)
===================================================================
--- trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java (rev 0)
+++ trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java 2007-01-03 20:24:27 UTC (rev 2979)
@@ -0,0 +1,49 @@
+/*
+ * $Id: NetworkArgument.java 2224 2006-01-01 12:49:03Z epr $
+ *
+ * JNode.org
+ * Copyright (C) 2003-2006 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.net.help.argument;
+
+import org.jnode.net.ipv4.IPv4Address;
+import org.jnode.shell.help.Argument;
+import org.jnode.shell.help.ParsedArguments;
+
+/**
+ * @author qades
+ */
+public class NetworkArgument extends Argument {
+
+ public NetworkArgument(String name, String description, boolean multi) {
+ super(name, description, multi);
+ }
+
+ public NetworkArgument(String name, String description) {
+ super(name, description);
+ }
+
+ // here the specific command line completion would be implemented
+
+ public IPv4Address getAddress(ParsedArguments args) {
+ String value = getValue(args);
+ if( "default".equals(value) )
+ value = "0.0.0.0";
+ return new IPv4Address(value);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-05-13 12:02:21
|
Revision: 4095
http://jnode.svn.sourceforge.net/jnode/?rev=4095&view=rev
Author: crawley
Date: 2008-05-13 05:02:17 -0700 (Tue, 13 May 2008)
Log Message:
-----------
Preliminary code-style changes
Modified Paths:
--------------
trunk/net/src/net/org/jnode/net/command/TftpCommand.java
trunk/net/src/net/org/jnode/net/ipv4/tftp/TFTPClient.java
Modified: trunk/net/src/net/org/jnode/net/command/TftpCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/TftpCommand.java 2008-05-13 11:42:45 UTC (rev 4094)
+++ trunk/net/src/net/org/jnode/net/command/TftpCommand.java 2008-05-13 12:02:17 UTC (rev 4095)
@@ -18,7 +18,7 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.net.command;
import java.io.InputStream;
@@ -38,42 +38,43 @@
* @author markhale
*/
public class TftpCommand extends AbstractCommand {
-
- private static final OptionArgument.Option[] COMMAND_OPTIONS = new OptionArgument.Option[] {
- new OptionArgument.Option("put", "transfer a file to a server"),
- new OptionArgument.Option("get", "transfer a file from a server")
- };
- private static final HostArgument ARG_SERVER = new HostArgument("hostname", "the hostname of the TFTP server");
- private static final OptionArgument ARG_COMMAND = new OptionArgument("command", "must be either PUT or GET", COMMAND_OPTIONS);
- private static final Argument ARG_FILENAME = new Argument("filename", "the file to transfer");
-
- public static Help.Info HELP_INFO = new Help.Info(
- "tftp",
- new Syntax[] {
- new Syntax(
- "Start the TFTP client as an interactive session",
- new Parameter[] {
- new Parameter(ARG_SERVER, Parameter.OPTIONAL)
- }
- ),
- new Syntax(
- "Execute the TFTP client non-interactively",
- new Parameter[] {
- new Parameter(ARG_SERVER, Parameter.MANDATORY),
- new Parameter(ARG_COMMAND, Parameter.MANDATORY),
- new Parameter(ARG_FILENAME, Parameter.MANDATORY)
- }
- )
- }
- );
-
- public static void main(String[] args) throws Exception {
- new TftpCommand().execute(args);
- }
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception {
- TFTPClient.main(commandLine.getArguments());
- System.out.println();
- }
+ private static final OptionArgument.Option[] COMMAND_OPTIONS = new OptionArgument.Option[] {
+ new OptionArgument.Option("put", "transfer a file to a server"),
+ new OptionArgument.Option("get", "transfer a file from a server")
+ };
+ private static final HostArgument ARG_SERVER = new HostArgument("hostname", "the hostname of the TFTP server");
+ private static final OptionArgument ARG_COMMAND = new OptionArgument("command", "must be either PUT or GET", COMMAND_OPTIONS);
+ private static final Argument ARG_FILENAME = new Argument("filename", "the file to transfer");
+
+ public static Help.Info HELP_INFO = new Help.Info(
+ "tftp",
+ new Syntax[] {
+ new Syntax(
+ "Start the TFTP client as an interactive session",
+ new Parameter[] {
+ new Parameter(ARG_SERVER, Parameter.OPTIONAL)
+ }
+ ),
+ new Syntax(
+ "Execute the TFTP client non-interactively",
+ new Parameter[] {
+ new Parameter(ARG_SERVER, Parameter.MANDATORY),
+ new Parameter(ARG_COMMAND, Parameter.MANDATORY),
+ new Parameter(ARG_FILENAME, Parameter.MANDATORY)
+ }
+ )
+ }
+ );
+
+ public static void main(String[] args) throws Exception {
+ new TftpCommand().execute(args);
+ }
+
+ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ throws Exception {
+ TFTPClient.main(commandLine.getArguments());
+ System.out.println();
+ }
}
Modified: trunk/net/src/net/org/jnode/net/ipv4/tftp/TFTPClient.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ipv4/tftp/TFTPClient.java 2008-05-13 11:42:45 UTC (rev 4094)
+++ trunk/net/src/net/org/jnode/net/ipv4/tftp/TFTPClient.java 2008-05-13 12:02:17 UTC (rev 4095)
@@ -34,211 +34,251 @@
* @author markhale
*/
public class TFTPClient extends org.apache.commons.net.tftp.TFTPClient {
-
- public final static String CONNECT_CMD = "connect";
- public final static String PUT_CMD = "put";
- public final static String GET_CMD = "get";
- public final static String ASCII_CMD = "ascii";
- public final static String BINARY_CMD = "binary";
- public final static String TIMEOUT_CMD = "timeout";
- public final static String RETRIES_CMD = "retries";
- public final static String STATUS_CMD = "status";
- public final static String HELP_CMD = "help";
- public final static String QUIT_CMD = "quit";
-
- // BufferedReader does not currently function correctly (GNU classpath bug 5558)
- //private final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- // use DataInputStream instead
- private final DataInputStream in = new DataInputStream(System.in);
- private InetAddress serverAddress;
- private int mode = BINARY_MODE;
- private boolean quit;
-
- public static void main(String[] args) {
- TFTPClient client = new TFTPClient();
- if(args.length == 3) { // non-interactive mode
- if(args[1].equalsIgnoreCase(PUT_CMD)) {
- if(client.executeCommand(new String[] {CONNECT_CMD, args[0]}))
- client.executeCommand(new String[] {PUT_CMD, args[2]});
- } else if(args[1].equalsIgnoreCase(GET_CMD)) {
- if(client.executeCommand(new String[] {CONNECT_CMD, args[0]}))
- client.executeCommand(new String[] {GET_CMD, args[2]});
- } else {
- System.out.println("Unrecognised command line.");
- }
- } else { // interactive mode
- if(args.length == 1)
- client.executeCommand(new String[] {CONNECT_CMD, args[0]});
- client.run();
- }
- }
-
+
+ public final static String CONNECT_CMD = "connect";
+ public final static String PUT_CMD = "put";
+ public final static String GET_CMD = "get";
+ public final static String ASCII_CMD = "ascii";
+ public final static String BINARY_CMD = "binary";
+ public final static String TIMEOUT_CMD = "timeout";
+ public final static String RETRIES_CMD = "retries";
+ public final static String STATUS_CMD = "status";
+ public final static String HELP_CMD = "help";
+ public final static String QUIT_CMD = "quit";
+
+ // BufferedReader does not currently function correctly (GNU classpath bug 5558)
+ //private final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+ // use DataInputStream instead
+ private final DataInputStream in = new DataInputStream(System.in);
+ private InetAddress serverAddress;
+ private int mode = BINARY_MODE;
+ private boolean quit;
+
+
+ public static void main(String[] args) {
+ TFTPClient client = new TFTPClient();
+ if (args.length == 3) { // non-interactive mode
+ if (args[1].equalsIgnoreCase(PUT_CMD)) {
+ if (client.executeCommand(new String[] {CONNECT_CMD, args[0]})) {
+ client.executeCommand(new String[] {PUT_CMD, args[2]});
+ }
+ }
+ else if (args[1].equalsIgnoreCase(GET_CMD)) {
+ if (client.executeCommand(new String[] {CONNECT_CMD, args[0]})) {
+ client.executeCommand(new String[] {GET_CMD, args[2]});
+ }
+ }
+ else {
+ System.out.println("Unrecognised command line.");
+ }
+ }
+ else { // interactive mode
+ if (args.length == 1) {
+ client.executeCommand(new String[] {CONNECT_CMD, args[0]});
+ }
+ client.run();
+ }
+ }
+
@SuppressWarnings("deprecation")
- private void run() {
- System.out.println("JNode TFTP Client");
- do {
- try {
- System.out.print("tftp> ");
- String line = in.readLine();
- String[] args = parseLine(line);
- executeCommand(args);
- } catch(IOException ex) {
- }
- } while(!quit);
- }
- private final static String[] parseLine(String line) {
- // count arguments
- int count = 0;
- int pos = -1;
- do {
- count++;
- pos = line.indexOf(' ', pos+1);
- } while(pos != -1);
-
- // parse
- String[] args = new String[count];
- count = 0;
- pos = -1;
- do {
- int startPos = pos + 1;
- pos = line.indexOf(' ', startPos);
- if(pos != -1)
- args[count] = line.substring(startPos, pos);
- else
- args[count] = line.substring(startPos, line.length());
- count++;
- } while(pos != -1);
- return args;
- }
- /**
- * High-level command API.
- * @return true on success.
- */
- public boolean executeCommand(String[] args) {
- if(args == null || args.length < 1)
- return false;
-
- boolean success = false;
- final String cmd = args[0];
- if(cmd.equals(CONNECT_CMD)) { // connect
- if(args.length < 2) {
- System.out.println("Please specify a host name.");
- } else {
- try {
- serverAddress = InetAddress.getByName(args[1]);
- serverAddress.getHostName(); // do DNS lookup
- success = true;
- } catch(UnknownHostException ex) {
- System.out.println("Unknown host "+args[1]+".");
- }
- }
- } else if(cmd.equals(GET_CMD)) { // get
- if(serverAddress == null) {
- System.out.println("Not connected.");
- } else if(args.length < 2) {
- System.out.println("Please specify a file name.");
- } else {
- String filename = args[1];
- try {
- FileOutputStream fileOut = new FileOutputStream(filename);
- try {
- open();
- try {
- int bytesTransferred = receiveFile(filename, mode, fileOut, serverAddress);
- System.out.println(bytesTransferred+" bytes transferred.");
- } finally {
- close();
- }
- } finally {
- fileOut.close();
- }
- success = true;
- } catch(IOException ex) {
- System.out.println("Error transferring file: "+ex.getMessage());
- }
- }
- } else if(cmd.equals(PUT_CMD)) { // put
- if(serverAddress == null) {
- System.out.println("Not connected.");
- } else if(args.length < 2) {
- System.out.println("Please specify a file name.");
- } else {
- String filename = args[1];
- try {
- FileInputStream fileIn = new FileInputStream(filename);
- try {
- open();
- try {
- sendFile(filename, mode, fileIn, serverAddress);
- } finally {
- close();
- }
- } finally {
- fileIn.close();
- }
- success = true;
- } catch(IOException ex) {
- System.out.println("Error transferring file: "+ex.getMessage());
- }
- }
- } else if(cmd.equals(ASCII_CMD)) { // ascii
- mode = ASCII_MODE;
- success = true;
- } else if(cmd.equals(BINARY_CMD)) { // binary
- mode = BINARY_MODE;
- success = true;
- } else if(cmd.equals(TIMEOUT_CMD)) { // timeout
- if(args.length < 2) {
- System.out.println("Please specify a timeout value.");
- } else {
- try {
- setDefaultTimeout(Integer.parseInt(args[1]));
- success = true;
- } catch(NumberFormatException ex) {
- System.out.println("Invalid timeout value.");
- }
- }
- } else if(cmd.equals(RETRIES_CMD)) { // retries
- if(args.length < 2) {
- System.out.println("Please specify a retries value.");
- } else {
- try {
- setMaxTimeouts(Integer.parseInt(args[1]));
- success = true;
- } catch(NumberFormatException ex) {
- System.out.println("Invalid retries value.");
- }
- }
- } else if(cmd.equals(STATUS_CMD)) { // status
- if(serverAddress != null)
- System.out.println("Connected to "+serverAddress.getHostName()+".");
- else
- System.out.println("Not connected.");
- if(mode == ASCII_MODE)
- System.out.print("mode: ASCII");
- else if(mode == BINARY_MODE)
- System.out.print("mode: BINARY");
- System.out.print(" timeout: "+getDefaultTimeout());
- System.out.println(" retries: "+getMaxTimeouts());
- success = true;
- } else if(cmd.equals(HELP_CMD)) { // help
- System.out.println(ASCII_CMD+" - set mode to ASCII");
- System.out.println(CONNECT_CMD+" - connect to a tftp server");
- System.out.println(BINARY_CMD+" - set mode to binary");
- System.out.println(GET_CMD+" - receive file");
- System.out.println(HELP_CMD+" - display this help");
- System.out.println(PUT_CMD+" - send file");
- System.out.println(QUIT_CMD+" - exit");
- System.out.println(RETRIES_CMD+" - set retries");
- System.out.println(STATUS_CMD+" - display current status");
- System.out.println(TIMEOUT_CMD+" - set timeout");
- success = true;
- } else if(cmd.equals(QUIT_CMD)) { // quit
- quit = true;
- success = true;
- } else {
- System.out.println("Unrecognised command.");
- }
- return success;
- }
+ private void run() {
+ System.out.println("JNode TFTP Client");
+ do {
+ try {
+ System.out.print("tftp> ");
+ String line = in.readLine();
+ String[] args = parseLine(line);
+ executeCommand(args);
+ } catch (IOException ex) {
+ }
+ } while (!quit);
+ }
+
+
+ private final static String[] parseLine(String line) {
+ // count arguments
+ int count = 0;
+ int pos = -1;
+ do {
+ count++;
+ pos = line.indexOf(' ', pos+1);
+ } while (pos != -1);
+
+ // parse
+ String[] args = new String[count];
+ count = 0;
+ pos = -1;
+ do {
+ int startPos = pos + 1;
+ pos = line.indexOf(' ', startPos);
+ if (pos != -1) {
+ args[count] = line.substring(startPos, pos);
+ }
+ else {
+ args[count] = line.substring(startPos, line.length());
+ }
+ count++;
+ } while (pos != -1);
+ return args;
+ }
+ /**
+ * High-level command API.
+ * @return true on success.
+ */
+ public boolean executeCommand(String[] args) {
+ if (args == null || args.length < 1) {
+ return false;
+ }
+
+ boolean success = false;
+ final String cmd = args[0];
+ if (cmd.equals(CONNECT_CMD)) { // connect
+ if (args.length < 2) {
+ System.out.println("Please specify a host name.");
+ }
+ else {
+ try {
+ serverAddress = InetAddress.getByName(args[1]);
+ serverAddress.getHostName(); // do DNS lookup
+ success = true;
+ }
+ catch (UnknownHostException ex) {
+ System.out.println("Unknown host " + args[1] + ".");
+ }
+ }
+ }
+ else if (cmd.equals(GET_CMD)) { // get
+ if (serverAddress == null) {
+ System.out.println("Not connected.");
+ }
+ else if (args.length < 2) {
+ System.out.println("Please specify a file name.");
+ }
+ else {
+ String filename = args[1];
+ try {
+ FileOutputStream fileOut = new FileOutputStream(filename);
+ try {
+ open();
+ try {
+ int bytesTransferred = receiveFile(filename, mode, fileOut, serverAddress);
+ System.out.println(bytesTransferred + " bytes transferred.");
+ }
+ finally {
+ close();
+ }
+ }
+ finally {
+ fileOut.close();
+ }
+ success = true;
+ }
+ catch (IOException ex) {
+ System.out.println("Error transferring file: " + ex.getMessage());
+ }
+ }
+ }
+ else if (cmd.equals(PUT_CMD)) { // put
+ if (serverAddress == null) {
+ System.out.println("Not connected.");
+ }
+ else if (args.length < 2) {
+ System.out.println("Please specify a file name.");
+ }
+ else {
+ String filename = args[1];
+ try {
+ FileInputStream fileIn = new FileInputStream(filename);
+ try {
+ open();
+ try {
+ sendFile(filename, mode, fileIn, serverAddress);
+ }
+ finally {
+ close();
+ }
+ }
+ finally {
+ fileIn.close();
+ }
+ success = true;
+ }
+ catch (IOException ex) {
+ System.out.println("Error transferring file: " + ex.getMessage());
+ }
+ }
+ }
+ else if (cmd.equals(ASCII_CMD)) { // ascii
+ mode = ASCII_MODE;
+ success = true;
+ }
+ else if (cmd.equals(BINARY_CMD)) { // binary
+ mode = BINARY_MODE;
+ success = true;
+ }
+ else if (cmd.equals(TIMEOUT_CMD)) { // timeout
+ if (args.length < 2) {
+ System.out.println("Please specify a timeout value.");
+ }
+ else {
+ try {
+ setDefaultTimeout(Integer.parseInt(args[1]));
+ success = true;
+ } catch(NumberFormatException ex) {
+ System.out.println("Invalid timeout value.");
+ }
+ }
+ }
+ else if (cmd.equals(RETRIES_CMD)) { // retries
+ if (args.length < 2) {
+ System.out.println("Please specify a retries value.");
+ }
+ else {
+ try {
+ setMaxTimeouts(Integer.parseInt(args[1]));
+ success = true;
+ } catch(NumberFormatException ex) {
+ System.out.println("Invalid retries value.");
+ }
+ }
+ }
+ else if (cmd.equals(STATUS_CMD)) { // status
+ if (serverAddress != null) {
+ System.out.println("Connected to "+serverAddress.getHostName() + ".");
+ }
+ else {
+ System.out.println("Not connected.");
+ }
+ if (mode == ASCII_MODE) {
+ System.out.print("mode: ASCII");
+ }
+ else if (mode == BINARY_MODE) {
+ System.out.print("mode: BINARY");
+ }
+ System.out.print(" timeout: " + getDefaultTimeout());
+ System.out.println(" retries: " + getMaxTimeouts());
+ success = true;
+ }
+ else if (cmd.equals(HELP_CMD)) { // help
+ System.out.println(ASCII_CMD + " - set mode to ASCII");
+ System.out.println(CONNECT_CMD + " - connect to a tftp server");
+ System.out.println(BINARY_CMD + " - set mode to binary");
+ System.out.println(GET_CMD + " - receive file");
+ System.out.println(HELP_CMD + " - display this help");
+ System.out.println(PUT_CMD + " - send file");
+ System.out.println(QUIT_CMD + " - exit");
+ System.out.println(RETRIES_CMD + " - set retries");
+ System.out.println(STATUS_CMD + " - display current status");
+ System.out.println(TIMEOUT_CMD + " - set timeout");
+ success = true;
+ }
+ else if (cmd.equals(QUIT_CMD)) { // quit
+ quit = true;
+ success = true;
+ }
+ else {
+ System.out.println("Unrecognised command.");
+ }
+ return success;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-06-08 02:02:16
|
Revision: 4213
http://jnode.svn.sourceforge.net/jnode/?rev=4213&view=rev
Author: crawley
Date: 2008-06-07 19:02:10 -0700 (Sat, 07 Jun 2008)
Log Message:
-----------
Style fixes
Modified Paths:
--------------
trunk/net/src/net/org/jnode/net/HardwareAddress.java
trunk/net/src/net/org/jnode/net/InvalidLayerException.java
trunk/net/src/net/org/jnode/net/LayerAlreadyRegisteredException.java
trunk/net/src/net/org/jnode/net/LayerHeader.java
trunk/net/src/net/org/jnode/net/LinkLayer.java
trunk/net/src/net/org/jnode/net/LinkLayerHeader.java
trunk/net/src/net/org/jnode/net/NetPermission.java
trunk/net/src/net/org/jnode/net/NetworkLayer.java
trunk/net/src/net/org/jnode/net/NetworkLayerHeader.java
trunk/net/src/net/org/jnode/net/NetworkLayerManager.java
trunk/net/src/net/org/jnode/net/NoSuchProtocolException.java
trunk/net/src/net/org/jnode/net/ProtocolAddress.java
trunk/net/src/net/org/jnode/net/ProtocolAddressInfo.java
trunk/net/src/net/org/jnode/net/Resolver.java
trunk/net/src/net/org/jnode/net/SocketBuffer.java
trunk/net/src/net/org/jnode/net/TransportLayer.java
trunk/net/src/net/org/jnode/net/arp/ARPCache.java
trunk/net/src/net/org/jnode/net/arp/ARPCacheEntry.java
trunk/net/src/net/org/jnode/net/arp/ARPConstants.java
trunk/net/src/net/org/jnode/net/arp/ARPHeader.java
trunk/net/src/net/org/jnode/net/arp/ARPNetworkLayer.java
trunk/net/src/net/org/jnode/net/arp/ARPStatistics.java
trunk/net/src/net/org/jnode/net/arp/RARPNetworkLayer.java
trunk/net/src/net/org/jnode/net/command/ArpCommand.java
trunk/net/src/net/org/jnode/net/command/BootpCommand.java
trunk/net/src/net/org/jnode/net/command/DhcpCommand.java
trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java
trunk/net/src/net/org/jnode/net/command/NetstatCommand.java
trunk/net/src/net/org/jnode/net/command/PingCommand.java
trunk/net/src/net/org/jnode/net/command/ResolverCommand.java
trunk/net/src/net/org/jnode/net/command/RouteCommand.java
trunk/net/src/net/org/jnode/net/command/RpcInfoCommand.java
trunk/net/src/net/org/jnode/net/command/TcpInoutCommand.java
trunk/net/src/net/org/jnode/net/command/TftpCommand.java
trunk/net/src/net/org/jnode/net/command/WLanCtlCommand.java
trunk/net/src/net/org/jnode/net/ethernet/EthernetAddress.java
trunk/net/src/net/org/jnode/net/ethernet/EthernetConstants.java
trunk/net/src/net/org/jnode/net/ethernet/EthernetHeader.java
trunk/net/src/net/org/jnode/net/ethernet/EthernetUtils.java
trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java
trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4Address.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4AddressAndMask.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4Constants.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4ControlBlock.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4ControlBlockList.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4FragmentList.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4Header.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4IfAddress.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4Protocol.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4ProtocolAddressInfo.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4Route.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4RoutingTable.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4Service.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4Utils.java
trunk/net/src/net/org/jnode/net/ipv4/util/ResolverImpl.java
Modified: trunk/net/src/net/org/jnode/net/HardwareAddress.java
===================================================================
--- trunk/net/src/net/org/jnode/net/HardwareAddress.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/HardwareAddress.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -27,44 +27,44 @@
*/
public interface HardwareAddress {
- /**
- * Is this address equal to the given address.
- * @param o
- */
- public boolean equals(HardwareAddress o);
-
- /**
- * Gets the length of this address in bytes
- */
- public int getLength();
-
- /**
- * Gets the address-byte at a given index
- * @param index
- */
- public byte get(int index);
-
- /**
- * Write this address to a given offset in the given buffer
- * @param skbuf
- * @param skbufOffset
- */
- public void writeTo(SocketBuffer skbuf, int skbufOffset);
-
- /**
- * Is this a broadcast address?
- */
- public boolean isBroadcast();
+ /**
+ * Is this address equal to the given address.
+ * @param o
+ */
+ public boolean equals(HardwareAddress o);
- /**
- * Gets the default broadcast address for this kind of hardware address.
- */
- public HardwareAddress getDefaultBroadcastAddress();
-
- /**
- * Gets the type of this address.
- * This type is used by (e.g.) ARP.
- */
- public int getType();
-
+ /**
+ * Gets the length of this address in bytes
+ */
+ public int getLength();
+
+ /**
+ * Gets the address-byte at a given index
+ * @param index
+ */
+ public byte get(int index);
+
+ /**
+ * Write this address to a given offset in the given buffer
+ * @param skbuf
+ * @param skbufOffset
+ */
+ public void writeTo(SocketBuffer skbuf, int skbufOffset);
+
+ /**
+ * Is this a broadcast address?
+ */
+ public boolean isBroadcast();
+
+ /**
+ * Gets the default broadcast address for this kind of hardware address.
+ */
+ public HardwareAddress getDefaultBroadcastAddress();
+
+ /**
+ * Gets the type of this address.
+ * This type is used by (e.g.) ARP.
+ */
+ public int getType();
+
}
Modified: trunk/net/src/net/org/jnode/net/InvalidLayerException.java
===================================================================
--- trunk/net/src/net/org/jnode/net/InvalidLayerException.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/InvalidLayerException.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -28,18 +28,18 @@
*/
public class InvalidLayerException extends SocketException {
- /**
- *
- */
- public InvalidLayerException() {
- super();
- }
+ /**
+ *
+ */
+ public InvalidLayerException() {
+ super();
+ }
- /**
- * @param message
- */
- public InvalidLayerException(String message) {
- super(message);
- }
+ /**
+ * @param message
+ */
+ public InvalidLayerException(String message) {
+ super(message);
+ }
}
Modified: trunk/net/src/net/org/jnode/net/LayerAlreadyRegisteredException.java
===================================================================
--- trunk/net/src/net/org/jnode/net/LayerAlreadyRegisteredException.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/LayerAlreadyRegisteredException.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -28,36 +28,34 @@
*/
public class LayerAlreadyRegisteredException extends SocketException {
- /**
- *
- */
- public LayerAlreadyRegisteredException() {
- super();
- }
+ /**
+ *
+ */
+ public LayerAlreadyRegisteredException() {
+ super();
+ }
- /**
- * @param message
- * @param cause
- */
- public LayerAlreadyRegisteredException(
- String message,
- Throwable cause) {
- super(message);
- initCause(cause);
- }
+ /**
+ * @param message
+ * @param cause
+ */
+ public LayerAlreadyRegisteredException(String message, Throwable cause) {
+ super(message);
+ initCause(cause);
+ }
- /**
- * @param cause
- */
- public LayerAlreadyRegisteredException(Throwable cause) {
- super();
- initCause(cause);
- }
+ /**
+ * @param cause
+ */
+ public LayerAlreadyRegisteredException(Throwable cause) {
+ super();
+ initCause(cause);
+ }
- /**
- * @param s
- */
- public LayerAlreadyRegisteredException(String s) {
- super(s);
- }
+ /**
+ * @param s
+ */
+ public LayerAlreadyRegisteredException(String s) {
+ super(s);
+ }
}
Modified: trunk/net/src/net/org/jnode/net/LayerHeader.java
===================================================================
--- trunk/net/src/net/org/jnode/net/LayerHeader.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/LayerHeader.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -30,25 +30,27 @@
* @see org.jnode.net.TransportLayerHeader
*/
public interface LayerHeader {
-
- /**
- * Gets the length of this header in bytes
- */
- public int getLength();
- /**
- * Prefix this header to the front of the given buffer
- * @param skbuf
- */
- public void prefixTo(SocketBuffer skbuf);
-
- /**
- * Finalize the header in the given buffer.
- * This method is called when all layers have set their header data
- * and can be used e.g. to update checksum values.
- *
- * @param skbuf The buffer
- * @param offset The offset to the first byte (in the buffer) of this header (since low layer headers are already prefixed)
- */
- public void finalizeHeader(SocketBuffer skbuf, int offset);
+ /**
+ * Gets the length of this header in bytes
+ */
+ public int getLength();
+
+ /**
+ * Prefix this header to the front of the given buffer
+ *
+ * @param skbuf
+ */
+ public void prefixTo(SocketBuffer skbuf);
+
+ /**
+ * Finalize the header in the given buffer. This method is called when all
+ * layers have set their header data and can be used e.g. to update checksum
+ * values.
+ *
+ * @param skbuf The buffer
+ * @param offset The offset to the first byte (in the buffer) of this header
+ * (since low layer headers are already prefixed)
+ */
+ public void finalizeHeader(SocketBuffer skbuf, int offset);
}
Modified: trunk/net/src/net/org/jnode/net/LinkLayer.java
===================================================================
--- trunk/net/src/net/org/jnode/net/LinkLayer.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/LinkLayer.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -25,28 +25,28 @@
/**
* OSI datalink layers must implement this interface.
- *
+ *
* @author epr
*/
public interface LinkLayer {
-
- /**
- * Gets the name of this layer
- */
- public String getName();
-
- /**
- * Gets the type of frames this layer handles
- */
- public int getType();
-
- /**
- * Process a packet that has been received and matches the type of this
- * layer.
- * @param skbuf
- * @throws SocketException
- */
- public void receive(SocketBuffer skbuf)
- throws SocketException;
+ /**
+ * Gets the name of this layer
+ */
+ public String getName();
+
+ /**
+ * Gets the type of frames this layer handles
+ */
+ public int getType();
+
+ /**
+ * Process a packet that has been received and matches the type of this
+ * layer.
+ *
+ * @param skbuf
+ * @throws SocketException
+ */
+ public void receive(SocketBuffer skbuf) throws SocketException;
+
}
Modified: trunk/net/src/net/org/jnode/net/LinkLayerHeader.java
===================================================================
--- trunk/net/src/net/org/jnode/net/LinkLayerHeader.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/LinkLayerHeader.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -28,15 +28,15 @@
* @see org.jnode.net.LinkLayer
*/
public interface LinkLayerHeader extends LayerHeader {
-
- /**
- * Gets the source address of the packet described in this header
- */
- public HardwareAddress getSourceAddress();
- /**
- * Gets the source address of the packet described in this header
- */
- public HardwareAddress getDestinationAddress();
+ /**
+ * Gets the source address of the packet described in this header
+ */
+ public HardwareAddress getSourceAddress();
+ /**
+ * Gets the source address of the packet described in this header
+ */
+ public HardwareAddress getDestinationAddress();
+
}
Modified: trunk/net/src/net/org/jnode/net/NetPermission.java
===================================================================
--- trunk/net/src/net/org/jnode/net/NetPermission.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/NetPermission.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -35,7 +35,7 @@
public NetPermission(String name) {
super(name);
}
-
+
/**
* @param name
* @param actions
Modified: trunk/net/src/net/org/jnode/net/NetworkLayer.java
===================================================================
--- trunk/net/src/net/org/jnode/net/NetworkLayer.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/NetworkLayer.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -34,66 +34,70 @@
* @author epr
*/
public interface NetworkLayer {
-
- /**
- * Gets the name of this type
- */
- public String getName();
-
- /**
- * Gets the protocol ID this layer handles
- */
- public int getProtocolID();
-
- /**
- * Can this packet type process packets received from the given device?
- */
- public boolean isAllowedForDevice(Device dev);
-
- /**
- * Process a packet that has been received and matches getType()
- * @param skbuf
- * @param deviceAPI
- * @throws SocketException
- */
- public void receive(SocketBuffer skbuf, NetDeviceAPI deviceAPI)
- throws SocketException;
-
- /**
- * Gets the statistics of this protocol
- */
- public Statistics getStatistics();
- /**
- * Register a transportlayer as possible destination of packets received by this networklayer
- * @param layer
- */
- public void registerTransportLayer(TransportLayer layer)
- throws LayerAlreadyRegisteredException, InvalidLayerException;
-
- /**
- * Unregister a transportlayer
- * @param layer
- */
- public void unregisterTransportLayer(TransportLayer layer);
-
- /**
- * Gets all registered transport-layers
- */
- public Collection<TransportLayer> getTransportLayers();
-
- /**
- * Gets a registered transportlayer by its protocol ID.
- * @param protocolID
- * @throws NoSuchProtocolException No protocol with the given ID was found.
- */
- public TransportLayer getTransportLayer(int protocolID)
- throws NoSuchProtocolException;
+ /**
+ * Gets the name of this type
+ */
+ public String getName();
- /**
- * Gets the protocol addresses for a given name, or null if not found.
- * @param hostname
- * @return
- */
+ /**
+ * Gets the protocol ID this layer handles
+ */
+ public int getProtocolID();
+
+ /**
+ * Can this packet type process packets received from the given device?
+ */
+ public boolean isAllowedForDevice(Device dev);
+
+ /**
+ * Process a packet that has been received and matches getType()
+ *
+ * @param skbuf
+ * @param deviceAPI
+ * @throws SocketException
+ */
+ public void receive(SocketBuffer skbuf, NetDeviceAPI deviceAPI) throws SocketException;
+
+ /**
+ * Gets the statistics of this protocol
+ */
+ public Statistics getStatistics();
+
+ /**
+ * Register a transportlayer as possible destination of packets received by
+ * this networklayer
+ *
+ * @param layer
+ */
+ public void registerTransportLayer(TransportLayer layer)
+ throws LayerAlreadyRegisteredException, InvalidLayerException;
+
+ /**
+ * Unregister a transportlayer
+ *
+ * @param layer
+ */
+ public void unregisterTransportLayer(TransportLayer layer);
+
+ /**
+ * Gets all registered transport-layers
+ */
+ public Collection<TransportLayer> getTransportLayers();
+
+ /**
+ * Gets a registered transportlayer by its protocol ID.
+ *
+ * @param protocolID
+ * @throws NoSuchProtocolException No protocol with the given ID was found.
+ */
+ public TransportLayer getTransportLayer(int protocolID) throws NoSuchProtocolException;
+
+ /**
+ * Gets the protocol addresses for a given name, or null if not found.
+ *
+ * @param hostname
+ * @return
+ */
public ProtocolAddress[] getHostByName(String hostname);
}
Modified: trunk/net/src/net/org/jnode/net/NetworkLayerHeader.java
===================================================================
--- trunk/net/src/net/org/jnode/net/NetworkLayerHeader.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/NetworkLayerHeader.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -29,13 +29,13 @@
*/
public interface NetworkLayerHeader extends LayerHeader {
- /**
- * Gets the source address of the packet described in this header
- */
- public ProtocolAddress getSourceAddress();
+ /**
+ * Gets the source address of the packet described in this header
+ */
+ public ProtocolAddress getSourceAddress();
- /**
- * Gets the source address of the packet described in this header
- */
- public ProtocolAddress getDestinationAddress();
+ /**
+ * Gets the source address of the packet described in this header
+ */
+ public ProtocolAddress getDestinationAddress();
}
Modified: trunk/net/src/net/org/jnode/net/NetworkLayerManager.java
===================================================================
--- trunk/net/src/net/org/jnode/net/NetworkLayerManager.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/NetworkLayerManager.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -26,44 +26,42 @@
import org.jnode.driver.net.NetworkException;
/**
- * This interface must be implemented by the network service of the JNode kernel.
- * It contains methods to register/unregister and obtain NetworkLayers, and
- * it is used by Network drivers to deliver receive packets.
- * <p/>
- * The implementation of this interface must be obtained by invoking a lookup
- * of {@link #NAME} on {@link org.jnode.naming.InitialNaming}.
+ * This interface must be implemented by the network service of the JNode
+ * kernel. It contains methods to register/unregister and obtain NetworkLayers,
+ * and it is used by Network drivers to deliver receive packets. <p/> The
+ * implementation of this interface must be obtained by invoking a lookup of
+ * {@link #NAME} on {@link org.jnode.naming.InitialNaming}.
*
* @author epr
* @see org.jnode.driver.net.NetDeviceAPI
*/
public interface NetworkLayerManager {
- /** Name used to bind the ptm in the InitialNaming namespace */
- public static final Class<NetworkLayerManager> NAME = NetworkLayerManager.class;//"system/net/networklayermanager";
+ /** Name used to bind the ptm in the InitialNaming namespace */
+ public static final Class<NetworkLayerManager> NAME = NetworkLayerManager.class;
+
+ /**
+ * Get all register packet types.
+ *
+ * @return A collection of PacketType instances
+ */
+ public Collection<NetworkLayer> getNetworkLayers();
- /**
- * Get all register packet types.
- * @return A collection of PacketType instances
- */
- public Collection<NetworkLayer> getNetworkLayers();
-
- /**
- * Gets the packet type for a given protocol ID
- * @param protocolID
- * @throws NoSuchProtocolException
- */
- public NetworkLayer getNetworkLayer(int protocolID)
- throws NoSuchProtocolException;
-
- /**
- * Process a packet that has been received.
- * The receive method of all those packettypes that have a matching type
- * and allow the device(of the packet) is called.
- * The packet is cloned if more then 1 packettypes want to receive the
- * packet.
- *
- * @param skbuf
- */
- public void receive(SocketBuffer skbuf)
- throws NetworkException;
+ /**
+ * Gets the packet type for a given protocol ID
+ *
+ * @param protocolID
+ * @throws NoSuchProtocolException
+ */
+ public NetworkLayer getNetworkLayer(int protocolID) throws NoSuchProtocolException;
+
+ /**
+ * Process a packet that has been received. The receive method of all those
+ * packettypes that have a matching type and allow the device(of the packet)
+ * is called. The packet is cloned if more then 1 packettypes want to
+ * receive the packet.
+ *
+ * @param skbuf
+ */
+ public void receive(SocketBuffer skbuf) throws NetworkException;
}
Modified: trunk/net/src/net/org/jnode/net/NoSuchProtocolException.java
===================================================================
--- trunk/net/src/net/org/jnode/net/NoSuchProtocolException.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/NoSuchProtocolException.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -28,17 +28,17 @@
*/
public class NoSuchProtocolException extends SocketException {
- /**
- *
- */
- public NoSuchProtocolException() {
- super();
- }
+ /**
+ *
+ */
+ public NoSuchProtocolException() {
+ super();
+ }
- /**
- * @param message
- */
- public NoSuchProtocolException(String message) {
- super(message);
- }
+ /**
+ * @param message
+ */
+ public NoSuchProtocolException(String message) {
+ super(message);
+ }
}
Modified: trunk/net/src/net/org/jnode/net/ProtocolAddress.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ProtocolAddress.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/ProtocolAddress.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -29,44 +29,44 @@
*/
public interface ProtocolAddress {
- /**
- * Is this address equal to the given address.
- * @param o
- */
- public boolean equals(ProtocolAddress o);
-
- /**
- * Gets the length of this address in bytes
- */
- public int getLength();
-
- /**
- * Gets the address-byte at a given index
- * @param index
- */
- public byte get(int index);
-
- /**
- * Write this address to a given offset in the given buffer
- * @param skbuf
- * @param skbufOffset
- */
- public void writeTo(SocketBuffer skbuf, int skbufOffset);
+ /**
+ * Is this address equal to the given address.
+ * @param o
+ */
+ public boolean equals(ProtocolAddress o);
- /**
- * Gets the type of this address.
- * This type is used by (e.g.) ARP.
- */
- public int getType();
+ /**
+ * Gets the length of this address in bytes
+ */
+ public int getLength();
- /**
- * Convert to a java.net.InetAddress
- * @see java.net.InetAddress
- * @return This address as java.net.InetAddress
- */
- public InetAddress toInetAddress();
+ /**
+ * Gets the address-byte at a given index
+ * @param index
+ */
+ public byte get(int index);
/**
+ * Write this address to a given offset in the given buffer
+ * @param skbuf
+ * @param skbufOffset
+ */
+ public void writeTo(SocketBuffer skbuf, int skbufOffset);
+
+ /**
+ * Gets the type of this address.
+ * This type is used by (e.g.) ARP.
+ */
+ public int getType();
+
+ /**
+ * Convert to a java.net.InetAddress
+ * @see java.net.InetAddress
+ * @return This address as java.net.InetAddress
+ */
+ public InetAddress toInetAddress();
+
+ /**
* Convert to a new byte array.
* @return This address as byte array.
*/
Modified: trunk/net/src/net/org/jnode/net/ProtocolAddressInfo.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ProtocolAddressInfo.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/ProtocolAddressInfo.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -33,26 +33,26 @@
*/
public interface ProtocolAddressInfo {
- /**
- * Is the given address one of the addresses of this object?
- * @param address
- */
- public boolean contains(ProtocolAddress address);
-
- /**
- * Is the given address one of the addresses of this object?
- * @param address
- */
- public boolean contains(InetAddress address);
-
- /**
- * Gets the default protocol address
- */
- public ProtocolAddress getDefaultAddress();
+ /**
+ * Is the given address one of the addresses of this object?
+ * @param address
+ */
+ public boolean contains(ProtocolAddress address);
- /**
- * Gets a collection of all protocol addresses of this interface.
- * @return A Set of ProtocolAddress instances
- */
- public Set<ProtocolAddress> addresses();
+ /**
+ * Is the given address one of the addresses of this object?
+ * @param address
+ */
+ public boolean contains(InetAddress address);
+
+ /**
+ * Gets the default protocol address
+ */
+ public ProtocolAddress getDefaultAddress();
+
+ /**
+ * Gets a collection of all protocol addresses of this interface.
+ * @return A Set of ProtocolAddress instances
+ */
+ public Set<ProtocolAddress> addresses();
}
Modified: trunk/net/src/net/org/jnode/net/Resolver.java
===================================================================
--- trunk/net/src/net/org/jnode/net/Resolver.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/Resolver.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -27,24 +27,25 @@
* @author epr
*/
public interface Resolver {
-
- /**
- * Gets the address(es) of the given hostname.
- * @param hostname
- * @return All addresses of the given hostname. The returned array is at least 1 address long.
- * @throws UnknownHostException
- */
- public ProtocolAddress[] getByName(String hostname)
- throws UnknownHostException;
- /**
- * Gets the hostname of the given address.
- * @param address
- * @return All hostnames of the given hostname. The returned array is at least 1 hostname long.
- * @throws UnknownHostException
- */
- public String[] getByAddress(ProtocolAddress address)
- throws UnknownHostException;
-
+ /**
+ * Gets the address(es) of the given hostname.
+ *
+ * @param hostname
+ * @return All addresses of the given hostname. The returned array is at
+ * least 1 address long.
+ * @throws UnknownHostException
+ */
+ public ProtocolAddress[] getByName(String hostname) throws UnknownHostException;
+ /**
+ * Gets the hostname of the given address.
+ *
+ * @param address
+ * @return All hostnames of the given hostname. The returned array is at
+ * least 1 hostname long.
+ * @throws UnknownHostException
+ */
+ public String[] getByAddress(ProtocolAddress address) throws UnknownHostException;
+
}
Modified: trunk/net/src/net/org/jnode/net/SocketBuffer.java
===================================================================
--- trunk/net/src/net/org/jnode/net/SocketBuffer.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/SocketBuffer.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -25,649 +25,672 @@
import org.jnode.driver.Device;
/**
- * A SocketBuffer is container of a network packet. It enables efficient
- * storage even when various network layers prefix and/or postfix header/footers.
- * It also contains other information of a network packet, such as the headers
- * of the various network layers.
+ * A SocketBuffer is container of a network packet. It enables efficient storage
+ * even when various network layers prefix and/or postfix header/footers. It
+ * also contains other information of a network packet, such as the headers of
+ * the various network layers.
*
- * All numbers larger then a single byte written into this class are
- * converted to network byte order.
+ * All numbers larger then a single byte written into this class are converted
+ * to network byte order.
*
- * All numbers larger then a single byte read from this class are
- * converted from network byte order.
+ * All numbers larger then a single byte read from this class are converted from
+ * network byte order.
*
* @author epr
*/
public class SocketBuffer {
- private static final int INITIAL_SIZE = 256;
+ private static final int INITIAL_SIZE = 256;
- /** My logger */
- private static final Logger log = Logger.getLogger(SocketBuffer.class);
- /** Actual data */
- private byte[] data;
- /** Size of the buffer that is in use */
- private int size;
- /** Start offset in data */
- private int start;
- /** Next buffer, that is concatenated with this one */
- private SocketBuffer next;
+ /** My logger */
+ private static final Logger log = Logger.getLogger(SocketBuffer.class);
+ /** Actual data */
+ private byte[] data;
+ /** Size of the buffer that is in use */
+ private int size;
+ /** Start offset in data */
+ private int start;
+ /** Next buffer, that is concatenated with this one */
+ private SocketBuffer next;
- /** The network device who will be sending, or has received this buffer */
- private Device device;
- /** Identifying type of the packettype */
- private int protocolID;
- /** Link layer header (if any) */
- private LinkLayerHeader linkLayerHeader;
- /** Network layer header (if any) */
- private NetworkLayerHeader networkLayerHeader;
- /** Transport layer header (if any) */
- private TransportLayerHeader transportLayerHeader;
+ /** The network device who will be sending, or has received this buffer */
+ private Device device;
+ /** Identifying type of the packettype */
+ private int protocolID;
+ /** Link layer header (if any) */
+ private LinkLayerHeader linkLayerHeader;
+ /** Network layer header (if any) */
+ private NetworkLayerHeader networkLayerHeader;
+ /** Transport layer header (if any) */
+ private TransportLayerHeader transportLayerHeader;
- /**
- * Create a new instance
- */
- public SocketBuffer() {
- }
+ /**
+ * Create a new instance
+ */
+ public SocketBuffer() {
+ }
- /**
- * Create a new instance with a buffer of a given capacity
- */
- public SocketBuffer(int initialCapacity) {
- this(initialCapacity, 0);
- }
+ /**
+ * Create a new instance with a buffer of a given capacity
+ */
+ public SocketBuffer(int initialCapacity) {
+ this(initialCapacity, 0);
+ }
- /**
- * Create a new instance with a buffer of a given capacity
- */
- public SocketBuffer(int initialCapacity, int initialStart) {
- this.data = new byte[initialCapacity];
- }
+ /**
+ * Create a new instance with a buffer of a given capacity
+ */
+ ...
[truncated message content] |
|
From: <ls...@us...> - 2008-06-15 12:50:48
|
Revision: 4241
http://jnode.svn.sourceforge.net/jnode/?rev=4241&view=rev
Author: lsantha
Date: 2008-06-15 05:50:44 -0700 (Sun, 15 Jun 2008)
Log Message:
-----------
Turned off dangerous logging.
Modified Paths:
--------------
trunk/net/src/net/org/jnode/net/arp/ARPNetworkLayer.java
trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPControlBlock.java
trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutChannel.java
trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutSegment.java
trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPProtocol.java
trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPSocketImpl.java
Modified: trunk/net/src/net/org/jnode/net/arp/ARPNetworkLayer.java
===================================================================
--- trunk/net/src/net/org/jnode/net/arp/ARPNetworkLayer.java 2008-06-15 09:44:26 UTC (rev 4240)
+++ trunk/net/src/net/org/jnode/net/arp/ARPNetworkLayer.java 2008-06-15 12:50:44 UTC (rev 4241)
@@ -24,7 +24,6 @@
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collection;
-
import org.apache.log4j.Logger;
import org.jnode.driver.ApiNotFoundException;
import org.jnode.driver.Device;
@@ -49,12 +48,19 @@
*/
@SharedStatics
public class ARPNetworkLayer implements NetworkLayer, ARPConstants {
+ private static final boolean DEBUG = false;
- /** My logger */
+ /**
+ * My logger
+ */
private static final Logger log = Logger.getLogger(ARPNetworkLayer.class);
- /** My statistics */
+ /**
+ * My statistics
+ */
private final ARPStatistics stat = new ARPStatistics();
- /** ARP cache */
+ /**
+ * ARP cache
+ */
private static final ARPCache cache = new ARPCache();
/**
@@ -87,7 +93,7 @@
/**
* Process a packet that has been received and matches getType()
- *
+ *
* @param skbuf
* @param deviceAPI
* @throws SocketException
@@ -126,7 +132,7 @@
/**
* Process and ARP request.
- *
+ *
* @param skbuf
* @param hdr
* @param deviceAPI
@@ -154,7 +160,7 @@
/**
* Process and ARP reply
- *
+ *
* @param skbuf
* @param hdr
* @param deviceAPI
@@ -167,7 +173,7 @@
/**
* Process and RARP request
- *
+ *
* @param skbuf
* @param hdr
* @param deviceAPI
@@ -181,7 +187,7 @@
/**
* Process and RARP reply
- *
+ *
* @param skbuf
* @param hdr
* @param deviceAPI
@@ -230,7 +236,7 @@
/**
* Gets a registered transportlayer by its protocol ID.
- *
+ *
* @param protocolID
*/
public TransportLayer getTransportLayer(int protocolID) throws NoSuchProtocolException {
@@ -239,7 +245,7 @@
/**
* Gets the hardware address for a given protocol address.
- *
+ *
* @param address
* @param myAddress
* @param device
@@ -248,13 +254,15 @@
* @throws NetworkException
*/
public HardwareAddress getHardwareAddress(ProtocolAddress address, ProtocolAddress myAddress,
- Device device, long timeout) throws TimeoutException, NetworkException {
+ Device device, long timeout) throws TimeoutException, NetworkException {
final long start = System.currentTimeMillis();
long lastReq = 0;
- if (log.isDebugEnabled()) {
- log.debug("getHardwareAddress(" + address + ", " + myAddress + ", " + device.getId() +
+ if (DEBUG) {
+ if (log.isDebugEnabled()) {
+ log.debug("getHardwareAddress(" + address + ", " + myAddress + ", " + device.getId() +
", " + timeout + ")");
+ }
}
if (address.equals(myAddress)) {
@@ -285,7 +293,7 @@
/**
* Gets the protocol addresses for a given name, or null if not found.
- *
+ *
* @param hostname
* @return
*/
@@ -295,7 +303,7 @@
/**
* Create and transmit an ARP request
- *
+ *
* @param address
* @param myAddress
* @param device
@@ -310,8 +318,7 @@
final int hwtype = srcHwAddr.getType();
final int ptype = address.getType();
- final ARPHeader hdr =
- new ARPHeader(srcHwAddr, myAddress, trgHwAddr, address, op, hwtype, ptype);
+ final ARPHeader hdr = new ARPHeader(srcHwAddr, myAddress, trgHwAddr, address, op, hwtype, ptype);
final SocketBuffer skbuf = new SocketBuffer();
skbuf.setProtocolID(EthernetConstants.ETH_P_ARP);
hdr.prefixTo(skbuf);
@@ -321,7 +328,7 @@
/**
* Gets the NetDeviceAPI for a given device
- *
+ *
* @param device
*/
private NetDeviceAPI getAPI(Device device) {
Modified: trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPControlBlock.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPControlBlock.java 2008-06-15 09:44:26 UTC (rev 4240)
+++ trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPControlBlock.java 2008-06-15 12:50:44 UTC (rev 4241)
@@ -18,14 +18,13 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.net.ipv4.tcp;
import java.net.ConnectException;
import java.net.SocketException;
import java.util.LinkedList;
-
import org.apache.log4j.Logger;
import org.jnode.net.SocketBuffer;
import org.jnode.net.ipv4.IPv4Address;
@@ -39,7 +38,7 @@
* @author Ewout Prangsma (ep...@us...)
*/
public class TCPControlBlock extends IPv4ControlBlock implements TCPConstants {
-
+ private static final boolean DEBUG = false;
/**
* My logger
*/
@@ -57,7 +56,7 @@
/** Last incoming sequence number */
// private int lastInSeqNr;
-
+
/**
* Window size of the outgoing connection
*/
@@ -95,14 +94,14 @@
/**
* Create a new instance
- *
+ *
* @param list
* @param parent
* @param tcp
- * @param isn The initial outgoing sequence number
+ * @param isn The initial outgoing sequence number
*/
public TCPControlBlock(TCPControlBlockList list, TCPControlBlock parent, TCPProtocol tcp,
- int isn) {
+ int isn) {
super(list, IPv4Constants.IPPROTO_TCP, TCP_DEFAULT_TTL);
this.parent = parent;
this.outChannel = new TCPOutChannel(tcp, this, isn);
@@ -120,13 +119,15 @@
/**
* Handle a received segment for this connection
- *
+ *
* @param hdr
* @param skbuf
*/
public synchronized void receive(TCPHeader hdr, SocketBuffer skbuf) throws SocketException {
- if (log.isDebugEnabled()) {
- log.debug("receive: me=[" + this + "], hdr=[" + hdr + "]");
+ if (DEBUG) {
+ if (log.isDebugEnabled()) {
+ log.debug("receive: me=[" + this + "], hdr=[" + hdr + "]");
+ }
}
final IPv4Header ipHdr = (IPv4Header) skbuf.getNetworkLayerHeader();
@@ -171,19 +172,21 @@
receiveTimeWait(ipHdr, hdr, skbuf);
break;
default:
- log.debug("Unhandled state in receive (" + getStateName() + ")");
+ if (DEBUG) {
+ log.debug("Unhandled state in receive (" + getStateName() + ")");
+ }
break;
}
}
/**
* Process a reset segment
- *
+ *
* @param ipHdr
* @param hdr
* @param skbuf
*/
- private final void receiveProcessReset(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveProcessReset(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean ack = hdr.isFlagAcknowledgeSet();
final boolean syn = hdr.isFlagSynchronizeSet();
@@ -227,13 +230,15 @@
/**
* Current state is LISTEN. If a SYN segment is received, send a SYN&ACK,
* and set the state to SYN_RECV
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void receiveListen(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveListen(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
- log.debug("receiveListen");
+ if (DEBUG) {
+ log.debug("receiveListen");
+ }
final boolean ack = hdr.isFlagAcknowledgeSet();
final boolean syn = hdr.isFlagSynchronizeSet();
@@ -251,7 +256,7 @@
} else {
// Process the SYN request
final TCPControlBlock copy =
- (TCPControlBlock) copyAndConnect(dst, ipHdr.getSource(), hdr.getSrcPort());
+ (TCPControlBlock) copyAndConnect(dst, ipHdr.getSource(), hdr.getSrcPort());
copy.listenSynReceivedOnCopy(hdr, skbuf);
}
} else {
@@ -264,13 +269,15 @@
* Current state is 0, SYN segment received. This method is called on a copy
* of the listening control block. Send a SYN&ACK, and set the state to
* SYN_RECV
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void listenSynReceivedOnCopy(TCPHeader hdr, SocketBuffer skbuf)
+ private void listenSynReceivedOnCopy(TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
- log.debug("listenSynReceivedOnCopy");
+ if (DEBUG) {
+ log.debug("listenSynReceivedOnCopy");
+ }
// Save the foreign seq nr
inChannel.initISN(hdr);
@@ -285,7 +292,7 @@
/**
* Current state is SYN_RECV.
*/
- private final void receiveSynRecv(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveSynRecv(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean ack = hdr.isFlagAcknowledgeSet();
@@ -301,7 +308,7 @@
/**
* Current state is SYN_SEND.
*/
- private final void receiveSynSend(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveSynSend(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean syn = hdr.isFlagSynchronizeSet();
@@ -319,11 +326,11 @@
/**
* Current state is ESTABLISHED, FIN segment received. Send a ACK, and set
* the state to CLOSE_WAIT
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void receiveEstablished(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveEstablished(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean fin = hdr.isFlagFinishedSet();
// Process the data
@@ -336,11 +343,11 @@
/**
* State is FIN_WAIT_1, any segment received
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void receiveFinWait1(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveFinWait1(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean fin = hdr.isFlagFinishedSet();
final boolean ack = hdr.isFlagAcknowledgeSet();
@@ -361,11 +368,11 @@
/**
* State is FIN_WAIT_2, any segment received
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void receiveFinWait2(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveFinWait2(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean fin = hdr.isFlagFinishedSet();
// Process the data
@@ -401,11 +408,11 @@
/**
* State is LAST_ACK, any segment received
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void receiveLastAck(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveLastAck(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean ack = hdr.isFlagAcknowledgeSet();
if (ack) {
@@ -418,11 +425,11 @@
/**
* State is CLOSING, any segment received
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void receiveClosing(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveClosing(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
final boolean ack = hdr.isFlagAcknowledgeSet();
if (ack) {
@@ -435,11 +442,11 @@
/**
* State is TIME_WAIT, discard any segments
- *
+ *
* @param hdr
* @param skbuf
*/
- private final void receiveTimeWait(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
+ private void receiveTimeWait(IPv4Header ipHdr, TCPHeader hdr, SocketBuffer skbuf)
throws SocketException {
setState(TCPS_CLOSED);
drop(ipHdr, hdr, "discard all in TIME_WAIT state");
@@ -468,15 +475,18 @@
* Notify a segment drop to the debug log
*/
private void drop(IPv4Header ipHdr, TCPHeader hdr, String reason) {
- log.debug("Dropping segment due to: " + reason);
+ if (DEBUG) {
+ log.debug("Dropping segment due to: " + reason);
+ }
}
/**
* Send a ACK segment
*/
protected final void sendACK(int extraFlags, int ackNr) throws SocketException {
- log.debug("sendACK(0x" + NumberUtils.hex(extraFlags, 4) + ", " + (ackNr & 0xFFFFFFFFL) +
- ")");
+ if (DEBUG) {
+ log.debug("sendACK(0x" + NumberUtils.hex(extraFlags, 4) + ", " + (ackNr & 0xFFFFFFFFL) + ")");
+ }
// Create the FIN TCP reply
final TCPHeader replyHdr = createOutgoingTCPHeader(extraFlags | TCPF_ACK, ackNr);
@@ -492,12 +502,14 @@
/**
* Send a FIN segment
*/
- private final void sendFIN() throws SocketException {
- log.debug("sendFIN");
+ private void sendFIN() throws SocketException {
+ if (DEBUG) {
+ log.debug("sendFIN");
+ }
// Create the FIN TCP reply
final TCPHeader replyHdr =
- createOutgoingTCPHeader(TCPF_FIN | TCPF_ACK, inChannel.getRcvNext());
+ createOutgoingTCPHeader(TCPF_FIN | TCPF_ACK, inChannel.getRcvNext());
// Create the IP reply header
final IPv4Header replyIp = createOutgoingIPv4Header();
@@ -509,8 +521,10 @@
/**
* Send a RST segment
*/
- private final void sendRST() throws SocketException {
- log.debug("sendRST");
+ private void sendRST() throws SocketException {
+ if (DEBUG) {
+ log.debug("sendRST");
+ }
// Create the RST TCP reply
final TCPHeader replyHdr = createOutgoingTCPHeader(TCPF_RST, 0);
@@ -526,8 +540,10 @@
/**
* Send a SYN segment
*/
- private final void sendSYN() throws SocketException {
- log.debug("sendSYN");
+ private void sendSYN() throws SocketException {
+ if (DEBUG) {
+ log.debug("sendSYN");
+ }
// Create the SYN TCP
final TCPHeader hdr = createOutgoingTCPHeader(TCPF_SYN, 0);
@@ -542,7 +558,7 @@
/**
* Notify this listening parent that one of my children have established a
* connection.
- *
+ *
* @param child
*/
private synchronized void notifyChildEstablished(TCPControlBlock child) throws SocketException {
@@ -577,7 +593,7 @@
/**
* Is the current state equal to the given state?
- *
+ *
* @param state
* @return
*/
@@ -587,7 +603,7 @@
/**
* Update the state and notify any waiting threads
- *
+ *
* @param state
*/
private synchronized void setState(int state) throws SocketException {
@@ -625,13 +641,13 @@
/**
* Create a TCP header for outgoing trafic
- *
+ *
* @param options
* @return The created TCP header
*/
protected TCPHeader createOutgoingTCPHeader(int options, int ackNr) {
final TCPHeader hdr =
- new TCPHeader(getLocalPort(), getForeignPort(), 0, 0, ackNr, outWindowSize, 0);
+ new TCPHeader(getLocalPort(), getForeignPort(), 0, 0, ackNr, outWindowSize, 0);
hdr.setFlags(options);
return hdr;
}
@@ -642,7 +658,7 @@
/**
* Wait for incoming requests
- *
+ *
* @throws SocketException
*/
public synchronized void appListen() throws SocketException {
@@ -655,7 +671,7 @@
/**
* Active connect to a foreign address. This method blocks until the
* connection has been established.
- *
+ *
* @throws SocketException
*/
public synchronized void appConnect(IPv4Address fAddr, int fPort) throws SocketException {
@@ -675,7 +691,9 @@
if (isRefused()) {
throw new ConnectException("Connection refused");
}
- log.debug("Connected to " + fAddr + ":" + fPort);
+ if (DEBUG) {
+ log.debug("Connected to " + fAddr + ":" + fPort);
+ }
return;
} catch (TimeoutException ex) {
// Ignore and just try again
@@ -687,7 +705,7 @@
/**
* Wait for an established connection.
- *
+ *
* @return The accepted connection
*/
public synchronized TCPControlBlock appAccept() {
@@ -710,14 +728,16 @@
* Active close the connection by the application.
*/
public/* synchronized */void appClose() throws SocketException {
- if (log.isDebugEnabled()) {
- log.debug("active close state=" + getStateName());
+ if (DEBUG) {
+ if (log.isDebugEnabled()) {
+ log.debug("active close state=" + getStateName());
+ }
}
try {
switch (curState) {
case TCPS_SYN_RECV:
- case TCPS_ESTABLISHED:
+ case TCPS_ESTABLISHED:
sendFIN();
setState(TCPS_FIN_WAIT_1);
@@ -727,7 +747,7 @@
// waitUntilState(TCPS_CLOSED, 0);
break;
case TCPS_SYN_SENT:
- case TCPS_LISTEN:
+ case TCPS_LISTEN:
setState(TCPS_CLOSED);
break;
case TCPS_CLOSE_WAIT:
@@ -735,7 +755,7 @@
setState(TCPS_LAST_ACK);
waitUntilState(TCPS_CLOSED, 0);
break;
- case TCPS_CLOSED:
+ case TCPS_CLOSED:
// Ignore
break;
default:
@@ -753,14 +773,16 @@
* Send data to the foreign side. This method can split-up the data in
* chunks and blocks until there is space in the send buffer to hold the
* data.
- *
+ *
* @param data
* @param offset
* @param length
* @throws SocketException
*/
public void appSendData(byte[] data, int offset, int length) throws SocketException {
- log.debug("appSendData(data, " + offset + ", " + length + ")");
+ if (DEBUG) {
+ log.debug("appSendData(data, " + offset + ", " + length + ")");
+ }
if (!isState(TCPS_ESTABLISHED) && !isState(TCPS_CLOSE_WAIT)) {
throw new SocketException("Illegal state to send data: " + getStateName());
}
@@ -795,7 +817,7 @@
/**
* Read data from the input buffer up to len bytes long. Block until there
* is data available.
- *
+ *
* @param dst
* @param off
* @param len
@@ -828,7 +850,7 @@
/**
* Has this connection been reset
- *
+ *
* @return Returns the reset.
*/
public final boolean isReset() {
Modified: trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutChannel.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutChannel.java 2008-06-15 09:44:26 UTC (rev 4240)
+++ trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutChannel.java 2008-06-15 12:50:44 UTC (rev 4241)
@@ -18,13 +18,12 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.net.ipv4.tcp;
import java.net.SocketException;
import java.util.Iterator;
import java.util.LinkedList;
-
import org.apache.log4j.Logger;
import org.jnode.net.ipv4.IPv4Header;
@@ -32,6 +31,7 @@
* @author Ewout Prangsma (ep...@us...)
*/
public class TCPOutChannel {
+ private static final boolean DEBUG = false;
/**
* My logger
@@ -181,8 +181,10 @@
* @param length Must be smaller or equal to mss.
*/
public synchronized void send(IPv4Header ipHdr, TCPHeader hdr, byte[] data, int offset,
- int length) throws SocketException {
- log.debug("outChannel.send(ipHdr,hdr,data," + offset + ", " + length + ")");
+ int length) throws SocketException {
+ if (DEBUG) {
+ log.debug("outChannel.send(ipHdr,hdr,data," + offset + ", " + length + ")");
+ }
// Check for maximum datalength
if (length > mss) {
throw new IllegalArgumentException("dataLength must be <= mss");
@@ -213,7 +215,7 @@
* @param hdr
* @param dataOffset
*/
- private final void sendHelper(IPv4Header ipHdr, TCPHeader hdr, int dataOffset)
+ private void sendHelper(IPv4Header ipHdr, TCPHeader hdr, int dataOffset)
throws SocketException {
// Adjust the sequence numbers
hdr.setSequenceNr(snd_next);
@@ -226,10 +228,12 @@
snd_max = snd_next;
// Create & send the segment
final TCPOutSegment seg =
- new TCPOutSegment(ipHdr, hdr, dataBuffer, dataOffset, timeoutTicks);
+ new TCPOutSegment(ipHdr, hdr, dataBuffer, dataOffset, timeoutTicks);
seg.send(tcp);
if (!seg.isAckOnly() && !hdr.isFlagSynchronizeSet()) {
- log.debug("Adding segment " + seg.getSeqNr() + " to unacklist");
+ if (DEBUG) {
+ log.debug("Adding segment " + seg.getSeqNr() + " to unacklist");
+ }
unackedSegments.add(seg);
}
}
Modified: trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutSegment.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutSegment.java 2008-06-15 09:44:26 UTC (rev 4240)
+++ trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPOutSegment.java 2008-06-15 12:50:44 UTC (rev 4241)
@@ -18,12 +18,11 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.net.ipv4.tcp;
import java.net.SocketException;
-
import org.apache.log4j.Logger;
import org.jnode.net.SocketBuffer;
import org.jnode.net.ipv4.IPv4Header;
@@ -32,17 +31,24 @@
* @author Ewout Prangsma (ep...@us...)
*/
public class TCPOutSegment extends TCPSegment {
+ private static final boolean DEBUG = false;
- /** My logger */
+ /**
+ * My logger
+ */
private static final Logger log = Logger.getLogger(TCPOutSegment.class);
-
+
private final TCPDataBuffer buffer;
private int dataOffset;
-
- /** Timeout counter, if 0, re-transmit */
+
+ /**
+ * Timeout counter, if 0, re-transmit
+ */
private int timeout;
-
- /** Number of timeout ticks (usually grows) */
+
+ /**
+ * Number of timeout ticks (usually grows)
+ */
private int timeoutTicks;
/**
@@ -51,7 +57,7 @@
* @param dataOffset
*/
public TCPOutSegment(IPv4Header ipHdr, TCPHeader hdr, TCPDataBuffer buffer, int dataOffset,
- int timeout) {
+ int timeout) {
super(ipHdr, hdr);
this.buffer = buffer;
this.dataOffset = dataOffset;
@@ -65,7 +71,9 @@
public void timeout(TCPProtocol tcp) throws SocketException {
timeout--;
if (timeout == 0) {
- log.debug("Resend segment " + getSeqNr());
+ if (DEBUG) {
+ log.debug("Resend segment " + getSeqNr());
+ }
send(tcp);
timeoutTicks = timeoutTicks * 2;
timeout = timeoutTicks;
@@ -74,7 +82,7 @@
/**
* Send this segment
- *
+ *
* @param tcp
*/
public void send(TCPProtocol tcp) throws SocketException {
@@ -102,6 +110,7 @@
/**
* Does this segment only contain an ACK?
+ *
* @return True if this segment contains only an acknowledgment, false otherwise
*/
public boolean isAckOnly() {
Modified: trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPProtocol.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPProtocol.java 2008-06-15 09:44:26 UTC (rev 4240)
+++ trunk/net/src/net/org/jnode/net/ipv4/tcp/TCPProtocol.java 2008-06-15 12:50:44 UTC (rev 4241)
@@ -18,7 +18,7 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package org.jnode.net.ipv4.tcp;
import java.io.IOException;
@@ -31,7 +31,6 @@
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
-
import org.apache.log4j.Logger;
import org.jnode.driver.net.NetworkException;
import org.jnode.net.SocketBuffer;
@@ -46,31 +45,44 @@
* @author epr
*/
public class TCPProtocol implements IPv4Protocol, IPv4Constants, TCPConstants {
+ private static final boolean DEBUG = false;
- /** The IP service I'm a part of */
+ /**
+ * The IP service I'm a part of
+ */
private final IPv4Service ipService;
/** The ICMP service */
// private final ICMPUtils icmp;
-
- /** My statistics */
+
+ /**
+ * My statistics
+ */
private final TCPStatistics stat = new TCPStatistics();
- /** The SocketImpl factory for TCP */
+ /**
+ * The SocketImpl factory for TCP
+ */
private final TCPSocketImplFactory socketImplFactory;
- /** My control blocks */
+ /**
+ * My control blocks
+ */
private final TCPControlBlockList controlBlocks;
- /** The timer */
+ /**
+ * The timer
+ */
private final TCPTimer timer;
- /** My logger */
+ /**
+ * My logger
+ */
private static final Logger log = Logger.getLogger(TCPProtocol.class);
/**
* Initialize a new instance
- *
+ *
* @param ipService
*/
public TCPProtocol(IPv4Service ipService) throws NetworkException {
@@ -156,19 +168,23 @@
skbuf.trim(hdr.getDataLength());
if (!hdr.isChecksumOk()) {
- if (log.isDebugEnabled()) {
- log.debug("Receive: badsum: " + hdr);
+ if (DEBUG) {
+ if (log.isDebugEnabled()) {
+ log.debug("Receive: badsum: " + hdr);
+ }
}
stat.badsum.inc();
} else {
- if (log.isDebugEnabled()) {
- log.debug("Receive: " + hdr);
+ if (DEBUG) {
+ if (log.isDebugEnabled()) {
+ log.debug("Receive: " + hdr);
+ }
}
// Find the corresponding control block
final TCPControlBlock cb =
- (TCPControlBlock) controlBlocks.lookup(ipHdr.getSource(), hdr.getSrcPort(),
- ipHdr.getDestination(), hdr.getDstPort(), true);
+ (TCPControlBlock) controlBlocks.lookup(ipHdr.getSource(), hdr.getSrcPort(),
+ ipHdr.getDestination(), hdr.getDstPort(), true);
if (cb == null) {
final boolean ack = hdr.isFlagAcknowledgeSet();
final boolean rst = hdr.isFlagResetSet();
@@ -178,8 +194,7 @@
// Port unreachable
if (ack && rst) {
// the source is also unreachable
- log
- .debug("Dropping segment due to: connection refused as the source is also unreachable");
+ log.debug("Dropping segment due to: connection refused as the source is also unreachable");
} else {
processPortUnreachable(ipHdr, hdr);
}
@@ -200,13 +215,13 @@
/**
* Process a segment whose destination port is unreachable
- *
+ *
* @param hdr
*/
private void processPortUnreachable(IPv4Header ipHdr, TCPHeader hdr) throws SocketException {
final TCPHeader replyHdr =
- new TCPHeader(hdr.getDstPort(), hdr.getSrcPort(), 0, 0, hdr.getSequenceNr() + 1, 0,
- 0);
+ new TCPHeader(hdr.getDstPort(), hdr.getSrcPort(), 0, 0, hdr.getSequenceNr() + 1, 0,
+ 0);
replyHdr.setFlags(TCPF_ACK | TCPF_RST);
final IPv4Header replyIpHdr = new IPv4Header(ipHdr);
replyIpHdr.swapAddresses();
@@ -215,7 +230,7 @@
/**
* Create a binding for a local address
- *
+ *
* @param lAddr
* @param lPort
*/
@@ -225,13 +240,15 @@
/**
* Send an TCP packet
- *
+ *
* @param skbuf
*/
protected void send(IPv4Header ipHdr, TCPHeader tcpHdr, SocketBuffer skbuf)
throws SocketException {
- if (log.isDebugEnabled()) {
- log.debug("send(ipHdr, " + tcpHdr + ")");
+ if (DEBUG) {
+ if (log.isDebugEnabled()) {
+ log.debug("send(ipHdr, " + tcpHdr + ")");
+ }
}
skbuf.setTransportLayerHeader(tcpHdr);
tcpHdr.prefixTo(skbuf);
Modif...
[truncated message content] |