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:
Robert McMahon 2026-02-13 13:52:07 -08:00
parent cc180b7868
commit b80a9d818b
1 changed files with 19 additions and 20 deletions

View File

@ -80,36 +80,35 @@ iw dev "$INTERFACE" info | grep -E "(type|channel)" || echo "Could not verify"
# Check DLT with tshark (capture for 1 second) # Check DLT with tshark (capture for 1 second)
echo "" echo ""
echo "Checking Data Link Type (1 second test capture)..." echo "Checking Data Link Type (1 second test capture)..."
# First check if we can open the interface echo "(This may take up to 2 seconds if no packets are present)"
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
# Use -c to limit packets and add immediate output, redirect stderr to see warnings # Use timeout with -c to limit packets and avoid hanging
# Use a shorter timeout and limit packets to 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 || echo "") TEST_OUTPUT=$(timeout 2 tshark -i "$INTERFACE" -c 100 -T fields -e frame.number -e radiotap.present 2>&1 || true)
TEST_EXIT_CODE=$? TEST_EXIT_CODE=${PIPESTATUS[0]}
# Show any warnings/errors from tshark # Show any warnings/errors from tshark (but not packet data)
echo "$TEST_OUTPUT" | grep -E "(Running as|tshark:|Warning|Error)" || true 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) # 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 # Show sample output
if [ "$PACKET_COUNT" -gt 0 ]; then if [ "$PACKET_COUNT" -gt 0 ]; then
echo "Sample packets:" echo "Sample packets:"
echo "$TEST_OUTPUT" | grep -E '^[0-9]+' | head -3 echo "$PACKET_LINES" | head -3
fi fi
echo "Captured $PACKET_COUNT packet(s) in test capture" echo ""
if [ "$PLCP_COUNT" -gt 0 ]; then echo "Test capture results:"
echo "PLCP headers: $PLCP_COUNT (radiotap present)" echo " Packets captured: $PACKET_COUNT"
else echo " PLCP headers: $PLCP_COUNT"
echo "PLCP headers: 0 (no radiotap headers detected)" 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 fi
echo "" echo ""