#!/bin/bash

INTERFACE="$1"

PREFIX="$(date -Iseconds)-${INTERFACE}"

INDEX=1

OUTFILE="${PREFIX}-${INDEX}.pcap"

while [ -f "$OUTFILE" ]
do
  (( INDEX= $INDEX + 1 ))
  OUTFILE="${PREFIX}-${INDEX}.pcap"
done

echo "Capturing to $OUTFILE"
sudo tcpdump -i "$INTERFACE" -j adapter_unsynced --time-stamp-precision=nano -w "$OUTFILE"
sudo chown $USER $OUTFILE
