-all_frames=( $(cat $tmpdir/diameter_frames | cut -d\| -f1) )
-needs_join=( $(cat $tmpdir/diameter_frames | cut -d\| -f18) )
+cat $tmpdir/diameter_frames | cut -d\| -f1 > $tmpdir/frames_num
+all_frames=( $(cat $tmpdir/frames_num) )
+
+# Segments groups (TCP or SCTP):
+segmentsGroups=
+
+# The case of SCTP is precalculated:
+tshark -nr $PCAP_FILE $DISECT_SELECTORS -Tfields -e frame.number -e sctp.chunk_flags 2>/dev/null | awk '{ if ( $2 !~ "0x03" && $2 != "" ) print $1 }' > $tmpdir/extra_frames_num
+if [ -s $tmpdir/extra_frames_num ]
+then
+ # Take into account these frames in all_frames array:
+
+ cat $tmpdir/extra_frames_num >> $tmpdir/frames_num
+ all_frames=( $(cat $tmpdir/frames_num | sort -un) )
+
+ # Prepare as groups (1,2 7,8 ...)
+ segmentsGroups=$(tshark -nr $PCAP_FILE $DISECT_SELECTORS -Tfields -e frame.number -e sctp.chunk_flags 2>/dev/null | awk '{ if ( $2 !~ "0x03" && $2 != "" ) print $1; else print "\n" }' | uniq | tr '\n' ',' | sed 's/,,/ /g')
+fi
+