blob: 10e8ab484f8f113f8219e3cb2a6260b82677a673 [file] [log] [blame]
Harald Weltee0571462018-02-14 15:42:14 +01001#!/bin/sh
2
3PIDFILE=/tmp/tcpdump.pid
4TESTCASE=$1
5
6if [ "z$TTCN3_PCAP_PATH" = "z" ]; then
7 TTCN3_PCAP_PATH=/tmp
8fi
9
10if [ -e $PIDFILE ]; then
11 kill "$(cat "$PIDFILE")"
12 rm $PIDFILE
13fi
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
17if [ "$(id -u)" = "0" ]; then
18 CMD=/usr/sbin/tcpdump
19else
20 CMD="sudo /usr/sbin/tcpdump"
21fi
Pau Espin Pedrolef598552018-02-15 14:25:47 +010022$CMD -s 0 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$TTCN3_PCAP_PATH/$TESTCASE.pcap.log 2>&1 &
Harald Weltee0571462018-02-14 15:42:14 +010023PID=$!
24echo $PID > $PIDFILE
Pau Espin Pedrolb01d3132018-02-15 14:43:58 +010025
26# Wait until tcpdump creates the pcap file to give it some time to start listenting.
27# Timeout is 10 seconds.
28i=0
29while [ ! -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap" ] && [ $i -lt 10 ]
30do
31 echo "Waiting for tcpdump to start... $i"
32 sleep 1
33 i=$((i+1))
34done