Harald Welte | e057146 | 2018-02-14 15:42:14 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | PIDFILE=/tmp/tcpdump.pid |
| 4 | TESTCASE=$1 |
| 5 | |
| 6 | if [ "z$TTCN3_PCAP_PATH" = "z" ]; then |
| 7 | TTCN3_PCAP_PATH=/tmp |
| 8 | fi |
| 9 | |
| 10 | if [ -e $PIDFILE ]; then |
| 11 | kill "$(cat "$PIDFILE")" |
| 12 | rm $PIDFILE |
| 13 | fi |
| 14 | |
| 15 | # NOTE: This requires you to be root or something like |
| 16 | # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file |
| 17 | if [ "$(id -u)" = "0" ]; then |
| 18 | CMD=/usr/sbin/tcpdump |
| 19 | else |
| 20 | CMD="sudo /usr/sbin/tcpdump" |
| 21 | fi |
Pau Espin Pedrol | ef59855 | 2018-02-15 14:25:47 +0100 | [diff] [blame] | 22 | $CMD -s 0 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$TTCN3_PCAP_PATH/$TESTCASE.pcap.log 2>&1 & |
Harald Welte | e057146 | 2018-02-14 15:42:14 +0100 | [diff] [blame] | 23 | PID=$! |
| 24 | echo $PID > $PIDFILE |
Pau Espin Pedrol | b01d313 | 2018-02-15 14:43:58 +0100 | [diff] [blame^] | 25 | |
| 26 | # Wait until tcpdump creates the pcap file to give it some time to start listenting. |
| 27 | # Timeout is 10 seconds. |
| 28 | i=0 |
| 29 | while [ ! -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap" ] && [ $i -lt 10 ] |
| 30 | do |
| 31 | echo "Waiting for tcpdump to start... $i" |
| 32 | sleep 1 |
| 33 | i=$((i+1)) |
| 34 | done |