#!/bin/sh 
#
#/***************************************************************************
#*  Copyright (c) 1990-2003 Sun Microsystems, Inc, ALL RIGHTS RESERVED.
#*  Sun Microsystems Confidential
#****************************************************************************
#
# Returns either the name of the single network interface on the
# system, the string "toomany" if there is more than one interface
# installed and configured, or the string "toofew" if there are no
# interfaces installed.  It's up to the caller to parse the strings
# and do the correct thing w.r.t. error messages, defaults, etc.
# Note that it's also possible to glean the same info from the
# exit status IF you can get one back from however it is that the
# script is invoked.  For example, the system() routine does not
# return the proper return status from this, otherwise we wouldn't
# need the "too*" return strings...
#
lines=`/usr/bin/netstat -in | awk '{ if($0 == "") exit; print $0}'  | /usr/bin/wc -l`
lines=`expr $lines`

if [ $lines -eq 2 -o $lines -gt 3 ]
then
    if [ $lines -gt 3 ]
    then
	/usr/bin/echo "toomany"
	exit 1
    fi
    /usr/bin/echo "toofew"
    exit -1
fi

name=`/usr/bin/netstat -i |  grep -v lo0 | awk '{ if($0 == "") exit; print $0}' | /usr/bin/tail -1 | /usr/bin/cut -f1 -d' '`
/usr/bin/echo $name
exit 0
