diff --git a/script/ethercatctl.in b/script/ethercatctl.in index 62dae0bd..1664a31f 100755 --- a/script/ethercatctl.in +++ b/script/ethercatctl.in @@ -37,6 +37,7 @@ LSMOD=/sbin/lsmod MODPROBE=/sbin/modprobe RMMOD=/sbin/rmmod MODINFO=/sbin/modinfo +IP=/bin/ip ETHERCAT=@bindir@/ethercat @@ -55,13 +56,19 @@ fi #------------------------------------------------------------------------------ parse_mac_address() { + local DEVICENAMETOMAC if [ -z "${1}" ]; then MAC="" - elif echo "${1}" | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then + elif echo ${1} | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then MAC=${1} else - echo Invalid MAC address \""${1}"\" in ${ETHERCAT_CONFIG} - exit 1 + DEVICENAMETOMAC=$("${IP}" address show dev "${1}" | awk '/link\/ether/ { print $2; }') + if echo "${DEVICENAMETOMAC}" | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then + MAC=${DEVICENAMETOMAC} + else + echo Invalid MAC address \""${1}"\" in ${ETHERCAT_CONFIG} + exit 1 + fi fi }