Permalink
Browse files

Added in check for correct interface argument

  • Loading branch information...
1 parent d62395d commit 5cfa22a5dc172fccb1b43a3dd4b7c4d26e0ace87 @nickpoorman committed May 5, 2011
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -23,7 +23,7 @@ public static void main(String[] args) {
int port = 8090;
for (int i = 0; i < 4; i++) {
- SocketAddress receiverAddress = new InetSocketAddress("129.3.113.68", port + i);
+ SocketAddress receiverAddress = new InetSocketAddress("127.0.0.1", port + i);
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, receiverAddress);
datagramSocket.send(packet);
@@ -3,7 +3,7 @@
*
* The arguments for this program are as follows:
* -i<interface number>
- * -
+ * -p<comma separated port sequence>
*
*/
@@ -50,30 +50,36 @@ public static void main(String[] args) {
// NICs
StringBuilder errbuf = new StringBuilder(); // For any error msgs
+ // get a list of devices
+ int r = Pcap.findAllDevs(alldevs, errbuf);
+ if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
+ System.err.printf("Can't read list of devices, error is %s", errbuf.toString());
+ return;
+ }
+
// look for interface
String interfaceNum = Server.findArgument(Server.INTERFACE_SWITCH, args);
if (interfaceNum == "") {
+ System.out.println("DIDNT MAKE IT");
System.out.println(Server.PARAMS_ERROR);
-
- /***************************************************************************
- * First get a list of devices on this system
- **************************************************************************/
- int r = Pcap.findAllDevs(alldevs, errbuf);
- if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
- System.err.printf("Can't read list of devices, error is %s", errbuf.toString());
- return;
- }
-
- System.out.println("Network devices found:");
-
+ System.out.println("Network Devices Found: ");
int i = 0;
for (PcapIf device : alldevs) {
System.out.printf("#%d: %s [%s]\n", i++, device.getName(), device.getDescription());
}
}
- PcapIf device = alldevs.get(Integer.parseInt(interfaceNum)); // Pick one
+ int chosenInterface = -1;
+ try {
+ chosenInterface = Integer.parseInt(interfaceNum);
+
+ } catch (NumberFormatException e) {
+ System.err.println("[" + interfaceNum + "]" + "is not a valid interface number.");
+ return;
+ }
+
+ PcapIf device = alldevs.get(chosenInterface); // Pick one
System.out.printf("\nUsing interface 0 '%s':\n", device.getDescription());
/***************************************************************************
@@ -145,7 +151,7 @@ public void nextPacket(JPacket packet, String user) {
// open a reverse connection to the source host
ReverseConnection rc = new ReverseConnection(ksm.getSource());
Thread t = new Thread(rc);
- t.start();
+ t.start();u
} else {
System.out.println("Packet is Not a new connection");
}

0 comments on commit 5cfa22a

Please sign in to comment.