[wifi] capture: fix invoke_tcpdump()
When the number of packets captured was >0, set -e stopped the program as invoke_tcpdump() returned a non-zero value. This is fixed by using echo instead of return. Some messages improved, too.
This commit is contained in:
parent
a1f0a747a8
commit
a9cfd31217
|
@ -49,10 +49,10 @@ CHANNEL=1
|
|||
|
||||
## Functions ##
|
||||
|
||||
# Displays the message in argument and exits
|
||||
# Displays the message in argument on the error output and exits
|
||||
error()
|
||||
{
|
||||
echo "$1"
|
||||
echo "$1" >&2
|
||||
clean
|
||||
exit 1
|
||||
}
|
||||
|
@ -141,17 +141,21 @@ iface_up()
|
|||
|| error "Cannot turn the interface up!"
|
||||
}
|
||||
|
||||
# Invokes tcpdump and returns the number of packets captured
|
||||
# Invokes tcpdump and displays the number of packets captured
|
||||
invoke_tcpdump()
|
||||
{
|
||||
return $(tcpdump -i $IFACE -c $NB_PKT -w "$FILE" 2>&1 \
|
||||
| sed -n 's/ packets captured$//p')
|
||||
NCAP=$(tcpdump -i $IFACE -c $NB_PKT -w "$FILE" 2>&1 \
|
||||
| sed -nr 's/([[:digit:]]+) packets captured$/\1/p')
|
||||
[ "$NCAP" = "" ] \
|
||||
&& error "Error parsing the tcpdump messages! (NCAP=\"$NCAP\")"
|
||||
echo $NCAP
|
||||
}
|
||||
|
||||
# Waits for a number of seconds, then kills any tcpdump process
|
||||
wait_tcpdump()
|
||||
{
|
||||
sleep $1
|
||||
echo "$1 seconds passed, killing all tcpdump processes..."
|
||||
pkill tcpdump
|
||||
}
|
||||
|
||||
|
@ -228,16 +232,16 @@ while [ $CAPTURED -eq 0 -a $CHANNEL -le 14 ] ; do
|
|||
echo
|
||||
iface_set_channel $CHANNEL
|
||||
wait_tcpdump $TIMEOUT &
|
||||
invoke_tcpdump
|
||||
CAPTURED=$?
|
||||
CAPTURED=$(invoke_tcpdump)
|
||||
[ $CAPTURED -eq 0 ] \
|
||||
&& echo "No packet captured on channel $CHANNEL."
|
||||
&& echo "No packet captured on channel $CHANNEL." \
|
||||
|| echo "$CAPTURED packets captured on channel $CHANNEL."
|
||||
CHANNEL=`expr $CHANNEL + 1`
|
||||
done
|
||||
|
||||
echo
|
||||
[ $CAPTURED -gt 0 ] \
|
||||
&& echo "Capture file \"$FILE\" created with $CAPTURED packets." \
|
||||
&& echo "Capture file \"$FILE\" created." \
|
||||
|| error "Failed to capture any packet!"
|
||||
|
||||
gather_system_information
|
||||
|
|
Loading…
Reference in New Issue