diff --git a/libexec/rc/rc.d/netwait b/libexec/rc/rc.d/netwait --- a/libexec/rc/rc.d/netwait +++ b/libexec/rc/rc.d/netwait @@ -86,19 +86,28 @@ count=1 while [ ${count} -le ${netwait_timeout} ]; do - /sbin/ping -t 1 -c 1 -o ${ip} >/dev/null 2>&1 - rc=$? - - if [ $rc -eq 0 ]; then - # Restore default SIGINT handler - trap - SIGINT - - echo ', got response.' - return - fi - count=$((count+1)) - done - warn ', failed: No response from host.' + if echo "$ip" | grep -E "^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$" >/dev/null; then + # IPv4 + /sbin/ping -t 1 -c 1 -o "$ip" >/dev/null 2>&1 + elif echo "$ip" | grep -E "^[0-9a-fA-F:]+$" >/dev/null; then + # IPv6 + /sbin/ping6 -c 1 "$ip" >/dev/null 2>&1 + else + warn "Invalid IP address format." + exit 1 + fi + + rc=$? + if [ $rc -eq 0 ]; then + # Restore default SIGINT handler + trap - SIGINT + + echo "Got response." + exit 0 + fi + count=$((count+1)) + done + echo "No response after $netwait_timeout attempts." done # Restore default SIGINT handler