Fix test_monitor_tshark.sh to always show counters
- Add message that capture may take time - Always display packet and PLCP counts - Better parsing of tshark output - Separate warnings/errors from packet data - Show note if packets captured but no PLCP headers Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
cc180b7868
commit
b80a9d818b
|
|
@ -80,36 +80,35 @@ iw dev "$INTERFACE" info | grep -E "(type|channel)" || echo "Could not verify"
|
|||
# Check DLT with tshark (capture for 1 second)
|
||||
echo ""
|
||||
echo "Checking Data Link Type (1 second test capture)..."
|
||||
# First check if we can open the interface
|
||||
DLT_CHECK=$(tshark -i "$INTERFACE" -T fields -e frame.number -c 0 2>&1 | head -1)
|
||||
if echo "$DLT_CHECK" | grep -q "Running as"; then
|
||||
echo "$DLT_CHECK"
|
||||
fi
|
||||
echo "(This may take up to 2 seconds if no packets are present)"
|
||||
|
||||
# Use -c to limit packets and add immediate output, redirect stderr to see warnings
|
||||
# Use a shorter timeout and limit packets to avoid hanging
|
||||
TEST_OUTPUT=$(timeout 2 tshark -i "$INTERFACE" -c 100 -T fields -e frame.number -e radiotap.present 2>&1 || echo "")
|
||||
TEST_EXIT_CODE=$?
|
||||
# Use timeout with -c to limit packets and avoid hanging
|
||||
# Capture both stdout and stderr
|
||||
TEST_OUTPUT=$(timeout 2 tshark -i "$INTERFACE" -c 100 -T fields -e frame.number -e radiotap.present 2>&1 || true)
|
||||
TEST_EXIT_CODE=${PIPESTATUS[0]}
|
||||
|
||||
# Show any warnings/errors from tshark
|
||||
echo "$TEST_OUTPUT" | grep -E "(Running as|tshark:|Warning|Error)" || true
|
||||
# Show any warnings/errors from tshark (but not packet data)
|
||||
echo "$TEST_OUTPUT" | grep -E "(Running as|tshark:|Warning|Error|Capturing)" || true
|
||||
|
||||
# Count packets (lines starting with a number, excluding error messages)
|
||||
PACKET_LINES=$(echo "$TEST_OUTPUT" | grep -E '^[0-9]+' || true)
|
||||
PACKET_COUNT=$(echo "$PACKET_LINES" | wc -l || echo "0")
|
||||
|
||||
# Count packets (lines starting with a number)
|
||||
PACKET_COUNT=$(echo "$TEST_OUTPUT" | grep -E '^[0-9]+' | wc -l || echo "0")
|
||||
# Count lines with both frame.number and radiotap.present (non-empty second field)
|
||||
PLCP_COUNT=$(echo "$TEST_OUTPUT" | awk -F'\t' 'NF >= 2 && $1 != "" && $2 != "" && $2 != "0" && $2 != "-" {count++} END {print count+0}' || echo "0")
|
||||
PLCP_COUNT=$(echo "$PACKET_LINES" | awk -F'\t' 'NF >= 2 && $1 != "" && $2 != "" && $2 != "0" && $2 != "-" {count++} END {print count+0}' || echo "0")
|
||||
|
||||
# Show sample output
|
||||
if [ "$PACKET_COUNT" -gt 0 ]; then
|
||||
echo "Sample packets:"
|
||||
echo "$TEST_OUTPUT" | grep -E '^[0-9]+' | head -3
|
||||
echo "$PACKET_LINES" | head -3
|
||||
fi
|
||||
|
||||
echo "Captured $PACKET_COUNT packet(s) in test capture"
|
||||
if [ "$PLCP_COUNT" -gt 0 ]; then
|
||||
echo "PLCP headers: $PLCP_COUNT (radiotap present)"
|
||||
else
|
||||
echo "PLCP headers: 0 (no radiotap headers detected)"
|
||||
echo ""
|
||||
echo "Test capture results:"
|
||||
echo " Packets captured: $PACKET_COUNT"
|
||||
echo " PLCP headers: $PLCP_COUNT"
|
||||
if [ "$PLCP_COUNT" -eq 0 ] && [ "$PACKET_COUNT" -gt 0 ]; then
|
||||
echo " Note: Packets captured but no radiotap headers (may be using DLT_IEEE802_11 instead of DLT_IEEE802_11_RADIO)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
|
|
|||
Loading…
Reference in New Issue