@@ -59,7 +59,8 @@ public class ZigBeeSniffer {
59
59
static Integer channelRotationRangeStart ;
60
60
static Integer channelRotationRangeEnd ;
61
61
static Long lastChannelRotationTimestamp ;
62
- static int clientPort ;
62
+ static int sourcePort ;
63
+ static int destinationPort ;
63
64
static DatagramSocket client ;
64
65
static InetAddress address ;
65
66
static SilabsIsdLogFile isdFile ;
@@ -89,7 +90,7 @@ public static void main(final String[] args) {
89
90
90
91
Options options = new Options ();
91
92
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 ());
93
94
options .addOption (
94
95
Option .builder ("b" ).longOpt ("baud" ).hasArg ().argName ("baud" ).desc ("Set the port baud rate" ).build ());
95
96
options .addOption (Option .builder ("f" ).longOpt ("flow" ).hasArg ().argName ("type" )
@@ -104,8 +105,10 @@ public static void main(final String[] args) {
104
105
.desc ("Set the channel rotation range end" ).build ());
105
106
options .addOption (Option .builder ("a" ).longOpt ("ipaddr" ).hasArg ().argName ("remote IP address" )
106
107
.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 ());
109
112
options .addOption (Option .builder ("s" ).longOpt ("silabs" ).hasArg ().argName ("filename" )
110
113
.desc ("Log data to a Silabs ISD compatible event log" ).build ());
111
114
options .addOption (Option .builder ("w" ).longOpt ("pcap" ).hasArg ().argName ("filename" )
@@ -192,19 +195,26 @@ public static void main(final String[] args) {
192
195
pcapFile = null ;
193
196
}
194
197
198
+ if (cmdline .hasOption ("dport" )) {
199
+ destinationPort = parseDecimalOrHexInt (cmdline .getOptionValue ("dport" ));
200
+ } else {
201
+ destinationPort = ZEP_UDP_PORT ;
202
+ }
203
+
195
204
try {
196
205
if (cmdline .hasOption ("ipaddr" )) {
197
206
address = InetAddress .getByName (cmdline .getOptionValue ("ipaddr" ));
198
207
} else {
199
208
address = InetAddress .getByName ("127.0.0.1" );
200
209
}
201
210
202
- if (cmdline .hasOption ("ipport " )) {
203
- clientPort = parseDecimalOrHexInt (cmdline .getOptionValue ("ipport " ));
211
+ if (cmdline .hasOption ("sport " )) {
212
+ sourcePort = parseDecimalOrHexInt (cmdline .getOptionValue ("sport " ));
204
213
} else {
205
- clientPort = ZEP_UDP_PORT ;
214
+ sourcePort = ZEP_UDP_PORT ;
206
215
}
207
- client = new DatagramSocket (ZEP_UDP_PORT );
216
+
217
+ client = new DatagramSocket (sourcePort );
208
218
} catch (IOException e ) {
209
219
e .printStackTrace ();
210
220
return ;
@@ -257,7 +267,7 @@ public static void main(final String[] args) {
257
267
}
258
268
259
269
System .out .println ("NCP initialisation complete..." );
260
- System .out .println ("Wireshark destination : " + address + ":" + clientPort );
270
+ System .out .println ("Wireshark destination : " + address + ":" + destinationPort );
261
271
if (channelRotationIntervalMillis != null ) {
262
272
System .out .println ("Scanning channel range : range = [" + channelRotationRangeStart
263
273
+ " , " + channelRotationRangeEnd + "] , interval = " + channelRotationIntervalMillis
@@ -348,7 +358,7 @@ private static void packetReceived(int sequence, int lqi, int rssi, int[] data)
348
358
System .out .println (zepFrame );
349
359
350
360
byte [] buffer = zepFrame .getBuffer ();
351
- DatagramPacket packet = new DatagramPacket (buffer , buffer .length , address , clientPort );
361
+ DatagramPacket packet = new DatagramPacket (buffer , buffer .length , address , destinationPort );
352
362
try {
353
363
client .send (packet );
354
364
} catch (IOException e ) {
0 commit comments