diff --git a/script/ethercat.conf b/script/ethercat.conf index 91ccaeb8..f6f0a549 100644 --- a/script/ethercat.conf +++ b/script/ethercat.conf @@ -17,6 +17,10 @@ # Specify the MAC address (hexadecimal with colons) of the Ethernet device to # use. Example: "00:00:08:44:ab:66" # +# Alternatively, a network interface name can be specified. The interface +# name will be resolved to a MAC address using the 'ip' command. +# Example: "eth0" +# # The broadcast address "ff:ff:ff:ff:ff:ff" has a special meaning: It tells # the master to accept the first device offered by any Ethernet driver. # @@ -24,6 +28,10 @@ # created: A non-empty variable MASTER0_DEVICE will create one master, adding a # non-empty variable MASTER1_DEVICE will create a second master, and so on. # +# Examples: +# MASTER0_DEVICE="00:00:08:44:ab:66" +# MASTER0_DEVICE="eth0" +# MASTER0_DEVICE="" #MASTER1_DEVICE="" diff --git a/script/ethercatctl.in b/script/ethercatctl.in index 62dae0bd..361b95d8 100755 --- a/script/ethercatctl.in +++ b/script/ethercatctl.in @@ -4,9 +4,7 @@ # # Start script for EtherCAT to use with systemd # -# $Id$ -# -# Copyright (C) 2006-2012 Florian Pose, Ingenieurgemeinschaft IgH +# Copyright (C) 2006-2021 Florian Pose, Ingenieurgemeinschaft IgH # # This file is part of the IgH EtherCAT Master. # @@ -37,6 +35,7 @@ LSMOD=/sbin/lsmod MODPROBE=/sbin/modprobe RMMOD=/sbin/rmmod MODINFO=/sbin/modinfo +IP=/bin/ip ETHERCAT=@bindir@/ethercat @@ -55,13 +54,22 @@ 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 or interface name \""${1}"\" \ + in ${ETHERCAT_CONFIG} + exit 1 + fi fi }