5 # Randpkt testing script for TShark
7 # This script uses Randpkt to generate capture files with randomized
8 # content. It runs TShark on each generated file and checks for errors.
9 # The files are processed repeatedly until an error is found.
11 # Tweak the following to your liking.
15 # This needs to point to a 'date' that supports %s.
17 BASE_NAME=randpkt-`$DATE +%Y-%m-%d`-$$
19 # Temporary file directory and names.
20 # (had problems with this on cygwin, tried TMP_DIR=./ which worked)
22 TMP_FILE=$BASE_NAME.pcap
23 ERR_FILE=$BASE_NAME.err
25 # Loop this many times (< 1 loops forever)
28 # These may be set to your liking
29 # Stop the child process, if it's running longer than x seconds
31 # Stop the child process, if it's using more than y * 1024 bytes
33 # Trigger an abort if a dissector finds a bug.
34 # Uncomment to disable
35 WIRESHARK_ABORT_ON_DISSECTOR_BUG="True"
37 PKT_TYPES=`$RANDPKT -h | awk '/^\t/ {print $1}'`
39 # To do: add options for file names and limits
40 while getopts ":d:p:t:" OPTCHAR ; do
43 p) MAX_PASSES=$OPTARG ;;
44 t) PKT_TYPES=$OPTARG ;;
47 shift $(($OPTIND - 1))
49 # set some limits to the child processes, e.g. stop it if it's running longer then MAX_CPU_TIME seconds
50 # (ulimit is not supported well on cygwin and probably other platforms, e.g. cygwin shows some warnings)
51 ulimit -S -t $MAX_CPU_TIME -v $MAX_VMEM
54 ### usually you won't have to change anything below this line ###
56 # TShark arguments (you won't have to change these)
57 # n Disable network object name resolution
58 # V Print a view of the details of the packet rather than a one-line summary of the packet
59 # x Cause TShark to print a hex and ASCII dump of the packet data after printing the summary or details
60 # r Read packet data from the following infile
62 RANDPKT_ARGS="-b 2000 -c 5000"
65 for i in "$TSHARK" "$RANDPKT" "$DATE" "$TMP_DIR" ; do
67 echo "Couldn't find $i"
71 if [ $NOTFOUND -eq 1 ]; then
76 if [ $MAX_PASSES -gt 0 ]; then
77 HOWMANY="$MAX_PASSES passes"
79 echo "Running $TSHARK with args: $TSHARK_ARGS ($HOWMANY)"
80 echo "Running $RANDPKT with args: $RANDPKT_ARGS"
83 # Not yet - properly handle empty filenames
84 #trap "rm $TMP_DIR/$TMP_FILE $TMP_DIR/$RAND_FILE; exit 1" 1 2 15
86 # Iterate over our capture files.
88 while [ $PASS -lt $MAX_PASSES -o $MAX_PASSES -lt 1 ] ; do
92 for PKT_TYPE in $PKT_TYPES ; do
93 echo -n " $PKT_TYPE: "
97 "$RANDPKT" $RANDPKT_ARGS -t $PKT_TYPE $TMP_DIR/$TMP_FILE \
100 "$TSHARK" $TSHARK_ARGS $TMP_DIR/$TMP_FILE \
101 > /dev/null 2> $TMP_DIR/$ERR_FILE
103 grep -i "dissector bug" $TMP_DIR/$ERR_FILE \
104 > /dev/null 2>&1 && DISSECTOR_BUG=1
105 if [ $RETVAL -ne 0 -o $DISSECTOR_BUG -ne 0 ] ; then
106 RAND_FILE="rand-`$DATE +%Y-%m-%d`-$$.pcap"
109 echo -e "Processing failed. Capture info follows:\n"
110 mv $TMP_DIR/$TMP_FILE $TMP_DIR/$RAND_FILE
111 echo " Output file: $TMP_DIR/$RAND_FILE"
112 if [ $DISSECTOR_BUG -ne 0 ] ; then
113 echo -e "stderr follows:\n"
114 cat $TMP_DIR/$ERR_FILE
119 rm -f $TMP_DIR/$TMP_FILE $TMP_DIR/$ERR_FILE