Environment variable to be more flexible
[anna.git] / example / diameter / pcapDecoder / tsharkDecoder.sh
index 64fd44b..b6c98aa 100755 (executable)
@@ -42,6 +42,7 @@
 # VARIABLES #
 #############
 tmpdir=$(mktemp -d)
+[ -z "$TSHARK_DECODER_NON_STANDARD_PORTS" ] && TSHARK_DECODER_NON_STANDARD_PORTS="13868"
 
 #############
 # FUNCTIONS #
@@ -60,6 +61,13 @@ usage () {
   echo "          <results_dir>/<frame sequence>.hex"
   echo "          <results_dir>/<frame sequence>.metadata"
   echo
+  echo
+  echo "       TSHARK_DECODER_NON_STANDARD_PORTS: environment variable"
+  echo "       defined as a space-separated list of ports which frames"
+  echo "       will be decoded as diameter protocol. By default, \"13868\""
+  echo "       is used when the variable has not been exported in shell,"
+  echo "       in order to disect the Ericsson Sy variant."
+  echo
   _exit
 }
 
@@ -107,7 +115,13 @@ RESULTS_DIR=`dirname $PCAP_FILE`
 # Fields needed (we won't need diameter.hopbyhopid & diameter.endtoendid to verify diameter message as hint patterns; length management will be enough):
 FIELDS_DIAMETER="-e diameter.cmd.code -e diameter.flags.request -e diameter.applicationId -e diameter.hopbyhopid -e diameter.endtoendid -e diameter.length"
 FIELDS="-e frame.number -e frame.time_epoch -e ip.src_host -e ip.dst_host $FIELDS_DIAMETER -e tcp.len -e frame.protocols -e tcp.segment"
-tshark -E separator="|" -r $PCAP_FILE -N mntC -Tfields $FIELDS 2>/dev/null | grep -i diameter > $tmpdir/diameter_frames
+# Disect selectors for non-standard diameter ports:
+for port in $TSHARK_DECODER_NON_STANDARD_PORTS
+do
+  DISECT_SELECTORS="$DISECT_SELECTORS -d tcp.port=$port,diameter"
+done
+
+tshark -E separator="|" -r $PCAP_FILE -N mntC -Tfields $FIELDS $DISECT_SELECTORS 2>/dev/null | grep -i diameter > $tmpdir/diameter_frames
 # Example output:
 #                                                                               /length\
 # frame     timestamp        src     dst   code R  App-ID   HopByHop   EndToEnd DIAM TCP          protocol                         segments