#!/bin/sh
# testpppoe for whereami
# Chris Halls, GPL version 2
#
# Uses pppoe to search for access concentrators.
#
# Since pppoe runs for a long time if nothing is there,
# this test kills the pppoe process after a while if it
# has not exited.

# Syntax: testpppoe [network interface name]

DEVICE=${1:-"eth0"}

# Time to wait before giving up
PPPOE_TIMEOUT=6

[ -x /usr/sbin/pppoe ] || exit 1

/usr/sbin/pppoe -I $DEVICE -A > /dev/null &            
pppoepid="$!"

# Start a job in the background to kill pppoe
( sleep $PPPOE_TIMEOUT ; kill $pppoepid 2>/dev/null ) &

# wait for pppoe to complete or die
wait $pppoepid 2> /dev/null
status=$?

# fail?
[ $status -eq 0 ] || exit 1

# Got a response packet
exit 0
