|
|
02ab27f |
Fix for when arp_disp_2() is called without opt_n set. If there is a DNS lookup, an
|
|
|
02ab27f |
entry is added to /proc/net/arp after fopen(), resulting in a duplicate entry.
|
|
|
02ab27f |
|
|
|
02ab27f |
--- net-tools-1.60/arp.c.fgets 2005-12-10 14:52:04.000000000 -0500
|
|
|
02ab27f |
+++ net-tools-1.60/arp.c 2005-12-11 00:15:59.000000000 -0500
|
|
|
02ab27f |
@@ -528,7 +528,7 @@ static int arp_show(char *name)
|
|
|
02ab27f |
int type, flags;
|
|
|
02ab27f |
FILE *fp;
|
|
|
02ab27f |
char *hostname;
|
|
|
02ab27f |
- int num, entries = 0, showed = 0;
|
|
|
02ab27f |
+ int num, entries, showed = 0;
|
|
|
02ab27f |
|
|
|
02ab27f |
host[0] = '\0';
|
|
|
02ab27f |
|
|
|
02ab27f |
@@ -546,18 +546,21 @@ static int arp_show(char *name)
|
|
|
02ab27f |
perror(_PATH_PROCNET_ARP);
|
|
|
02ab27f |
return (-1);
|
|
|
02ab27f |
}
|
|
|
02ab27f |
+ /* Count number of entries, in case file changes */
|
|
|
02ab27f |
+ for (entries = 0; fgets(line, sizeof(line), fp); entries++);
|
|
|
02ab27f |
+ entries--;
|
|
|
02ab27f |
+ fseek (fp, 0L, SEEK_SET);
|
|
|
02ab27f |
/* Bypass header -- read until newline */
|
|
|
02ab27f |
if (fgets(line, sizeof(line), fp) != (char *) NULL) {
|
|
|
02ab27f |
strcpy(mask, "-");
|
|
|
02ab27f |
strcpy(dev, "-");
|
|
|
02ab27f |
/* Read the ARP cache entries. */
|
|
|
02ab27f |
- for (; fgets(line, sizeof(line), fp);) {
|
|
|
02ab27f |
- num = sscanf(line, "%s 0x%x 0x%x %100s %100s %100s\n",
|
|
|
02ab27f |
- ip, &type, &flags, hwa, mask, dev);
|
|
|
02ab27f |
- if (num < 4)
|
|
|
02ab27f |
+ for (num = 0; num < entries; num++) {
|
|
|
02ab27f |
+ fgets(line, sizeof(line), fp);
|
|
|
02ab27f |
+ if (sscanf(line, "%s 0x%x 0x%x %100s %100s %100s\n",
|
|
|
02ab27f |
+ ip, &type, &flags, hwa, mask, dev) < 4)
|
|
|
02ab27f |
break;
|
|
|
02ab27f |
|
|
|
02ab27f |
- entries++;
|
|
|
02ab27f |
/* if the user specified hw-type differs, skip it */
|
|
|
02ab27f |
if (hw_set && (type != hw->type))
|
|
|
02ab27f |
continue;
|