#!/sbin/sh 

  #
  # xtutil_can-ping
  #
  # Check if we seem to be able to ping host $1 
  # If yes return with exit code 0, if not return with 1 
  # If formal error return with exit code 3
  #

THISPATH=`ls -la $0 | awk '{print $NF}'`
THISDIR=`dirname $THISPATH`

PATH=$THISDIR:$PATH

formal_err_exit ()
{
    echo $1
    echo "usage: $0 hostname" >&2
    exit 3
}

if [ $# -ne 1 ] 
then
  formal_err_exit ""
fi

XTNAME=$1

if [ "$XTUTIL_OS" = "" ]
then
  XTUTIL_OS=`xtutil_get-os`
  if [ $? -ne 0 -o "XTUTIL_OS" = "" ]
  then
    echo xtutil_get-os failed >&2
    exit 3
  fi
fi


case $XTUTIL_OS in
  sun4|sun5)
    CMD="ping -s $XTNAME 100 2" ;;
  sco)
    CMD="ping -s 100 -c 2 $XTNAME" ;;
  aix| mips)
    CMD="ping $XTNAME 100 2" ;;
  hp*)
    CMD="ping $XTNAME 100 -n 2" ;;
esac


$CMD | fgrep '100% packet loss' > /dev/null
if [ $? -eq 0 ]
then
  exit 1
else
  exit 0
fi

