#!/bin/sh
#
# %Z%%M% %I% %E% Copyr 1986 Sun Micro
#
debug=0
hostname=`hostname`

if [ $# != 1 ]
then
	echo "Usage: $0 <interface>"
	exit 2
fi

# Look for an interface specific Ethernet address (used by DecNet)

# For 4.1 we can get the ethernet address using ifconfig (as root).
addr=`ifconfig $1 ether 2>/dev/null | grep "ether" | awk '{print $2}'`
if [ $debug != 0 -a "$addr" != "" ]
then
	echo "$0: found $addr using ifconfig ether" >/dev/console
fi
if [ "$addr" = "" ]
then
	addr=`grep ifconfig /etc/rc.boot | grep $1 | grep ether | \
		awk '{print $4}'`
	if [ $debug != 0 -a "$addr" != "" ]
	then
		echo "$0: found $addr in rc.boot" >/dev/console
	fi
fi
if [ "$addr" = "" -a -f /var/adm/messages ]
then
	# Find the Ethernet address for this machine
	addr=`grep "Ethernet address" /var/adm/messages | awk '{if (!p) {print $9; p++}}'`
	if [ $debug != 0 -a "$addr" != "" ]
	then
		echo "$0: found $addr in /var/adm/messages" >/dev/console
	fi
fi
index=0
while [ -f /var/adm/messages.$index -a "$addr" = "" ]
do
        addr=`grep "Ethernet address" /var/adm/messages.$index | awk '{if (!p) {print $9; p++}}'`
	if [ $debug != 0 -a "$addr" != "" ]
	then
		echo "$0: found $addr in /var/adm/messages.$index" >/dev/console
	fi
	index=`expr $index + 1`
done
if [ "$addr" = "" -a -f /etc/ethers ]
then
	# Find the Ethernet address for this machine
	addr=`grep $hostname /etc/ethers | awk '{print $1}'`
	if [ $debug != 0 -a "$addr" != "" ]
	then
		echo "$0: found $addr in /etc/ethers" >/dev/console
	fi
fi
if [ "$addr" = "" ]
then
	# Find the Ethernet address for this machine
	addr=`ypmatch $hostname ethers.byname 2>/dev/null | awk '{print $1}'`
	if [ $debug != 0 -a "$addr" != "" ]
	then
		echo "$0: found $addr in ethers.byname" >/dev/console
	fi
fi
echo $addr
