Skip to content

Commit cf0ad8e

Browse files
authored
use separate arguments for source and destination ports (#28)
* use separate arguments for source and destination ports * backward compatibility
1 parent b096512 commit cf0ad8e

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/main/java/com/zsmartsystems/zigbee/sniffer/ZigBeeSniffer.java

+20-10
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public class ZigBeeSniffer {
5959
static Integer channelRotationRangeStart;
6060
static Integer channelRotationRangeEnd;
6161
static Long lastChannelRotationTimestamp;
62-
static int clientPort;
62+
static int sourcePort;
63+
static int destinationPort;
6364
static DatagramSocket client;
6465
static InetAddress address;
6566
static SilabsIsdLogFile isdFile;
@@ -89,7 +90,7 @@ public static void main(final String[] args) {
8990

9091
Options options = new Options();
9192
options.addOption(
92-
Option.builder("p").longOpt("port").argName("port name").hasArg().desc("Set the port").build());
93+
Option.builder("p").longOpt("port").argName("port name").hasArg().desc("Set the serial port").build());
9394
options.addOption(
9495
Option.builder("b").longOpt("baud").hasArg().argName("baud").desc("Set the port baud rate").build());
9596
options.addOption(Option.builder("f").longOpt("flow").hasArg().argName("type")
@@ -104,8 +105,10 @@ public static void main(final String[] args) {
104105
.desc("Set the channel rotation range end").build());
105106
options.addOption(Option.builder("a").longOpt("ipaddr").hasArg().argName("remote IP address")
106107
.desc("Set the remote IP address").build());
107-
options.addOption(Option.builder("r").longOpt("ipport").hasArg().argName("remote IP port")
108-
.desc("Set the remote IP port").build());
108+
options.addOption(Option.builder("k").longOpt("sport").hasArg().argName("source port")
109+
.desc("Set the UDP source port (use 0 to let the system choose)").build());
110+
options.addOption(Option.builder("r").longOpt("dport").hasArg().argName("destination port")
111+
.desc("Set the UDP destination port").build());
109112
options.addOption(Option.builder("s").longOpt("silabs").hasArg().argName("filename")
110113
.desc("Log data to a Silabs ISD compatible event log").build());
111114
options.addOption(Option.builder("w").longOpt("pcap").hasArg().argName("filename")
@@ -192,19 +195,26 @@ public static void main(final String[] args) {
192195
pcapFile = null;
193196
}
194197

198+
if (cmdline.hasOption("dport")) {
199+
destinationPort = parseDecimalOrHexInt(cmdline.getOptionValue("dport"));
200+
} else {
201+
destinationPort = ZEP_UDP_PORT;
202+
}
203+
195204
try {
196205
if (cmdline.hasOption("ipaddr")) {
197206
address = InetAddress.getByName(cmdline.getOptionValue("ipaddr"));
198207
} else {
199208
address = InetAddress.getByName("127.0.0.1");
200209
}
201210

202-
if (cmdline.hasOption("ipport")) {
203-
clientPort = parseDecimalOrHexInt(cmdline.getOptionValue("ipport"));
211+
if (cmdline.hasOption("sport")) {
212+
sourcePort = parseDecimalOrHexInt(cmdline.getOptionValue("sport"));
204213
} else {
205-
clientPort = ZEP_UDP_PORT;
214+
sourcePort = ZEP_UDP_PORT;
206215
}
207-
client = new DatagramSocket(ZEP_UDP_PORT);
216+
217+
client = new DatagramSocket(sourcePort);
208218
} catch (IOException e) {
209219
e.printStackTrace();
210220
return;
@@ -257,7 +267,7 @@ public static void main(final String[] args) {
257267
}
258268

259269
System.out.println("NCP initialisation complete...");
260-
System.out.println("Wireshark destination : " + address + ":" + clientPort);
270+
System.out.println("Wireshark destination : " + address + ":" + destinationPort);
261271
if (channelRotationIntervalMillis != null) {
262272
System.out.println("Scanning channel range : range = [" + channelRotationRangeStart
263273
+ " , " + channelRotationRangeEnd + "] , interval = " + channelRotationIntervalMillis
@@ -348,7 +358,7 @@ private static void packetReceived(int sequence, int lqi, int rssi, int[] data)
348358
System.out.println(zepFrame);
349359

350360
byte[] buffer = zepFrame.getBuffer();
351-
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, address, clientPort);
361+
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, address, destinationPort);
352362
try {
353363
client.send(packet);
354364
} catch (IOException e) {

0 commit comments

Comments
 (0)