31 lines
1.1 KiB
Diff
31 lines
1.1 KiB
Diff
diff -up net-tools-1.60/arp.c.fgets net-tools-1.60/arp.c
|
|
--- net-tools-1.60/arp.c.fgets 2011-12-05 16:34:16.000000000 +0100
|
|
+++ net-tools-1.60/arp.c 2011-12-05 16:54:52.683352733 +0100
|
|
@@ -558,18 +558,21 @@ static int arp_show(char *name)
|
|
perror(_PATH_PROCNET_ARP);
|
|
return (-1);
|
|
}
|
|
+ /* Count number of entries, in case file changes */
|
|
+ for (entries = 0; fgets(line, sizeof(line), fp); entries++);
|
|
+ entries--;
|
|
+ fseek (fp, 0L, SEEK_SET);
|
|
/* Bypass header -- read until newline */
|
|
if (fgets(line, sizeof(line), fp) != (char *) NULL) {
|
|
strcpy(mask, "-");
|
|
strcpy(dev, "-");
|
|
/* Read the ARP cache entries. */
|
|
- for (; fgets(line, sizeof(line), fp);) {
|
|
- num = sscanf(line, "%s 0x%x 0x%x %99s %99s %99s\n",
|
|
- ip, &type, &flags, hwa, mask, dev);
|
|
- if (num < 4)
|
|
+ for (num = 0; num < entries; num++) {
|
|
+ fgets(line, sizeof(line), fp);
|
|
+ if (sscanf(line, "%s 0x%x 0x%x %99s %99s %99s\n",
|
|
+ ip, &type, &flags, hwa, mask, dev) < 4)
|
|
break;
|
|
|
|
- entries++;
|
|
/* if the user specified hw-type differs, skip it */
|
|
if (hw_set && (type != hw->type))
|
|
continue;
|