3 # A small script to export some variables and run tshark or wireshark in
4 # valgrind on a given capture file.
6 # Copyright 2012 Jeff Morriss <jeff.morriss.ws [AT] gmail.com>
8 # Wireshark - Network traffic analyzer
9 # By Gerald Combs <gerald@wireshark.org>
10 # Copyright 1998 Gerald Combs
12 # SPDX-License-Identifier: GPL-2.0-or-later
14 # Directory containing tshark or wireshark. Default current directory.
15 if [ -z "$WIRESHARK_BIN_DIR" ]; then
19 # Use tshark by default
27 while getopts ":2a:b:C:lmnpP:rstTYwcevWdG" OPTCHAR ; do
29 2) COMMAND_ARGS="-2 $COMMAND_ARGS" ;;
30 a) ADDITIONAL_SUPPRESSION_FILE="$ADDITIONAL_SUPPRESSION_FILE --suppressions=$OPTARG" ;;
31 b) WIRESHARK_BIN_DIR=$OPTARG ;;
32 C) COMMAND_ARGS="-C $OPTARG $COMMAND_ARGS" ;;
33 l) LEAK_CHECK="--leak-check=full" ;;
37 p) TOOL="callgrind" ;;
39 CALLGRIND_OUT_FILE="--callgrind-out-file=$OPTARG" ;;
40 r) REACHABLE="--show-reachable=yes" ;;
41 s) GEN_SUPPRESSIONS="--gen-suppressions=yes" ;;
42 t) TRACK_ORIGINS="--track-origins=yes" ;;
43 T) COMMAND_ARGS="-Vx $COMMAND_ARGS" ;; # "build the Tree"
44 Y) COMMAND_ARGS="-Y frame $COMMAND_ARGS" ;; # Run with a read filter (but no tree)
50 COMMAND_ARGS="-E 0.02"
51 # We don't care about the output of editcap
52 COMMAND_ARGS2="/dev/null" ;;
53 v) VERBOSE="--num-callers=256 -v" ;;
57 G) COMMAND=wireshark-gtk
61 COMMAND_ARGS="-i eth1 -c 3000"
63 *) printf "Unknown option -$OPTARG!\n"
67 shift $(($OPTIND - 1))
70 if [ "$COMMAND" != "tshark" ] && [[ $COMMAND_ARGS =~ Vx ]]
72 printf "\nYou can't use -T if you're not using tshark\n\n" >&2
84 printf "\nUsage: $(basename $0) [-2] [-a file] [-b bin_dir] [-c] [-e] [-C config_profile] "
85 printf "[-l] [-m] [-n] [-p] [-r] [-s] [-t] [-T] [-w] [-v] /path/to/file.pcap\n"
87 printf "[-2]: run tshark with 2-pass analysis\n"
88 printf "[-a]: additional valgrind suppression file\n"
89 printf "[-b]: tshark binary dir\n"
90 printf "[-e]: use 'editcap -E 0.02' instead of tshark\n"
91 printf "[-c]: use capinfos instead of tshark\n"
92 printf "[-C]: binary profile file\n"
93 printf "[-l]: add valgrind option --leak-check=full\n"
94 printf "[-m]: use valgrind massif tool\n"
95 printf "[-n]: print binary version\n"
96 printf "[-p]: use callgrind massif tool\n"
97 printf "[-r]: add valgrind option --show-reachable=yes\n"
98 printf "[-s]: add valgrind option --gen-suppressions=yes\n"
99 printf "[-t]: add valgrind option --track-origins=yes\n"
100 printf "[-T]: build the tshark tree (-Vx)\n"
101 printf "[-w]: use wireshark instead of tshark\n"
102 printf "[-v]: run in verbose mode (--num-callers=256)\n"
106 if [ "$WIRESHARK_BIN_DIR" = "." ]; then
107 export WIRESHARK_RUN_FROM_BUILD_DIRECTORY=
110 if [ "$TOOL" != "callgrind" ]; then
111 export WIRESHARK_DEBUG_WMEM_OVERRIDE=simple
112 export G_SLICE=always-malloc # or debug-blocks
115 COMMAND="$WIRESHARK_BIN_DIR/$COMMAND"
117 if file $COMMAND | grep -q "ASCII text"; then
118 if [ -x "`dirname $0`/../libtool" ]; then
119 LIBTOOL="`dirname $0`/../libtool"
123 LIBTOOL="$LIBTOOL --mode=execute"
128 cmdline="$LIBTOOL valgrind --suppressions=`dirname $0`/vg-suppressions $ADDITIONAL_SUPPRESSION_FILE \
129 --suppressions=`dirname $0`/gtk.suppression \
130 --tool=$TOOL $CALLGRIND_OUT_FILE $VERBOSE $LEAK_CHECK $REACHABLE $GEN_SUPPRESSIONS $TRACK_ORIGINS \
131 $COMMAND $COMMAND_ARGS $PCAP $COMMAND_ARGS2"
133 if [ "$VERBOSE" != "" ];then
134 echo -e "\n$cmdline\n"