summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schier <nicolas@fjasle.eu>2020-10-27 21:23:44 +0100
committerJoey Hess <joeyh@joeyh.name>2021-01-02 12:23:36 -0400
commitbeb43483d0a312051a1bfa60b0d50983cf01421e (patch)
tree9987bfb012e8919a7864e9db425ba9aca6f0cb4f
parent83b0a23a8e68d326bbc96fef9174d8c188385868 (diff)
downloadmoreutils-beb43483d0a312051a1bfa60b0d50983cf01421e.tar.gz
ifdata: fail when -ph is given but no hwaddr is available (Closes: #386755)
Exit ifdata with an error code if '-ph' (print hardware address) is given but no hardware address is available for the given network device. Previously, ifdata printed the invalid hardware address 00:00:00:00:00:00 in such cases and exited as if this was the real hardware address. Signed-off-by: Nicolas Schier <nicolas@fjasle.eu>
-rw-r--r--ifdata.c7
-rw-r--r--ifdata.docbook5
2 files changed, 11 insertions, 1 deletions
diff --git a/ifdata.c b/ifdata.c
index 99f30e9..6e0bd0b 100644
--- a/ifdata.c
+++ b/ifdata.c
@@ -195,6 +195,13 @@ void if_hwaddr(const char *iface) {
return;
hwaddr = (unsigned char *)r.ifr_hwaddr.sa_data;
+
+ if (!hwaddr[0] && !hwaddr[1] && !hwaddr[2] &&
+ !hwaddr[3] && !hwaddr[4] && !hwaddr[5]) {
+ fprintf(stderr, "Error: %s: no hardware address\n", iface);
+ exit(1);
+ }
+
printf("%02X:%02X:%02X:%02X:%02X:%02X",
hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]);
}
diff --git a/ifdata.docbook b/ifdata.docbook
index 4aa24db..a8c27d9 100644
--- a/ifdata.docbook
+++ b/ifdata.docbook
@@ -155,7 +155,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<term><option>-ph</option></term>
<listitem>
<para>Prints the hardware address of the
- interface.</para>
+ interface. Exit with a failure exit code
+ if there is not hardware address for the
+ given network interface.
+ </para>
</listitem>
</varlistentry>