Commit 479bb4a7 authored by Ralf Baechle's avatar Ralf Baechle Committed by Mike Frysinger

Fix incorrect ARP output

arp(8) obtains the information it prints the old way from /proc/net/arp
which for incomplete ARP entries contains no HW address such as in the
following example:

IP address       HW type     Flags       HW address            Mask     Device   0x1         0x0         00:00:00:00:00:00     *        ens3   0x1         0x0         00:00:00:00:00:00     *        ens3    0x1         0x2         52:54:00:00:5d:5f     *        ens3      0x3         0x0              *        bpq0         0x1         0x0         00:00:00:00:00:00     *        ens7

This means the scanf call will incorrectly scan the * character for the
HW address, the device (bpq0 in above example) for the mask and nothing
for the device, that is the last scanf'ed device name or "-" if non has
been read before, will be used resulting in the following incorrect output

Address                  HWtype  HWaddress           Flags Mask            Iface
[...]                      (incomplete)                              ens3

Fixed by calling scanf a 2nd time if we notice that the first time around
only 5 elements were read.

Arguably this is a kernel bug caused by the silly attempt of printing a
MAC address that consists of only blanks for incomplete ARP entries of
HW type 0x3 but it exists for so long that it virtually has become part of
the API so this just tries to live with it.
Signed-off-by: 's avatarRalf Baechle <>
parent b4f51826
......@@ -565,6 +565,15 @@ static int arp_show(char *name)
ip, &type, &flags, hwa, mask, dev);
if (num < 4)
if (num == 5) {
* This happens for incomplete ARP entries for which there is
* no hardware address in the line.
num = sscanf(line, "%s 0x%x 0x%x %99s %99s\n",
ip, &type, &flags, mask, dev);
hwa[0] = 0;
/* if the user specified hw-type differs, skip it */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment