net-tools/net-tools-1.60-fgets.patch
2006-03-16 21:22:44 +00:00

42 lines
1.4 KiB
Diff

Fix for when arp_disp_2() is called without opt_n set. If there is a DNS lookup, an
entry is added to /proc/net/arp after fopen(), resulting in a duplicate entry.
--- net-tools-1.60/arp.c.fgets 2005-12-10 14:52:04.000000000 -0500
+++ net-tools-1.60/arp.c 2005-12-11 00:15:59.000000000 -0500
@@ -528,7 +528,7 @@ static int arp_show(char *name)
int type, flags;
FILE *fp;
char *hostname;
- int num, entries = 0, showed = 0;
+ int num, entries, showed = 0;
host[0] = '\0';
@@ -546,18 +546,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 %100s %100s %100s\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 %100s %100s %100s\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;