#!/bin/ksh -p

#
# ident "@(#)utsdhcpsum.ksh	1.5 02/09/13 SMI"
#
# Copyright 2000-2002 Sun Microsystems, Inc.  All rights reserved.
#

INIT_DHCP="/etc/init.d/dhcp";

#
# Verify that dhcp is installed
#
function CheckDHCP {
  if [ ! -x "${INIT_DHCP}" ]; then
    print "Error:  DHCP cannot be run on this machine." >&2;
    print "        Ensure DHCP is installed, /etc/init.d/dhcp has the" >&2;
    print "        correct permissions and run \"utdhcpsum\" again." >&2;
    exit 2;
  fi
}

################################################################
#
# MAIN
#
################################################################

set -u
umask 022

# check if we're root
if [ `id | cut -c5` -ne 0 ]; then
  print "Error:  must have super user (root) privileges" >&2;
  exit 1;
fi

CheckDHCP;

typeset -r UT_BASE="$(pkginfo -r SUNWuto 2>&-)"
typeset -r UT_BASEDIR="${UT_BASE:-/opt}"
typeset -r UT_TMPDIR="/var/opt/SUNWut/tmp"

${UT_BASEDIR}/SUNWut/sbin/utadm -p > ${UT_TMPDIR}/srnets.$$ 2>&1;
if [ $? -ne 0 ]; then
  /bin/rm -rf ${UT_TMPDIR}/srnets.$$;
  exit 1;
fi

/bin/cat ${UT_TMPDIR}/srnets.$$ | /bin/grep -v '^Interf' | /bin/nawk '{
  split($5,d,"/")
  count = d[2] - d[1] 
  printf "SunRay-%s\n%s\n", $1, count }'
/bin/rm -rf ${UT_TMPDIR}/srnets.$$;
exit 0
