|
From: <hag...@us...> - 2007-01-10 14:00:38
|
Revision: 3063
http://jnode.svn.sourceforge.net/jnode/?rev=3063&view=rev
Author: hagar-wize
Date: 2007-01-10 06:00:35 -0800 (Wed, 10 Jan 2007)
Log Message:
-----------
updated to dnsjava 2.0.3
Modified Paths:
--------------
trunk/net/descriptors/org.xbill.dns.xml
Added Paths:
-----------
trunk/net/lib/dnsjava-2.0.3.jar
Removed Paths:
-------------
trunk/net/lib/dnsjava-1.5.0.jar
trunk/net/lib/dnsjava-2.0.1a.jar
Modified: trunk/net/descriptors/org.xbill.dns.xml
===================================================================
--- trunk/net/descriptors/org.xbill.dns.xml 2007-01-09 20:25:48 UTC (rev 3062)
+++ trunk/net/descriptors/org.xbill.dns.xml 2007-01-10 14:00:35 UTC (rev 3063)
@@ -3,7 +3,7 @@
<plugin id="org.xbill.dns"
name="DNSJava"
- version="1.5.0"
+ version="2.0.3"
provider-name="XBill.org"
provider-url="http://www.dnsjava.org"
license-name="BSD like"
@@ -11,7 +11,7 @@
<runtime>
- <library name="dnsjava-1.5.0.jar">
+ <library name="dnsjava-2.0.3.jar">
<export name="*"/>
</library>
</runtime>
Deleted: trunk/net/lib/dnsjava-1.5.0.jar
===================================================================
(Binary files differ)
Deleted: trunk/net/lib/dnsjava-2.0.1a.jar
===================================================================
(Binary files differ)
Added: trunk/net/lib/dnsjava-2.0.3.jar
===================================================================
(Binary files differ)
Property changes on: trunk/net/lib/dnsjava-2.0.3.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-05-09 13:14:37
|
Revision: 4074
http://jnode.svn.sourceforge.net/jnode/?rev=4074&view=rev
Author: crawley
Date: 2008-05-09 06:14:24 -0700 (Fri, 09 May 2008)
Log Message:
-----------
Converted ArpCommand
Modified Paths:
--------------
trunk/net/descriptors/org.jnode.net.command.xml
trunk/net/src/net/org/jnode/net/command/ArpCommand.java
Modified: trunk/net/descriptors/org.jnode.net.command.xml
===================================================================
--- trunk/net/descriptors/org.jnode.net.command.xml 2008-05-09 12:42:23 UTC (rev 4073)
+++ trunk/net/descriptors/org.jnode.net.command.xml 2008-05-09 13:14:24 UTC (rev 4074)
@@ -38,7 +38,14 @@
<alias name="net" class="org.jnode.net.command.NetCommand"/>
<alias name="rpcinfo" class="org.jnode.net.command.RpcInfoCommand"/>
</extension>
-
+
+ <extension point="org.jnode.shell.syntaxes">
+ <syntax alias="arp">
+ <empty description="List the ARP cache"/>
+ <option argLabel="clear" shortName="c" longName="clear" description="Clear the ARP cache"/>
+ </syntax>
+ </extension>
+
<extension point="org.jnode.security.permissions">
<permission class="java.net.SocketPermission" name="*" actions="connect,resolve"/>
<permission class="java.net.SocketPermission" name="*:1024-" actions="listen,accept"/>
Modified: trunk/net/src/net/org/jnode/net/command/ArpCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/ArpCommand.java 2008-05-09 12:42:23 UTC (rev 4073)
+++ trunk/net/src/net/org/jnode/net/command/ArpCommand.java 2008-05-09 13:14:24 UTC (rev 4074)
@@ -24,29 +24,29 @@
import java.io.InputStream;
import java.io.PrintStream;
+import org.jnode.driver.net.NetworkException;
+import org.jnode.net.NoSuchProtocolException;
import org.jnode.net.arp.ARPCacheEntry;
import org.jnode.net.arp.ARPNetworkLayer;
import org.jnode.net.ethernet.EthernetConstants;
import org.jnode.net.util.NetUtils;
-import org.jnode.shell.AbstractCommand;
+import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.Syntax;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.FlagArgument;
/**
* @author epr
*/
public class ArpCommand extends AbstractCommand {
- static final Parameter PARAM_DELETE = new Parameter("d", "delete the ARP cache", Parameter.MANDATORY);
+ private final FlagArgument FLAG_CLEAR =
+ new FlagArgument("clear", Argument.OPTIONAL, "if set, clear the ARP cache");
- public static Help.Info HELP_INFO = new Help.Info("arp",
- new Syntax[] {
- new Syntax("Print ARP cache"),
- new Syntax("Clear ARP cache", new Parameter[] { PARAM_DELETE })
- });
+ public ArpCommand() {
+ super("print or clear the ARP cache");
+ registerArguments(FLAG_CLEAR);
+ }
/**
* Execute this command
@@ -55,16 +55,17 @@
new ArpCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception {
- ParsedArguments cmdLine = HELP_INFO.parse(commandLine);
-
+ public void execute(CommandLine commandLine, InputStream in,
+ PrintStream out, PrintStream err) throws NoSuchProtocolException, NetworkException {
+
ARPNetworkLayer arp = (ARPNetworkLayer) NetUtils.getNLM().getNetworkLayer(EthernetConstants.ETH_P_ARP);
- if (PARAM_DELETE.isSet(cmdLine)) {
+ if (FLAG_CLEAR.isSet()) {
arp.getCache().clear();
- System.out.println("Cleared the ARP cache");
- } else {
+ out.println("Cleared the ARP cache");
+ }
+ else {
for (ARPCacheEntry entry : arp.getCache().entries()) {
- System.out.println(entry);
+ out.println(entry);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-05-09 13:45:35
|
Revision: 4075
http://jnode.svn.sourceforge.net/jnode/?rev=4075&view=rev
Author: crawley
Date: 2008-05-09 06:45:11 -0700 (Fri, 09 May 2008)
Log Message:
-----------
Converted BootpCommand
Modified Paths:
--------------
trunk/net/descriptors/org.jnode.net.command.xml
trunk/net/src/net/org/jnode/net/command/BootpCommand.java
Modified: trunk/net/descriptors/org.jnode.net.command.xml
===================================================================
--- trunk/net/descriptors/org.jnode.net.command.xml 2008-05-09 13:14:24 UTC (rev 4074)
+++ trunk/net/descriptors/org.jnode.net.command.xml 2008-05-09 13:45:11 UTC (rev 4075)
@@ -44,6 +44,9 @@
<empty description="List the ARP cache"/>
<option argLabel="clear" shortName="c" longName="clear" description="Clear the ARP cache"/>
</syntax>
+ <syntax alias="bootp">
+ <argument argLabel="device" description="Configure a network interface using BOOTP"/>
+ </syntax>
</extension>
<extension point="org.jnode.security.permissions">
Modified: trunk/net/src/net/org/jnode/net/command/BootpCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/BootpCommand.java 2008-05-09 13:14:24 UTC (rev 4074)
+++ trunk/net/src/net/org/jnode/net/command/BootpCommand.java 2008-05-09 13:45:11 UTC (rev 4075)
@@ -24,45 +24,42 @@
import java.io.InputStream;
import java.io.PrintStream;
+import javax.naming.NameNotFoundException;
+
import org.jnode.driver.Device;
import org.jnode.driver.net.NetDeviceAPI;
+import org.jnode.driver.net.NetworkException;
import org.jnode.naming.InitialNaming;
import org.jnode.net.ipv4.config.IPv4ConfigurationService;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.argument.DeviceArgument;
+import org.jnode.shell.syntax.*;
/**
* @author epr
*/
public class BootpCommand extends AbstractCommand {
- static final DeviceArgument ARG_DEVICE = new DeviceArgument("device", "the device to boot from", NetDeviceAPI.class);
+ private final DeviceArgument ARG_DEVICE =
+ new DeviceArgument("device", Argument.MANDATORY,
+ "", NetDeviceAPI.class);
- public static Help.Info HELP_INFO = new Help.Info(
- "bootp",
- "Try to configure the given device using BOOTP",
- new Parameter[]{
- new Parameter(ARG_DEVICE, Parameter.MANDATORY)
- }
- );
+ public BootpCommand() {
+ super("Configure a network interface using BOOTP");
+ registerArguments(ARG_DEVICE);
+ }
- public static void main(String[] args)
- throws Exception {
+ public static void main(String[] args) throws Exception {
new BootpCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception {
- ParsedArguments cmdLine = HELP_INFO.parse(commandLine);
-
- final Device dev = ARG_DEVICE.getDevice(cmdLine);
- System.out.println("Trying to configure " + dev.getId() + "...");
- final IPv4ConfigurationService cfg = (IPv4ConfigurationService)InitialNaming.lookup(IPv4ConfigurationService.NAME);
+ public void execute(CommandLine commandLine, InputStream in,
+ PrintStream out, PrintStream err) throws NameNotFoundException, NetworkException {
+ final Device dev = ARG_DEVICE.getValue();
+ out.println("Trying to configure " + dev.getId() + "...");
+ final IPv4ConfigurationService cfg =
+ (IPv4ConfigurationService) InitialNaming.lookup(IPv4ConfigurationService.NAME);
cfg.configureDeviceBootp(dev, true);
-
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-05-10 03:42:30
|
Revision: 4077
http://jnode.svn.sourceforge.net/jnode/?rev=4077&view=rev
Author: crawley
Date: 2008-05-09 20:42:29 -0700 (Fri, 09 May 2008)
Log Message:
-----------
Converted DhcpCommand
Modified Paths:
--------------
trunk/net/descriptors/org.jnode.net.command.xml
trunk/net/src/net/org/jnode/net/command/DhcpCommand.java
Modified: trunk/net/descriptors/org.jnode.net.command.xml
===================================================================
--- trunk/net/descriptors/org.jnode.net.command.xml 2008-05-09 14:37:39 UTC (rev 4076)
+++ trunk/net/descriptors/org.jnode.net.command.xml 2008-05-10 03:42:29 UTC (rev 4077)
@@ -47,6 +47,9 @@
<syntax alias="bootp">
<argument argLabel="device" description="Configure a network interface using BOOTP"/>
</syntax>
+ <syntax alias="dhcp">
+ <argument argLabel="device" description="Configure a network interface using DHCP"/>
+ </syntax>
</extension>
<extension point="org.jnode.security.permissions">
Modified: trunk/net/src/net/org/jnode/net/command/DhcpCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/DhcpCommand.java 2008-05-09 14:37:39 UTC (rev 4076)
+++ trunk/net/src/net/org/jnode/net/command/DhcpCommand.java 2008-05-10 03:42:29 UTC (rev 4077)
@@ -24,71 +24,68 @@
import java.io.InputStream;
import java.io.PrintStream;
import java.net.InetAddress;
-import java.net.NoRouteToHostException;
+import java.net.UnknownHostException;
import javax.naming.NameNotFoundException;
+import org.jnode.driver.ApiNotFoundException;
import org.jnode.driver.Device;
import org.jnode.driver.DeviceManager;
import org.jnode.driver.DeviceNotFoundException;
import org.jnode.driver.net.NetDeviceAPI;
+import org.jnode.driver.net.NetworkException;
import org.jnode.naming.InitialNaming;
import org.jnode.net.ProtocolAddressInfo;
import org.jnode.net.ethernet.EthernetConstants;
-import org.jnode.net.ipv4.IPv4Address;
-import org.jnode.net.ipv4.IPv4RoutingTable;
import org.jnode.net.ipv4.config.IPv4ConfigurationService;
-import org.jnode.net.ipv4.layer.IPv4NetworkLayer;
-import org.jnode.net.util.NetUtils;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.SyntaxErrorException;
-import org.jnode.shell.help.argument.DeviceArgument;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.DeviceArgument;
/**
* @author markhale
+ * @author cr...@jn...
*/
public class DhcpCommand extends AbstractCommand {
- static final DeviceArgument ARG_DEVICE = new DeviceArgument("device", "the device to boot from", NetDeviceAPI.class);
+ private final DeviceArgument ARG_DEVICE =
+ new DeviceArgument("device", Argument.MANDATORY,
+ "the network interface device to be configured", NetDeviceAPI.class);
- public static Help.Info HELP_INFO = new Help.Info(
- "dhcp",
- "Try to configure the given device using DHCP",
- new Parameter[]{
- new Parameter(ARG_DEVICE, Parameter.MANDATORY)
- }
- );
+ public DhcpCommand() {
+ super("Configure a network interface using DHCP");
+ registerArguments(ARG_DEVICE);
+ }
- public static void main(String[] args)
- throws Exception {
- new DhcpCommand().execute(args);
- }
+ public static void main(String[] args) throws Exception {
+ new DhcpCommand().execute(args);
+ }
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception {
- ParsedArguments cmdLine = HELP_INFO.parse(commandLine);
+ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ throws DeviceNotFoundException, NameNotFoundException, ApiNotFoundException,
+ UnknownHostException, NetworkException
+ {
+ final Device dev = ARG_DEVICE.getValue();
- final Device dev = ARG_DEVICE.getDevice(cmdLine);
-
- // The DHCP network configuration process will attempt to configure the DNS. This will only work if
- // the IP address 127.0.0.1 is bound to the loopback network interface. And if there isn't the network
- // is left in a state that will require a reboot to unjam. Check that we have bound it ...
- Device loopback = ((DeviceManager)InitialNaming.lookup(DeviceManager.NAME)).getDevice("loopback");
- NetDeviceAPI api = (NetDeviceAPI)loopback.getAPI(NetDeviceAPI.class);
- ProtocolAddressInfo info = api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP);
- if (info == null || !info.contains(InetAddress.getByAddress(new byte[]{127, 0, 0, 1}))) {
- System.err.println("The loopback network device is not bound to IP address 127.0.0.1");
- System.err.println("Run 'ifconfig loopback 127.0.0.1 255.255.255.255' to fix this.");
- exit(1);
- }
-
- // Now it should be safe to do the DHCP configuration ...
- System.out.println("Trying to configure " + dev.getId() + "...");
- final IPv4ConfigurationService cfg = (IPv4ConfigurationService)InitialNaming.lookup(IPv4ConfigurationService.NAME);
- cfg.configureDeviceDhcp(dev, true);
- }
+ // The DHCP network configuration process will attempt to configure the DNS. This will only work if
+ // the IP address 127.0.0.1 is bound to the loopback network interface. And if there isn't, JNode's
+ // network layer is left in a state that will require a reboot to unjam it (AFAIK).
+ //
+ // So, check that loopback is correctly bound ...
+ Device loopback = ((DeviceManager) InitialNaming.lookup(DeviceManager.NAME)).getDevice("loopback");
+ NetDeviceAPI api = (NetDeviceAPI) loopback.getAPI(NetDeviceAPI.class);
+ ProtocolAddressInfo info = api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP);
+ if (info == null || !info.contains(InetAddress.getByAddress(new byte[]{127, 0, 0, 1}))) {
+ err.println("The loopback network device is not bound to IP address 127.0.0.1");
+ err.println("Run 'ifconfig loopback 127.0.0.1 255.255.255.255' to fix this.");
+ exit(1);
+ }
+ // Now it should be safe to do the DHCP configuration.
+ out.println("Configuring network device " + dev.getId() + "...");
+ final IPv4ConfigurationService cfg =
+ (IPv4ConfigurationService) InitialNaming.lookup(IPv4ConfigurationService.NAME);
+ cfg.configureDeviceDhcp(dev, true);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-05-10 14:17:24
|
Revision: 4079
http://jnode.svn.sourceforge.net/jnode/?rev=4079&view=rev
Author: crawley
Date: 2008-05-10 07:17:22 -0700 (Sat, 10 May 2008)
Log Message:
-----------
Implemented an IPv4 Argument class. Converted IfconfigCommand.
Modified Paths:
--------------
trunk/net/descriptors/org.jnode.net.command.xml
trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java
Added Paths:
-----------
trunk/net/src/net/org/jnode/net/syntax/
trunk/net/src/net/org/jnode/net/syntax/IPv4AddressArgument.java
Modified: trunk/net/descriptors/org.jnode.net.command.xml
===================================================================
--- trunk/net/descriptors/org.jnode.net.command.xml 2008-05-10 14:15:48 UTC (rev 4078)
+++ trunk/net/descriptors/org.jnode.net.command.xml 2008-05-10 14:17:22 UTC (rev 4079)
@@ -20,6 +20,7 @@
<library name="jnode-net.jar">
<export name="org.jnode.net.command.*"/>
<export name="org.jnode.net.help.argument.*"/>
+ <export name="org.jnode.net.syntax.*"/>
</library>
</runtime>
@@ -50,6 +51,15 @@
<syntax alias="dhcp">
<argument argLabel="device" description="Configure a network interface using DHCP"/>
</syntax>
+ <syntax alias="ifconfig">
+ <empty description="Print network addresses for all network devices"/>
+ <argument argLabel="device" description="Print network addresses for a given device"/>
+ <sequence description="Bind a given device to an IPv4 address">
+ <argument argLabel="device"/>
+ <argument argLabel="ipAddress"/>
+ <optional><argument argLabel="subnetMask"/></optional>
+ </sequence>
+ </syntax>
</extension>
<extension point="org.jnode.security.permissions">
Modified: trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java 2008-05-10 14:15:48 UTC (rev 4078)
+++ trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java 2008-05-10 14:17:22 UTC (rev 4079)
@@ -24,83 +24,85 @@
import java.io.InputStream;
import java.io.PrintStream;
+import javax.naming.NameNotFoundException;
+
+import org.jnode.driver.ApiNotFoundException;
import org.jnode.driver.Device;
import org.jnode.driver.DeviceManager;
import org.jnode.driver.net.NetDeviceAPI;
+import org.jnode.driver.net.NetworkException;
import org.jnode.naming.InitialNaming;
import org.jnode.net.ethernet.EthernetConstants;
-import org.jnode.net.help.argument.HostArgument;
import org.jnode.net.ipv4.IPv4Address;
import org.jnode.net.ipv4.config.IPv4ConfigurationService;
+import org.jnode.net.syntax.IPv4AddressArgument;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.Syntax;
-import org.jnode.shell.help.argument.DeviceArgument;
+import org.jnode.shell.syntax.*;
/**
+ * This command class binds IP addresses to network devices, and displays bindings.
+ *
* @author epr
+ * @author cr...@jn...
*/
public class IfconfigCommand extends AbstractCommand {
+ // FIXME should support IPv6 and other address families.
- static final DeviceArgument ARG_DEVICE = new DeviceArgument("device", "the device", NetDeviceAPI.class);
- static final HostArgument ARG_IP_ADDRESS = new HostArgument("ip-address", "the IP address to bind the device to");
- static final HostArgument ARG_SUBNET_MASK = new HostArgument("subnet-mask", "if given, specifies the range of reachable subnets");
+ private final DeviceArgument ARG_DEVICE =
+ new DeviceArgument("device", Argument.OPTIONAL, "the device", NetDeviceAPI.class);
+
+ private final IPv4AddressArgument ARG_IP_ADDRESS =
+ new IPv4AddressArgument("ipAddress", Argument.OPTIONAL, "the IPv4 address to bind the device to");
+
+ private final IPv4AddressArgument ARG_SUBNET_MASK =
+ new IPv4AddressArgument("subnetMask", Argument.OPTIONAL, "the IPv4 subnet mask for the device");
- public static Help.Info HELP_INFO = new Help.Info(
- "ifconfig", new Syntax[]{
- new Syntax("Print status of all network devices"),
- new Syntax("Print status of a single network device",
- new Parameter[]{
- new Parameter(ARG_DEVICE, Parameter.MANDATORY),
- }
- ),
- new Syntax("Bind a device to an IP address",
- new Parameter[]{
- new Parameter(ARG_DEVICE, Parameter.MANDATORY),
- new Parameter(ARG_IP_ADDRESS, Parameter.MANDATORY),
- new Parameter(ARG_SUBNET_MASK, Parameter.OPTIONAL)
- }
- )
- }
- );
+
+ public IfconfigCommand() {
+ super("List or manage network interface bindings");
+ registerArguments(ARG_DEVICE, ARG_IP_ADDRESS, ARG_SUBNET_MASK);
+ }
- public static void main(String[] args)
- throws Exception {
+ public static void main(String[] args) throws Exception {
new IfconfigCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception {
- ParsedArguments cmdLine = HELP_INFO.parse(commandLine);
-
- if( cmdLine.size() == 0 ) {
- final DeviceManager dm = (DeviceManager)InitialNaming.lookup(DeviceManager.NAME);
+ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ throws NameNotFoundException, ApiNotFoundException, NetworkException {
+ if (!ARG_DEVICE.isSet()) {
+ // Print MAC address, MTU and IP address(es) for all network devices.
+ final DeviceManager dm = (DeviceManager) InitialNaming.lookup(DeviceManager.NAME);
for (Device dev : dm.getDevicesByAPI(NetDeviceAPI.class)) {
- final NetDeviceAPI api = (NetDeviceAPI)dev.getAPI(NetDeviceAPI.class);
- System.out.println(dev.getId() + ": MAC-Address " + api.getAddress() + " MTU " + api.getMTU());
- System.out.println(" " + api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP));
- System.out.println();
+ final NetDeviceAPI api = (NetDeviceAPI) dev.getAPI(NetDeviceAPI.class);
+ out.println(dev.getId() + ": MAC-Address " + api.getAddress() + " MTU " + api.getMTU());
+ out.println(" " + api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP));
}
- } else {
+ }
+ else {
+ final Device dev = ARG_DEVICE.getValue();
+ final NetDeviceAPI api = (NetDeviceAPI) dev.getAPI(NetDeviceAPI.class);
- Device dev = ARG_DEVICE.getDevice(cmdLine);
- NetDeviceAPI api = (NetDeviceAPI)dev.getAPI(NetDeviceAPI.class);
-
- if( cmdLine.size() == 1 ) {
- // Print address
- System.out.println("IP address(es) for " + dev.getId() + " " + api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP));
- } else {
- // Set IP address
- IPv4Address ip = ARG_IP_ADDRESS.getAddress(cmdLine);
- IPv4Address mask = ARG_SUBNET_MASK.getAddress(cmdLine);
- final IPv4ConfigurationService cfg = (IPv4ConfigurationService)InitialNaming.lookup(IPv4ConfigurationService.NAME);
+ if (!ARG_IP_ADDRESS.isSet()) {
+ // Print IP address(es) for device
+ out.println("IP address(es) for " + dev.getId() +
+ " " + api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP));
+ }
+ else {
+ // Set IP address for device
+ final IPv4Address ip = ARG_IP_ADDRESS.getValue();
+ final IPv4Address mask = ARG_SUBNET_MASK.getValue();
+ final IPv4ConfigurationService cfg = (IPv4ConfigurationService)
+ InitialNaming.lookup(IPv4ConfigurationService.NAME);
cfg.configureDeviceStatic(dev, ip, mask, true);
- System.out.println("IP address for " + dev.getId() + " set to " + api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP));
+
+ // FIXME ... this doesn't show the device's new address because the
+ // IPv4 ConfigurationServiceImpl calls processor.apply with the
+ // waitUntilReady parameter == false. (The comment in the code
+ // talks about avoiding deadlocks.)
+ out.println("IP address for " + dev.getId() + " set to " +
+ api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP));
}
}
- System.out.println();
}
-
}
Added: trunk/net/src/net/org/jnode/net/syntax/IPv4AddressArgument.java
===================================================================
--- trunk/net/src/net/org/jnode/net/syntax/IPv4AddressArgument.java (rev 0)
+++ trunk/net/src/net/org/jnode/net/syntax/IPv4AddressArgument.java 2008-05-10 14:17:22 UTC (rev 4079)
@@ -0,0 +1,63 @@
+package org.jnode.net.syntax;
+
+import java.net.InetAddress;
+import java.util.StringTokenizer;
+
+import org.jnode.driver.console.CompletionInfo;
+import org.jnode.net.ipv4.IPv4Address;
+
+import org.jnode.shell.CommandLine.Token;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.CommandSyntaxException;
+
+/**
+ * This Argument class accepts 4-part IPv4 addresses. It validates the address,
+ * but does no completion.
+ *
+ * @author cr...@jn...
+ */
+public class IPv4AddressArgument extends Argument<IPv4Address> {
+
+ public IPv4AddressArgument(String label, int flags,
+ String description) {
+ super(label, flags, new IPv4Address[0], description);
+ }
+
+ @Override
+ protected String argumentKind() {
+ return "IPv4 address";
+ }
+
+ @Override
+ protected IPv4Address doAccept(Token value) throws CommandSyntaxException {
+ final StringTokenizer tok = new StringTokenizer(value.token, ".");
+ if (tok.countTokens() != 4) {
+ throw new CommandSyntaxException("Wrong number of components for an IPv4 address");
+ }
+ try {
+ final byte b1 = parseUnsignedByte(tok.nextToken());
+ final byte b2 = parseUnsignedByte(tok.nextToken());
+ final byte b3 = parseUnsignedByte(tok.nextToken());
+ final byte b4 = parseUnsignedByte(tok.nextToken());
+ return new IPv4Address(new byte[]{b1, b2, b3, b4}, 0);
+ } catch (NumberFormatException ex) {
+ throw new CommandSyntaxException("Invalid component in IPv4 address");
+ }
+ }
+
+ /**
+ * Parse a number and check it is in the range 0 to 255.
+ *
+ * @param str
+ * @throws NumberFormatException if 'str' is not a number or if it is out of range
+ * @return the number cast as a byte.
+ */
+ private byte parseUnsignedByte(String str) {
+ final int v = Integer.parseInt(str);
+ if ((v >= 0) && (v < 256)) {
+ return (byte) v;
+ } else {
+ throw new NumberFormatException(str);
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-05-11 09:16:49
|
Revision: 4083
http://jnode.svn.sourceforge.net/jnode/?rev=4083&view=rev
Author: crawley
Date: 2008-05-11 02:16:47 -0700 (Sun, 11 May 2008)
Log Message:
-----------
Renamed / converted TcpInoutCommand
Modified Paths:
--------------
trunk/net/descriptors/org.jnode.net.command.xml
Added Paths:
-----------
trunk/net/src/net/org/jnode/net/command/TcpInoutCommand.java
Removed Paths:
-------------
trunk/net/src/net/org/jnode/net/command/NetCommand.java
Modified: trunk/net/descriptors/org.jnode.net.command.xml
===================================================================
--- trunk/net/descriptors/org.jnode.net.command.xml 2008-05-11 03:00:18 UTC (rev 4082)
+++ trunk/net/descriptors/org.jnode.net.command.xml 2008-05-11 09:16:47 UTC (rev 4083)
@@ -36,7 +36,7 @@
<alias name="resolve" class="org.jnode.net.command.ResolveCommand"/>
<alias name="tftp" class="org.jnode.net.command.TftpCommand"/>
<alias name="wlanctl" class="org.jnode.net.command.WLanCtlCommand"/>
- <alias name="net" class="org.jnode.net.command.NetCommand"/>
+ <alias name="tcpinout" class="org.jnode.net.command.TcpInoutCommand"/>
<alias name="rpcinfo" class="org.jnode.net.command.RpcInfoCommand"/>
</extension>
@@ -60,6 +60,13 @@
<optional><argument argLabel="subnetMask"/></optional>
</sequence>
</syntax>
+ <syntax alias="tcpinout">
+ <argument argLabel="localPort" description="Run tcpinout in server mode"/>
+ <sequence description="Run tcpinout in client mode">
+ <argument argLabel="host"/>
+ <argument argLabel="port"/>
+ </sequence>
+ </syntax>
</extension>
<extension point="org.jnode.security.permissions">
Deleted: trunk/net/src/net/org/jnode/net/command/NetCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/NetCommand.java 2008-05-11 03:00:18 UTC (rev 4082)
+++ trunk/net/src/net/org/jnode/net/command/NetCommand.java 2008-05-11 09:16:47 UTC (rev 4083)
@@ -1,140 +0,0 @@
-package org.jnode.net.command;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.net.InetAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-import javax.net.ServerSocketFactory;
-import javax.net.SocketFactory;
-
-import org.jnode.shell.AbstractCommand;
-import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.Syntax;
-import org.jnode.shell.help.argument.InetAddressArgument;
-import org.jnode.shell.help.argument.IntegerArgument;
-
-public class NetCommand extends AbstractCommand {
-
- private static final InetAddressArgument ARG_HOST = new InetAddressArgument(
- "ip-address", "the IP-address of the server to contact");
-
- private static final IntegerArgument ARG_PORT = new IntegerArgument("port",
- "the port the server is listening to");
-
- private static final IntegerArgument ARG_LISTENPORT = new IntegerArgument(
- "port", "the Port the server should listen to");
-
- private static final Parameter PARAM_LISTEN = new Parameter(ARG_LISTENPORT);
-
- public static Help.Info HELP_INFO = new Help.Info("tcp", new Syntax(
- "Connect to a remote server", new Parameter(ARG_HOST),
- new Parameter(ARG_PORT)), new Syntax("Listens to a specified port",
- PARAM_LISTEN));
-
- /**
- * @param args
- */
- public static void main(String[] args) throws Exception {
- new NetCommand().execute(args);
- }
-
-
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception {
- ParsedArguments args = HELP_INFO.parse(commandLine);
-
- Socket socket = null;
- if (PARAM_LISTEN.isSet(args)) {
- int port = ARG_LISTENPORT.getInteger(args);
- ServerSocket ss = ServerSocketFactory.getDefault()
- .createServerSocket(port);
- socket = ss.accept();
- } else {
- InetAddress host = ARG_HOST.getAddress(args);
- int port = ARG_PORT.getInteger(args);
- socket = SocketFactory.getDefault().createSocket(host, port);
- }
-
- new NetConnection(socket).start();
- }
-
- private static class NetConnection {
- private Socket socket;
-
- private CopyThread toThread;
-
- private CopyThread fromThread;
-
- private NetConnection(Socket socket) {
- this.socket = socket;
- }
-
- private void start() throws IOException {
- toThread = new CopyThread(System.in, socket.getOutputStream());
- fromThread = new CopyThread(socket.getInputStream(), System.out);
- toThread.start();
- fromThread.start();
- synchronized(this) {
- try {
- wait();
- } catch (Exception e) {
- }
- }
- }
-
- private void close(CopyThread source) {
- if (socket != null) {
- try {
- socket.close();
- } catch (IOException e) {
- }
- socket = null;
- synchronized(this) {
- notifyAll();
- }
- }
- if (source == fromThread)
- toThread.breakout();
- else
- fromThread.breakout();
- }
-
- private class CopyThread extends Thread {
-
- private final InputStream in;
-
- private final OutputStream out;
-
- public CopyThread(InputStream in, OutputStream out) {
- this.in = in;
- this.out = out;
- }
-
- void breakout() {
- interrupt();
- }
-
- public void run() {
- try {
- while (socket != null) {
- int b = in.read();
- if (b == -1)
- break;
-
- out.write(b);
- }
- } catch (Exception iex) {
- } finally {
- close(this);
- }
- }
-
- }
- }
-}
Added: trunk/net/src/net/org/jnode/net/command/TcpInoutCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/TcpInoutCommand.java (rev 0)
+++ trunk/net/src/net/org/jnode/net/command/TcpInoutCommand.java 2008-05-11 09:16:47 UTC (rev 4083)
@@ -0,0 +1,150 @@
+package org.jnode.net.command;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+import javax.net.ServerSocketFactory;
+import javax.net.SocketFactory;
+
+import org.jnode.shell.AbstractCommand;
+import org.jnode.shell.CommandLine;
+import org.jnode.shell.syntax.*;
+
+/**
+ * This command establishes a TCP connection to a remote machine, either by
+ * connecting to it or accepting a remote connection. Once the connection has
+ * been set up, it sends the command's standard input to the remote connection and
+ * sends the output from the connection to the command's standard output.
+ *
+ * @author quades
+ * @author cr...@jn...
+ */
+public class TcpInoutCommand extends AbstractCommand {
+ // FIXME this command is only useful for testing. What we need is
+ // implementations of TELNET, RSH and SSH protocols (client and server-side).
+
+ private final HostNameArgument ARG_HOST =
+ new HostNameArgument("host", Argument.OPTIONAL,
+ "the hostname of the server to contact");
+
+ private final PortNumberArgument ARG_PORT =
+ new PortNumberArgument("port", Argument.OPTIONAL,
+ "the port the server is listening to");
+
+ private final PortNumberArgument ARG_LOCAL_PORT =
+ new PortNumberArgument("localPort", Argument.OPTIONAL,
+ "the local port we should listen to");
+
+ private Socket socket;
+ private CopyThread toThread;
+ private CopyThread fromThread;
+
+ public TcpInoutCommand() {
+ super("Set up an interactive TCP connection to a remote machine");
+ registerArguments(ARG_HOST, ARG_LOCAL_PORT, ARG_PORT);
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) throws Exception {
+ new TcpInoutCommand().execute(args);
+ }
+
+
+ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ throws IOException {
+ Socket socket;
+ if (ARG_LOCAL_PORT.isSet()) {
+ int port = ARG_LOCAL_PORT.getValue();
+ ServerSocket ss =
+ ServerSocketFactory.getDefault().createServerSocket(port);
+ socket = ss.accept();
+ }
+ else {
+ InetAddress host = ARG_HOST.getAsInetAddress();
+ int port = ARG_PORT.getValue();
+ socket = SocketFactory.getDefault().createSocket(host, port);
+ }
+
+ toThread = new CopyThread(in, socket.getOutputStream(), err);
+ fromThread = new CopyThread(socket.getInputStream(), out, err);
+
+ synchronized (this) {
+ toThread.start();
+ fromThread.start();
+ try {
+ wait();
+ }
+ catch (InterruptedException e) {
+ close(null);
+ }
+ }
+ }
+
+ private synchronized void close(CopyThread source) {
+ if (socket != null) {
+ try {
+ socket.close();
+ }
+ catch (IOException e) {
+ // We don't care ...
+ }
+ socket = null;
+ notifyAll();
+ }
+ if (source != toThread) {
+ toThread.terminate();
+ }
+ if (source != fromThread) {
+ fromThread.terminate();
+ }
+ }
+
+ private class CopyThread extends Thread {
+ private final InputStream in;
+ private final OutputStream out;
+ private final PrintStream err;
+ private boolean terminated;
+
+ CopyThread(InputStream in, OutputStream out, PrintStream err) {
+ this.in = in;
+ this.out = out;
+ this.err = err;
+ }
+
+ synchronized void terminate() {
+ if (!this.terminated) {
+ interrupt();
+ this.terminated = true;
+ }
+ }
+
+ public void run() {
+ try {
+ while (socket != null) {
+ int b = in.read();
+ if (b == -1) {
+ break;
+ }
+ out.write(b);
+ }
+ }
+ catch (IOException ex) {
+ synchronized(this) {
+ if (!terminated) {
+ err.println(ex.getLocalizedMessage());
+ }
+ }
+ }
+ finally {
+ close(this);
+ }
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-05-11 13:52:45
|
Revision: 4084
http://jnode.svn.sourceforge.net/jnode/?rev=4084&view=rev
Author: crawley
Date: 2008-05-11 06:52:42 -0700 (Sun, 11 May 2008)
Log Message:
-----------
Converted NetstatCommand
Modified Paths:
--------------
trunk/net/descriptors/org.jnode.net.command.xml
trunk/net/src/net/org/jnode/net/command/NetstatCommand.java
Modified: trunk/net/descriptors/org.jnode.net.command.xml
===================================================================
--- trunk/net/descriptors/org.jnode.net.command.xml 2008-05-11 09:16:47 UTC (rev 4083)
+++ trunk/net/descriptors/org.jnode.net.command.xml 2008-05-11 13:52:42 UTC (rev 4084)
@@ -60,6 +60,9 @@
<optional><argument argLabel="subnetMask"/></optional>
</sequence>
</syntax>
+ <syntax alias="netstat">
+ <empty description="Print statistics for all network devices"/>
+ </syntax>
<syntax alias="tcpinout">
<argument argLabel="localPort" description="Run tcpinout in server mode"/>
<sequence description="Run tcpinout in client mode">
Modified: trunk/net/src/net/org/jnode/net/command/NetstatCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/NetstatCommand.java 2008-05-11 09:16:47 UTC (rev 4083)
+++ trunk/net/src/net/org/jnode/net/command/NetstatCommand.java 2008-05-11 13:52:42 UTC (rev 4084)
@@ -31,7 +31,6 @@
import org.jnode.net.util.NetUtils;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Help;
import org.jnode.util.Statistic;
import org.jnode.util.Statistics;
@@ -40,30 +39,19 @@
*/
public class NetstatCommand extends AbstractCommand {
- public static Help.Info HELP_INFO = new Help.Info(
- "netstat",
- "Print the statistics of all network devices"
- );
+ public NetstatCommand() {
+ super("Print statistics for all network devices");
+ }
- public static void main(String[] args)
- throws Exception {
+ public static void main(String[] args) throws Exception {
new NetstatCommand().execute(args);
}
/**
* Execute this command
*/
- public void execute(
- CommandLine cmdLine,
- InputStream in,
- PrintStream out,
- PrintStream err)
+ public void execute(CommandLine cmdLine, InputStream in, PrintStream out, PrintStream err)
throws Exception {
- showStats(out);
- }
-
- private void showStats(PrintStream out)
- throws NetworkException {
final NetworkLayerManager nlm = NetUtils.getNLM();
for (NetworkLayer nl : nlm.getNetworkLayers()) {
@@ -82,7 +70,6 @@
final String prefix2 = prefix + prefix;
out.print(prefix2);
showStats(out, tl.getStatistics(), maxWidth - prefix2.length(), prefix2);
- //out.println();
}
out.println();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-05-11 14:18:23
|
Revision: 4085
http://jnode.svn.sourceforge.net/jnode/?rev=4085&view=rev
Author: crawley
Date: 2008-05-11 07:18:18 -0700 (Sun, 11 May 2008)
Log Message:
-----------
Converted PingCommand
Modified Paths:
--------------
trunk/net/descriptors/org.jnode.net.command.xml
trunk/net/src/net/org/jnode/net/command/PingCommand.java
Modified: trunk/net/descriptors/org.jnode.net.command.xml
===================================================================
--- trunk/net/descriptors/org.jnode.net.command.xml 2008-05-11 13:52:42 UTC (rev 4084)
+++ trunk/net/descriptors/org.jnode.net.command.xml 2008-05-11 14:18:18 UTC (rev 4085)
@@ -63,6 +63,9 @@
<syntax alias="netstat">
<empty description="Print statistics for all network devices"/>
</syntax>
+ <syntax alias="ping">
+ <argument argLabel="host" description="Ping a remote host"/>
+ </syntax>
<syntax alias="tcpinout">
<argument argLabel="localPort" description="Run tcpinout in server mode"/>
<sequence description="Run tcpinout in client mode">
Modified: trunk/net/src/net/org/jnode/net/command/PingCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/PingCommand.java 2008-05-11 13:52:42 UTC (rev 4084)
+++ trunk/net/src/net/org/jnode/net/command/PingCommand.java 2008-05-11 14:18:18 UTC (rev 4085)
@@ -21,7 +21,8 @@
package org.jnode.net.command;
-import java.net.InetAddress;
+import java.io.InputStream;
+import java.io.PrintStream;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;
@@ -38,79 +39,70 @@
import org.jnode.net.ipv4.icmp.ICMPProtocol;
import org.jnode.net.ipv4.layer.IPv4NetworkLayer;
import org.jnode.net.util.NetUtils;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.Syntax;
-import org.jnode.shell.help.argument.HostNameArgument;
+import org.jnode.shell.AbstractCommand;
+import org.jnode.shell.CommandLine;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.HostNameArgument;
/**
* @author JPG
*/
-public class PingCommand implements ICMPListener {
-
+public class PingCommand extends AbstractCommand implements ICMPListener {
+ // FIXME Some of the following could be command parameters ...
private final Statistics stat = new Statistics();
-
private boolean wait = true;
-
private int count = 4;
-
private boolean dontFragment = false;
-
- private final IPv4Address dst;
-
+ private IPv4Address dst;
private boolean flood = false;
-
private int interval = 6000;
-
private int size = 64;
-
private long timeout = 5000;
-
private int ttl = 255;
- static final HostNameArgument DST = new HostNameArgument("host", "the target host");
+ private final HostNameArgument ARG_HOST =
+ new HostNameArgument("host", Argument.MANDATORY, "the target host");
- public static Help.Info HELP_INFO = new Help.Info(
- "ping",
- new Syntax[] { new Syntax("Ping the specified host",
- new Parameter[] { new Parameter(DST, Parameter.MANDATORY)})});
+ public PingCommand() {
+ super("Ping the specified host");
+ registerArguments(ARG_HOST);
+ }
public static void main(String[] args) throws Exception {
- final ParsedArguments cmdLine = HELP_INFO.parse(args);
- final PingCommand cmd = new PingCommand(DST.getAddress(cmdLine));
- cmd.execute();
+ new PingCommand().execute(args);
}
- public PingCommand(InetAddress destination) {
- this.dst = new IPv4Address(destination);
- }
-
- public void execute() throws SocketException, InterruptedException {
- final IPv4Header netHeader = new IPv4Header(0, this.ttl, IPv4Constants.IPPROTO_ICMP, this.dst, 8);
+ public void execute(CommandLine commandLine, InputStream in,
+ PrintStream out, PrintStream err)
+ throws SocketException, InterruptedException {
+ this.dst = new IPv4Address(ARG_HOST.getValue());
+ final IPv4Header netHeader =
+ new IPv4Header(0, this.ttl, IPv4Constants.IPPROTO_ICMP, this.dst, 8);
netHeader.setDontFragment(this.dontFragment);
final IPv4NetworkLayer netLayer = (IPv4NetworkLayer) NetUtils.getNLM()
- .getNetworkLayer(EthernetConstants.ETH_P_IP);
- final ICMPProtocol icmpProtocol = (ICMPProtocol) netLayer
- .getProtocol(ICMPProtocol.IPPROTO_ICMP);
+ .getNetworkLayer(EthernetConstants.ETH_P_IP);
+ final ICMPProtocol icmpProtocol =
+ (ICMPProtocol) netLayer.getProtocol(ICMPProtocol.IPPROTO_ICMP);
icmpProtocol.addListener(this);
try {
int id_count = 0;
int seq_count = 0;
while (this.count != 0) {
- System.out.println("Ping " + dst + " attempt " + seq_count);
+ out.println("Ping " + dst + " attempt " + seq_count);
- if (!this.flood) this.wait = true;
+ if (!this.flood) {
+ this.wait = true;
+ }
SocketBuffer packet = new SocketBuffer();
packet.insert(this.size);
- ICMPEchoHeader transportHeader = new ICMPEchoHeader(8,
- id_count, seq_count);
+ ICMPEchoHeader transportHeader =
+ new ICMPEchoHeader(8, id_count, seq_count);
transportHeader.prefixTo(packet);
- Request r = new Request(this.stat, this.timeout, System
- .currentTimeMillis(), id_count, seq_count);
+ Request r = new Request(this.stat, this.timeout,
+ System.currentTimeMillis(), id_count, seq_count);
registerRequest(r);
netLayer.transmit(netHeader, packet);
@@ -120,13 +112,13 @@
this.wait = false;
}
Thread.sleep(500);
- synchronized(this){
- if(response){
- System.out.print("Reply from " + dst.toString() + ": ");
- System.out.print(hdr1.getDataLength() - 8 + "bytes of data ");
- System.out.print("ttl=" + hdr1.getTtl() + " ");
- System.out.print("seq=" + hdr2.getSeqNumber() + " ");
- System.out.println("time=" + (roundt) + "ms");
+ synchronized (this) {
+ if (response) {
+ out.print("Reply from " + dst.toString() + ": ");
+ out.print(hdr1.getDataLength() - 8 + "bytes of data ");
+ out.print("ttl=" + hdr1.getTtl() + " ");
+ out.print("seq=" + hdr2.getSeqNumber() + " ");
+ out.println("time=" + (roundt) + "ms");
response = false;
}
}
@@ -138,19 +130,22 @@
while (!isEmpty()) {
Thread.sleep(100);
}
- } finally {
+ }
+ finally {
icmpProtocol.removeListener(this);
}
- System.out.println("-> Packet statistics");
- System.out.println(this.stat.getStatistics());
+ out.println("-> Packet statistics");
+ out.println(this.stat.getStatistics());
}
private long match(int id, int seq, Request r) {
- if ((r != null) && (id == r.getId()))
+ if (r != null && id == r.getId()) {
return r.getTimestamp();
- else
+ }
+ else {
return -1;
+ }
}
public void packetReceived(SocketBuffer skbuf) {
@@ -161,7 +156,9 @@
int seq = hdr2.getSeqNumber();
Request r = removeRequest(seq);
- if ((r == null) || (r.Obsolete())) return;
+ if (r == null || r.Obsolete()) {
+ return;
+ }
long timestamp = match(hdr2.getIdentifier(), seq, r);
@@ -169,7 +166,8 @@
gotResponse(timestamp, hdr1, hdr2, roundtrip);
}
- private synchronized void gotResponse(long timestamp, IPv4Header hdr1, ICMPEchoHeader hdr2, long roundtrip) {
+ private synchronized void gotResponse(
+ long timestamp, IPv4Header hdr1, ICMPEchoHeader hdr2, long roundtrip) {
if (timestamp != -1) {
this.hdr1 = hdr1;
this.hdr2 = hdr2;
@@ -179,8 +177,8 @@
wait = false;
this.stat.recordPacket(roundtrip);
}
-
- //respose data
+
+ //response data
private boolean response;
private long roundt;
private IPv4Header hdr1;
@@ -201,15 +199,10 @@
}
class Request extends TimerTask {
-
private Timer timer = new Timer();
-
private boolean obsolete = false;
-
private Statistics stat;
-
private long timestamp;
-
private int id, seq;
Request(Statistics stat, long timeout, long timestamp, int id, int seq) {
@@ -234,8 +227,10 @@
this.obsolete = true;
this.timer.cancel();
return false;
- } else
+ }
+ else {
return true;
+ }
}
long getTimestamp() {
@@ -250,42 +245,35 @@
return seq;
}
}
-}
-class Statistics {
+ private class Statistics {
+ private int received = 0, lost = 0;
+ private long min = Integer.MAX_VALUE, max = 0;
+ private long sum;
- private int received = 0, lost = 0;
+ void recordPacket(long roundtrip) {
+ received++;
+ if (roundtrip < min) {
+ min = roundtrip;
+ }
+ if (roundtrip > max) {
+ max = roundtrip;
+ }
+ sum += roundtrip;
+ }
- private long min = Integer.MAX_VALUE, max = 0;
+ void recordLost() {
+ lost++;
+ }
- private long sum;
-
- void recordPacket(long roundtrip) {
- received++;
-
- if (roundtrip < min) min = roundtrip;
- if (roundtrip > max) max = roundtrip;
-
- sum += roundtrip;
+ String getStatistics() {
+ int packets = received + lost;
+ float avg = sum / packets;
+ return (packets + " packets transmitted, " +
+ received +" packets received\n" +
+ "round-trip min/avg/max = " + min + "/" + avg +
+ "/" + max + " ms");
+ }
}
-
- void recordLost() {
- lost++;
- }
-
- String getStatistics() {
- int packets = received + lost;
- //float percent = 0;
- // if (packets != 0){
- // percent = lost/packets;
- // percent *= 100;
- // }
- float avg = sum / packets;
- return packets + " packets transmitted, " + received
- + " packets received\n" +
- // percent +"% packet loss\n"+
- "round-trip min/avg/max = " + min + "/" + avg + "/" + max
- + " ms";
- }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-05-12 11:23:35
|
Revision: 4088
http://jnode.svn.sourceforge.net/jnode/?rev=4088&view=rev
Author: crawley
Date: 2008-05-12 04:23:29 -0700 (Mon, 12 May 2008)
Log Message:
-----------
Converted ResolverCommand.
Modified Paths:
--------------
trunk/net/descriptors/org.jnode.net.command.xml
trunk/net/src/net/org/jnode/net/command/ResolverCommand.java
Modified: trunk/net/descriptors/org.jnode.net.command.xml
===================================================================
--- trunk/net/descriptors/org.jnode.net.command.xml 2008-05-12 11:21:57 UTC (rev 4087)
+++ trunk/net/descriptors/org.jnode.net.command.xml 2008-05-12 11:23:29 UTC (rev 4088)
@@ -66,6 +66,17 @@
<syntax alias="ping">
<argument argLabel="host" description="Ping a remote host"/>
</syntax>
+ <syntax alias="resolver">
+ <empty description="List the DNS servers used by the resolver's list"/>
+ <sequence description="Add a DNS server to the resolver">
+ <option argLabel="add" shortName="a" longName="add"/>
+ <argument argLabel="server"/>
+ </sequence>
+ <sequence description="Remove a DNS server from the resolver's list">
+ <option argLabel="del" shortName="d" longName="del"/>
+ <argument argLabel="server"/>
+ </sequence>
+ </syntax>
<syntax alias="tcpinout">
<argument argLabel="localPort" description="Run tcpinout in server mode"/>
<sequence description="Run tcpinout in client mode">
Modified: trunk/net/src/net/org/jnode/net/command/ResolverCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/ResolverCommand.java 2008-05-12 11:21:57 UTC (rev 4087)
+++ trunk/net/src/net/org/jnode/net/command/ResolverCommand.java 2008-05-12 11:23:29 UTC (rev 4088)
@@ -25,16 +25,14 @@
import java.io.PrintStream;
import java.util.Collection;
-import org.jnode.net.help.argument.HostArgument;
+import org.jnode.driver.net.NetworkException;
import org.jnode.net.ipv4.IPv4Address;
import org.jnode.net.ipv4.util.ResolverImpl;
+import org.jnode.net.syntax.IPv4AddressArgument;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.Syntax;
-import org.jnode.shell.help.argument.OptionArgument;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.FlagArgument;
/**
* This command class manages the DNS resolver.
@@ -43,48 +41,43 @@
*/
public class ResolverCommand extends AbstractCommand
{
- private static final String FUNC_ADD = "add";
- private static final String FUNC_DEL = "del";
+ // FIXME this should not be restricted to IPv4 addresses.
+ private final FlagArgument FLAG_ADD =
+ new FlagArgument("add", Argument.OPTIONAL, "if set, add a DNS server");
+ private final FlagArgument FLAG_DEL =
+ new FlagArgument("del", Argument.OPTIONAL, "if set, remove a DNS server");
- private static final OptionArgument ARG_FUNCTION =
- new OptionArgument(
- "function",
- "the function to perform",
- new OptionArgument.Option[] {
- new OptionArgument.Option(FUNC_ADD, "add a dns server"),
- new OptionArgument.Option(FUNC_DEL, "delete a dns server")});
+ private final IPv4AddressArgument ARG_DNS_SERVER =
+ new IPv4AddressArgument("server", Argument.OPTIONAL,
+ "the DNS server's hostname or IP address");
- private static final HostArgument ARG_DNSSERVER =
- new HostArgument("dns server", "the dns server IP address");
+ public ResolverCommand() {
+ super("Manage JNode's DNS resolver");
+ registerArguments(FLAG_ADD, FLAG_DEL, ARG_DNS_SERVER);
+ }
- public static Help.Info HELP_INFO =
- new Help.Info(
- "resolver",
- new Syntax[] {
- new Syntax("Print the dns servers"),
- new Syntax(
- "Add or remove a dns server",
- new Parameter[] {
- new Parameter(ARG_FUNCTION, Parameter.MANDATORY),
- new Parameter(ARG_DNSSERVER, Parameter.MANDATORY)
- })
- });
-
-
public static void main(String[] args) throws Exception {
new ResolverCommand().execute(args);
}
-
public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
- ParsedArguments cmdLine = HELP_INFO.parse(commandLine);
-
- if (cmdLine.size() == 0) {
+ PrintStream out, PrintStream err)
+ throws NetworkException {
+ IPv4Address server = ARG_DNS_SERVER.getValue();
+ if (FLAG_ADD.isSet()) {
+ // Add a DNS server
+ ResolverImpl.addDnsServer(server);
+ }
+ else if (FLAG_DEL.isSet()) {
+ // Remove a DNS server
+ ResolverImpl.removeDnsServer(server);
+ }
+ else {
+ // List the DNS servers that the resolver uses
Collection<String> resolvers = ResolverImpl.getDnsServers();
- if (resolvers == null) {
+ if (resolvers.size() == 0) {
out.println("No DNS servers found.");
}
else {
@@ -94,18 +87,5 @@
}
}
}
- else {
- String func = ARG_FUNCTION.getValue(cmdLine);
- IPv4Address server = ARG_DNSSERVER.getAddress(cmdLine);
-
- if (FUNC_ADD.equals(func)) {
- ResolverImpl.addDnsServer(server);
- }
- else if (FUNC_DEL.equals(func)) {
- ResolverImpl.removeDnsServer(server);
- }
- }
-
- out.println();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-05-12 15:18:19
|
Revision: 4093
http://jnode.svn.sourceforge.net/jnode/?rev=4093&view=rev
Author: crawley
Date: 2008-05-12 08:17:37 -0700 (Mon, 12 May 2008)
Log Message:
-----------
Counverted RouteCommand
Modified Paths:
--------------
trunk/net/descriptors/org.jnode.net.command.xml
trunk/net/src/net/org/jnode/net/command/RouteCommand.java
Modified: trunk/net/descriptors/org.jnode.net.command.xml
===================================================================
--- trunk/net/descriptors/org.jnode.net.command.xml 2008-05-12 15:16:48 UTC (rev 4092)
+++ trunk/net/descriptors/org.jnode.net.command.xml 2008-05-12 15:17:37 UTC (rev 4093)
@@ -77,6 +77,18 @@
<argument argLabel="server"/>
</sequence>
</syntax>
+ <syntax alias="route">
+ <empty description="Print the routing table"/>
+ <sequence description="Add or remove a route">
+ <alternatives>
+ <option argLabel="add" shortName="a" longName="add"/>
+ <option argLabel="del" shortName="d" longName="del"/>
+ </alternatives>
+ <argument argLabel="target"/>
+ <argument argLabel="device"/>
+ <optional><argument argLabel="gateway"/></optional>
+ </sequence>
+ </syntax>
<syntax alias="tcpinout">
<argument argLabel="localPort" description="Run tcpinout in server mode"/>
<sequence description="Run tcpinout in client mode">
Modified: trunk/net/src/net/org/jnode/net/command/RouteCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/RouteCommand.java 2008-05-12 15:16:48 UTC (rev 4092)
+++ trunk/net/src/net/org/jnode/net/command/RouteCommand.java 2008-05-12 15:17:37 UTC (rev 4093)
@@ -21,86 +21,78 @@
package org.jnode.net.command;
+import static org.jnode.net.ethernet.EthernetConstants.ETH_P_IP;
+
import java.io.InputStream;
import java.io.PrintStream;
+import javax.naming.NameNotFoundException;
+
import org.jnode.driver.Device;
+import org.jnode.driver.net.NetworkException;
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.net.NoSuchProtocolException;
import org.jnode.net.ipv4.IPv4Address;
import org.jnode.net.ipv4.config.IPv4ConfigurationService;
import org.jnode.net.ipv4.layer.IPv4NetworkLayer;
+import org.jnode.net.syntax.IPv4AddressArgument;
+import org.jnode.net.syntax.IPv4HostArgument;
import org.jnode.net.util.NetUtils;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.Syntax;
-import org.jnode.shell.help.argument.DeviceArgument;
-import org.jnode.shell.help.argument.OptionArgument;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.DeviceArgument;
+import org.jnode.shell.syntax.FlagArgument;
/**
* @author epr
*/
-public class RouteCommand extends AbstractCommand implements EthernetConstants {
- // FIXME the "constants interface" anti-pattern.
- static final String FUNC_ADD = "add";
- static final String FUNC_DEL = "del";
+public class RouteCommand extends AbstractCommand {
+ private final FlagArgument FLAG_ADD =
+ new FlagArgument("add", Argument.OPTIONAL, "if set, add a route");
+
+ private final FlagArgument FLAG_DEL =
+ new FlagArgument("del", Argument.OPTIONAL, "if set, remove a route");
+
+ private final IPv4AddressArgument ARG_TARGET =
+ new IPv4AddressArgument("target", Argument.OPTIONAL, "the target network");
+
+ private final IPv4HostArgument ARG_GATEWAY =
+ new IPv4HostArgument("gateway", Argument.OPTIONAL, "the gateway name or IP address");
+
+ private final DeviceArgument ARG_DEVICE =
+ new DeviceArgument("device", Argument.OPTIONAL, "the device to connect to the foreign network");
+
+
+ public RouteCommand() {
+ super("Manage the IPv4 network routing table");
+ registerArguments(FLAG_ADD, FLAG_DEL, ARG_DEVICE, ARG_GATEWAY, ARG_TARGET);
+ }
- static final OptionArgument ARG_FUNCTION =
- new OptionArgument(
- "function",
- "the function to perform",
- new OptionArgument.Option[] { new OptionArgument.Option(FUNC_ADD, "add a route"), new OptionArgument.Option(FUNC_DEL, "delete a route")});
- static final NetworkArgument ARG_TARGET = new NetworkArgument("target", "the target network");
- static final HostArgument ARG_GATEWAY = new HostArgument("gateway", "the gateway name or IP address");
- static final DeviceArgument ARG_DEVICE = new DeviceArgument("device", "the device to connect to the foreign network");
-
- public static Help.Info HELP_INFO =
- new Help.Info(
- "route",
- new Syntax[] {
- new Syntax("Print the routing table"),
- new Syntax(
- "Add or remove a route",
- new Parameter[] {
- new Parameter(ARG_FUNCTION, Parameter.MANDATORY),
- new Parameter(ARG_TARGET, Parameter.MANDATORY),
- //new Parameter("gw", "the gateway to access the target network", ARG_GATEWAY, Parameter.OPTIONAL),
- new Parameter(ARG_DEVICE, Parameter.MANDATORY),
- new Parameter(ARG_GATEWAY, Parameter.OPTIONAL)})
- });
-
public static void main(String[] args) throws Exception {
new RouteCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception {
- ParsedArguments cmdLine = HELP_INFO.parse(commandLine);
+ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ throws NoSuchProtocolException, NetworkException, NameNotFoundException
+ {
+ final IPv4NetworkLayer ipNL =
+ (IPv4NetworkLayer) NetUtils.getNLM().getNetworkLayer(ETH_P_IP);
+ final IPv4Address target = ARG_TARGET.getValue();
+ final IPv4Address gateway = ARG_GATEWAY.getValue();
+ final Device device = ARG_DEVICE.getValue();
+ final IPv4ConfigurationService cfg =
+ (IPv4ConfigurationService) InitialNaming.lookup(IPv4ConfigurationService.NAME);
- final IPv4NetworkLayer ipNL = (IPv4NetworkLayer) NetUtils.getNLM().getNetworkLayer(ETH_P_IP);
-
- if (cmdLine.size() == 0) {
- System.out.println("Routing table");
- System.out.println(ipNL.getRoutingTable());
- } else {
- String func = ARG_FUNCTION.getValue(cmdLine);
- IPv4Address target = ARG_TARGET.getAddress(cmdLine);
- IPv4Address gateway = ARG_GATEWAY.getAddress(cmdLine);
- Device device = ARG_DEVICE.getDevice(cmdLine);
-
- final IPv4ConfigurationService cfg = (IPv4ConfigurationService)InitialNaming.lookup(IPv4ConfigurationService.NAME);
-
- if (FUNC_ADD.equals(func)) {
- cfg.addRoute(target, gateway, device, true);
- } else if (FUNC_DEL.equals(func)) {
- cfg.deleteRoute(target, gateway, device);
- }
- }
- System.out.println();
+ if (FLAG_ADD.isSet()) {
+ cfg.addRoute(target, gateway, device, true);
+ }
+ else if (FLAG_DEL.isSet()) {
+ cfg.deleteRoute(target, gateway, device);
+ }
+ else {
+ out.println("Routing table");
+ out.println(ipNL.getRoutingTable());
+ }
}
-
}
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:00:03
|
Revision: 4094
http://jnode.svn.sourceforge.net/jnode/?rev=4094&view=rev
Author: crawley
Date: 2008-05-13 04:42:45 -0700 (Tue, 13 May 2008)
Log Message:
-----------
Converted RpcInfoCommand
Modified Paths:
--------------
trunk/net/descriptors/org.jnode.net.command.xml
trunk/net/src/net/org/jnode/net/command/RpcInfoCommand.java
Modified: trunk/net/descriptors/org.jnode.net.command.xml
===================================================================
--- trunk/net/descriptors/org.jnode.net.command.xml 2008-05-12 15:17:37 UTC (rev 4093)
+++ trunk/net/descriptors/org.jnode.net.command.xml 2008-05-13 11:42:45 UTC (rev 4094)
@@ -89,6 +89,9 @@
<optional><argument argLabel="gateway"/></optional>
</sequence>
</syntax>
+ <syntax alias="rpcinfo">
+ <argument argLabel="host" description="Probe a remote host's portmapper service"/>
+ </syntax>
<syntax alias="tcpinout">
<argument argLabel="localPort" description="Run tcpinout in server mode"/>
<sequence description="Run tcpinout in client mode">
Modified: trunk/net/src/net/org/jnode/net/command/RpcInfoCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/RpcInfoCommand.java 2008-05-12 15:17:37 UTC (rev 4093)
+++ trunk/net/src/net/org/jnode/net/command/RpcInfoCommand.java 2008-05-13 11:42:45 UTC (rev 4094)
@@ -25,6 +25,7 @@
import java.io.InputStream;
import java.io.PrintStream;
import java.net.InetAddress;
+import java.net.UnknownHostException;
import org.acplt.oncrpc.OncRpcException;
import org.acplt.oncrpc.OncRpcPortmapClient;
@@ -32,11 +33,8 @@
import org.acplt.oncrpc.OncRpcServerIdent;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.Syntax;
-import org.jnode.shell.help.argument.HostNameArgument;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.HostNameArgument;
/**
* rpcinfo command makes an RPC call to an RPC server and reports what it finds.
@@ -47,36 +45,23 @@
private static final String LIST_SERVICES_FORMAT = "%1$10s %2$10s %3$10s %4$10s %5$10s";
- static final HostNameArgument HOST = new HostNameArgument("host", "host");
+ private final HostNameArgument ARG_HOST =
+ new HostNameArgument("host", Argument.MANDATORY, "the host to be probed");
- public static Help.Info HELP_INFO = new Help.Info("rpcinfo", new Syntax[]{new Syntax(
- "Probe the portmapper on host, and print a list of all registered RPC programs.",
- new Parameter[]{new Parameter(HOST)})});
-
+ public RpcInfoCommand() {
+ super("Probe the portmapper on host, and print a list of all registered RPC programs.");
+ registerArguments(ARG_HOST);
+ }
+
public static void main(String[] args) throws Exception {
-
new RpcInfoCommand().execute(args);
-
}
- public RpcInfoCommand() {
- }
-
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception {
-
- ParsedArguments parsedArguments = HELP_INFO.parse(commandLine);
-
- InetAddress host = HOST.getAddress(parsedArguments);
-
- listServices(host, out, err);
-
- }
-
- private void listServices(InetAddress host, PrintStream out, PrintStream err) {
-
+ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) {
OncRpcPortmapClient client = null;
+ String hostname = ARG_HOST.getValue();
try {
-
+ InetAddress host = InetAddress.getByName(hostname);
client = new OncRpcPortmapClient(host, OncRpcProtocols.ONCRPC_UDP);
OncRpcServerIdent[] servers = client.listServers();
@@ -86,31 +71,32 @@
for (int i = 0; i < servers.length; i++) {
OncRpcServerIdent server = servers[i];
-
- out.printf(LIST_SERVICES_FORMAT, server.program, server.version, server.protocol == 6 ? "tcp" : "udp",
- server.port, getName(server.program));
-
+ out.printf(LIST_SERVICES_FORMAT, server.program, server.version,
+ server.protocol == 6 ? "tcp" : "udp",
+ server.port, getName(server.program));
out.println();
}
} catch (OncRpcException e) {
- err.println("Can not make the rpc call to the host " + host.getHostAddress());
+ err.println("Cannot make the rpc call to host " + hostname);
exit(1);
+ } catch (UnknownHostException e) {
+ err.println("Unknown hostname " + hostname);
+ exit(1);
} catch (IOException e) {
- err.println("Can not connect to the host " + host.getHostAddress());
+ err.println("Cannot connect to host " + hostname);
exit(1);
} finally {
if (client != null) {
try {
client.close();
- } catch (Exception e) {
+ } catch (OncRpcException e) {
+ // Ignore exception on close
}
}
}
-
}
private String getName(int program) {
-
switch (program) {
case 100000:
return "portmapper";
@@ -123,8 +109,7 @@
case 100024:
return "status";
default:
- return "unknown";
+ return "unknown service (" + program + ")";
}
-
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-05-13 14:14:27
|
Revision: 4096
http://jnode.svn.sourceforge.net/jnode/?rev=4096&view=rev
Author: crawley
Date: 2008-05-13 07:13:57 -0700 (Tue, 13 May 2008)
Log Message:
-----------
Converted TftpCommand, refactored a bit and fixed some bugs
Modified Paths:
--------------
trunk/net/descriptors/org.jnode.net.command.xml
trunk/net/descriptors/org.jnode.net.ipv4.xml
trunk/net/src/net/org/jnode/net/command/TftpCommand.java
trunk/net/src/net/org/jnode/net/ipv4/tftp/TFTPClient.java
Modified: trunk/net/descriptors/org.jnode.net.command.xml
===================================================================
--- trunk/net/descriptors/org.jnode.net.command.xml 2008-05-13 12:02:17 UTC (rev 4095)
+++ trunk/net/descriptors/org.jnode.net.command.xml 2008-05-13 14:13:57 UTC (rev 4096)
@@ -99,6 +99,17 @@
<argument argLabel="port"/>
</sequence>
</syntax>
+ <syntax alias="tftp">
+ <optional description="Run an interactive TFTP client"><argument argLabel="host"/></optional>
+ <sequence description="Do a non-interactive TFTP 'get' or 'put'">
+ <alternatives>
+ <option argLabel="get" longName="get"/>
+ <option argLabel="put" longName="put"/>
+ </alternatives>
+ <argument argLabel="host"/>
+ <argument argLabel="filename"/>
+ </sequence>
+ </syntax>
</extension>
<extension point="org.jnode.security.permissions">
@@ -108,6 +119,7 @@
<permission class="java.net.SocketPermission" name="*:80" actions="resolve,listen,connect"/>
<permission class="java.util.PropertyPermission" name="dns.server" actions="read"/>
<permission class="java.util.PropertyPermission" name="dns.search" actions="read"/>
+ <permission class="java.util.PropertyPermission" name="user.dir" actions="read"/>
<permission class="org.jnode.net.NetPermission" name="bootpClient"/>
<permission class="org.jnode.net.NetPermission" name="dhcpClient"/>
<permission class="java.io.FilePermission" name="<<ALL FILES>>" actions="read,write"/>
Modified: trunk/net/descriptors/org.jnode.net.ipv4.xml
===================================================================
--- trunk/net/descriptors/org.jnode.net.ipv4.xml 2008-05-13 12:02:17 UTC (rev 4095)
+++ trunk/net/descriptors/org.jnode.net.ipv4.xml 2008-05-13 14:13:57 UTC (rev 4096)
@@ -48,6 +48,12 @@
<permission class="java.net.SocketPermission" name="*:53" actions="connect,resolve,listen"/>
<permission class="java.util.PropertyPermission" name="dns.server" actions="read,write"/>
<permission class="java.util.PropertyPermission" name="dns.search" actions="read,write"/>
+
+ <!-- TFTP !?! -->
+ <permission class="java.io.FilePermission" name="<<ALL FILES>>" actions="read,write"/>
+ <permission class="java.util.PropertyPermission" name="user.dir" actions="read"/>
+ <permission class="java.net.SocketPermission" name="*:69" actions="connect,resolve"/>
+
</extension>
<extension point="org.jnode.net.networkLayers">
Modified: trunk/net/src/net/org/jnode/net/command/TftpCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/TftpCommand.java 2008-05-13 12:02:17 UTC (rev 4095)
+++ trunk/net/src/net/org/jnode/net/command/TftpCommand.java 2008-05-13 14:13:57 UTC (rev 4096)
@@ -21,60 +21,80 @@
package org.jnode.net.command;
+import java.io.File;
import java.io.InputStream;
import java.io.PrintStream;
-import org.jnode.net.help.argument.HostArgument;
import org.jnode.net.ipv4.tftp.TFTPClient;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Argument;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.Syntax;
-import org.jnode.shell.help.argument.OptionArgument;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.FileArgument;
+import org.jnode.shell.syntax.FlagArgument;
+import org.jnode.shell.syntax.HostNameArgument;
/**
+ * This Command class does a batch mode TFTP get or put, or starts a simple TFTP client.
+ *
* @author markhale
+ * @author crawley
*/
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");
+ private final FlagArgument FLAG_PUT =
+ new FlagArgument("put", Argument.OPTIONAL, "if set, transfer a file to the TFTP server");
- 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)
- }
- )
- }
- );
+ private final FlagArgument FLAG_GET =
+ new FlagArgument("get", Argument.OPTIONAL, "if set, fetch a file from the TFTP server");
+
+ private final HostNameArgument ARG_SERVER =
+ new HostNameArgument("host", Argument.OPTIONAL, "the hostname of the TFTP server");
+
+ private final FileArgument ARG_FILENAME =
+ new FileArgument("filename", Argument.OPTIONAL, "the file to transfer");
+ public TftpCommand() {
+ super("Do a TFTP get or put, or run an interactive TFTP client");
+ registerArguments(FLAG_GET, FLAG_PUT, ARG_FILENAME, ARG_SERVER);
+ }
+
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();
+ TFTPClient client = new TFTPClient(out);
+ String host = ARG_SERVER.getValue();
+ File file = ARG_FILENAME.getValue();
+ if (FLAG_PUT.isSet()) {
+ if (client.executeCommand(new String[] {TFTPClient.CONNECT_CMD, host})) {
+ if (!client.executeCommand(new String[] {TFTPClient.PUT_CMD, file.toString()})) {
+ exit(1);
+ }
+ }
+ else {
+ exit(2);
+ }
+ }
+ else if (FLAG_GET.isSet()) {
+ if (client.executeCommand(new String[] {TFTPClient.CONNECT_CMD, host})) {
+ if (!client.executeCommand(new String[] {TFTPClient.GET_CMD, file.toString()})) {
+ exit(1);
+ }
+ }
+ else {
+ exit(2);
+ }
+ }
+ else {
+ if (host != null) {
+ if (!client.executeCommand(new String[] {TFTPClient.CONNECT_CMD, host})) {
+ exit(2);
+ }
+ }
+ client.run(in);
+ }
}
}
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 12:02:17 UTC (rev 4095)
+++ trunk/net/src/net/org/jnode/net/ipv4/tftp/TFTPClient.java 2008-05-13 14:13:57 UTC (rev 4096)
@@ -21,16 +21,22 @@
package org.jnode.net.ipv4.tftp;
+import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
* Console TFTP client.
* Usage: TFTPClient [hostname [PUT/GET filename]]
+ *
* @author markhale
*/
public class TFTPClient extends org.apache.commons.net.tftp.TFTPClient {
@@ -46,81 +52,34 @@
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 BufferedReader br;
+ private PrintStream out;
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 TFTPClient(PrintStream out) {
+ this.out = out;
}
@SuppressWarnings("deprecation")
- private void run() {
- System.out.println("JNode TFTP Client");
+ public void run(InputStream in) throws IOException {
+ // FIXME ... figure out to how to use JNode command argument parsing
+ // (and completion) for our little TFTP interactive command syntax.
+ this.br = new BufferedReader(new InputStreamReader(in));
+ out.println("JNode TFTP Client");
do {
- try {
- System.out.print("tftp> ");
- String line = in.readLine();
- String[] args = parseLine(line);
- executeCommand(args);
- } catch (IOException ex) {
+ out.print("tftp> ");
+ String line = br.readLine();
+ if (line == null) {
+ // EOF
+ break;
}
+ executeCommand(line.trim().split("\\s+"));
} 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.
@@ -134,25 +93,26 @@
final String cmd = args[0];
if (cmd.equals(CONNECT_CMD)) { // connect
if (args.length < 2) {
- System.out.println("Please specify a host name.");
+ out.println("Please specify a host name.");
}
else {
try {
+ // FIXME ... this is not "connecting"!!
serverAddress = InetAddress.getByName(args[1]);
serverAddress.getHostName(); // do DNS lookup
success = true;
}
catch (UnknownHostException ex) {
- System.out.println("Unknown host " + args[1] + ".");
+ out.println("Unknown host " + args[1] + ".");
}
}
}
else if (cmd.equals(GET_CMD)) { // get
if (serverAddress == null) {
- System.out.println("Not connected.");
+ out.println("Not connected.");
}
else if (args.length < 2) {
- System.out.println("Please specify a file name.");
+ out.println("Please specify a file name.");
}
else {
String filename = args[1];
@@ -162,7 +122,7 @@
open();
try {
int bytesTransferred = receiveFile(filename, mode, fileOut, serverAddress);
- System.out.println(bytesTransferred + " bytes transferred.");
+ out.println(bytesTransferred + " bytes transferred.");
}
finally {
close();
@@ -174,16 +134,16 @@
success = true;
}
catch (IOException ex) {
- System.out.println("Error transferring file: " + ex.getMessage());
+ diagnose(ex, "Error transferring file");
}
}
}
else if (cmd.equals(PUT_CMD)) { // put
if (serverAddress == null) {
- System.out.println("Not connected.");
+ out.println("Not connected.");
}
else if (args.length < 2) {
- System.out.println("Please specify a file name.");
+ out.println("Please specify a file name.");
}
else {
String filename = args[1];
@@ -204,7 +164,7 @@
success = true;
}
catch (IOException ex) {
- System.out.println("Error transferring file: " + ex.getMessage());
+ diagnose(ex, "Error transferring file");
}
}
}
@@ -218,58 +178,58 @@
}
else if (cmd.equals(TIMEOUT_CMD)) { // timeout
if (args.length < 2) {
- System.out.println("Please specify a timeout value.");
+ 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.");
+ } catch (NumberFormatException ex) {
+ out.println("Invalid timeout value.");
}
}
}
else if (cmd.equals(RETRIES_CMD)) { // retries
if (args.length < 2) {
- System.out.println("Please specify a retries value.");
+ 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.");
+ } catch (NumberFormatException ex) {
+ out.println("Invalid retries value.");
}
}
}
else if (cmd.equals(STATUS_CMD)) { // status
if (serverAddress != null) {
- System.out.println("Connected to "+serverAddress.getHostName() + ".");
+ out.println("Connected to " + serverAddress.getHostName() + ".");
}
else {
- System.out.println("Not connected.");
+ out.println("Not connected.");
}
if (mode == ASCII_MODE) {
- System.out.print("mode: ASCII");
+ out.print("mode: ASCII");
}
else if (mode == BINARY_MODE) {
- System.out.print("mode: BINARY");
+ out.print("mode: BINARY");
}
- System.out.print(" timeout: " + getDefaultTimeout());
- System.out.println(" retries: " + getMaxTimeouts());
+ out.print(" timeout: " + getDefaultTimeout());
+ 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");
+ out.println(ASCII_CMD + " - set mode to ASCII");
+ out.println(CONNECT_CMD + " - connect to a tftp server");
+ out.println(BINARY_CMD + " - set mode to binary");
+ out.println(GET_CMD + " - receive file");
+ out.println(HELP_CMD + " - display this help");
+ out.println(PUT_CMD + " - send file");
+ out.println(QUIT_CMD + " - exit");
+ out.println(RETRIES_CMD + " - set retries");
+ out.println(STATUS_CMD + " - display current status");
+ out.println(TIMEOUT_CMD + " - set timeout");
success = true;
}
else if (cmd.equals(QUIT_CMD)) { // quit
@@ -277,8 +237,14 @@
success = true;
}
else {
- System.out.println("Unrecognised command.");
+ out.println("Unrecognised command.");
}
return success;
}
+
+ private void diagnose(IOException ex, String message) {
+ String exMessage = ex.getClass().getSimpleName() + " - " + ex.getLocalizedMessage();
+ out.println(message + ": " + exMessage);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cr...@us...> - 2008-05-14 11:26:27
|
Revision: 4098
http://jnode.svn.sourceforge.net/jnode/?rev=4098&view=rev
Author: crawley
Date: 2008-05-14 04:26:16 -0700 (Wed, 14 May 2008)
Log Message:
-----------
Converted WlanCtlCommand
Modified Paths:
--------------
trunk/net/descriptors/org.jnode.net.command.xml
trunk/net/src/net/org/jnode/net/command/WLanCtlCommand.java
Modified: trunk/net/descriptors/org.jnode.net.command.xml
===================================================================
--- trunk/net/descriptors/org.jnode.net.command.xml 2008-05-13 14:34:54 UTC (rev 4097)
+++ trunk/net/descriptors/org.jnode.net.command.xml 2008-05-14 11:26:16 UTC (rev 4098)
@@ -110,6 +110,13 @@
<argument argLabel="filename"/>
</sequence>
</syntax>
+ <syntax alias="wlanctl">
+ <sequence description="Set the ESSID for a WLan device">
+ <option argLabel="setEssid" longName="setessid"/>
+ <argument argLabel="device"/>
+ <argument argLabel="value"/>
+ </sequence>
+ </syntax>
</extension>
<extension point="org.jnode.security.permissions">
Modified: trunk/net/src/net/org/jnode/net/command/WLanCtlCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/WLanCtlCommand.java 2008-05-13 14:34:54 UTC (rev 4097)
+++ trunk/net/src/net/org/jnode/net/command/WLanCtlCommand.java 2008-05-14 11:26:16 UTC (rev 4098)
@@ -24,86 +24,53 @@
import java.io.InputStream;
import java.io.PrintStream;
-import org.apache.log4j.Logger;
import org.jnode.driver.ApiNotFoundException;
import org.jnode.driver.Device;
import org.jnode.driver.net.NetworkException;
import org.jnode.driver.net.WirelessNetDeviceAPI;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Argument;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.SyntaxErrorException;
-import org.jnode.shell.help.argument.DeviceArgument;
-import org.jnode.shell.help.argument.OptionArgument;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.DeviceArgument;
+import org.jnode.shell.syntax.FlagArgument;
+import org.jnode.shell.syntax.StringArgument;
/**
* @author Ewout Prangsma (ep...@us...)
+ * @author cr...@jn...
*/
public class WLanCtlCommand extends AbstractCommand {
- private static final String FUNC_SETESSID = "setessid";
+ private final FlagArgument FLAG_SET_ESSID = new FlagArgument(
+ "setEssid", Argument.OPTIONAL, "if set, set the ESSID");
- private static final OptionArgument ARG_FUNCTION = new OptionArgument(
- "function", "the function to perform",
- new OptionArgument.Option[] { new OptionArgument.Option(
- FUNC_SETESSID, "Set the ESSID"), });
+ private final DeviceArgument ARG_DEVICE = new DeviceArgument(
+ "device", Argument.MANDATORY, "the device to be operated on", WirelessNetDeviceAPI.class);
- private static final DeviceArgument ARG_DEVICE = new DeviceArgument(
- "device", "the device to control", WirelessNetDeviceAPI.class);
+ private final StringArgument ARG_VALUE = new StringArgument(
+ "value", Argument.OPTIONAL, "the value to use in the operation");
+
+
+ public WLanCtlCommand() {
+ super("Manage a WLan device");
+ registerArguments(FLAG_SET_ESSID, ARG_DEVICE, ARG_VALUE);
+ }
- private static final Argument ARG_VALUE = new Argument("value",
- "Value of the function");
-
- public static Help.Info HELP_INFO = new Help.Info("wlanctl",
- "Try to configure the given device using BOOTP", new Parameter[] {
- new Parameter(ARG_FUNCTION, Parameter.MANDATORY),
- new Parameter(ARG_DEVICE, Parameter.MANDATORY),
- new Parameter(ARG_VALUE, Parameter.OPTIONAL) });
-
- private static final Logger log = Logger.getLogger(HELP_INFO.getName());
-
- public static void main(String[] args) throws Exception, SyntaxErrorException {
+ public static void main(String[] args) throws Exception {
new WLanCtlCommand().execute(args);
}
- private static void setESSID(Device dev, WirelessNetDeviceAPI api,
- ParsedArguments cmdLine) throws NetworkException {
- final String essid = ARG_VALUE.getValue(cmdLine);
- System.out.println("Setting ESSID on " + dev.getId() + " to " + essid);
- api.setESSID(essid);
- }
-
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception {
- ParsedArguments cmdLine = HELP_INFO.parse(commandLine);
-
- final Device dev = ARG_DEVICE.getDevice(cmdLine);
+ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ throws ApiNotFoundException, NetworkException {
+ final Device dev = ARG_DEVICE.getValue();
final WirelessNetDeviceAPI api;
- try {
- api = (WirelessNetDeviceAPI) dev.getAPI(WirelessNetDeviceAPI.class);
- } catch (ApiNotFoundException e) {
- System.err.println("Device " + dev.getId()
- + " is not a wireless network device");
- exit(2);
- return; // not reached
- }
+ api = (WirelessNetDeviceAPI) dev.getAPI(WirelessNetDeviceAPI.class);
- // Get the function
- final String function = ARG_FUNCTION.getValue(cmdLine);
- try {
- if (function.equals(FUNC_SETESSID)) {
- setESSID(dev, api, cmdLine);
- } else {
- System.err.println("Unknown function " + function);
- exit(3);
- }
- } catch (NetworkException ex) {
- System.err.println("Function " + function + " failed: "
- + ex.getMessage());
- log.debug("Function " + function + " failed", ex);
- exit(1);
+ // Perform the selected operation
+ if (FLAG_SET_ESSID.isSet()) {
+ final String essid = ARG_VALUE.getValue();
+ out.println("Setting ESSID on " + dev.getId() + " to " + essid);
+ api.setESSID(essid);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|