]>
Commit | Line | Data |
---|---|---|
236898d6 MT |
1 | Fix for when arp_disp_2() is called without opt_n set. If there is a DNS lookup, an |
2 | entry is added to /proc/net/arp after fopen(), resulting in a duplicate entry. | |
3 | ||
4 | --- net-tools-1.60/arp.c.fgets 2005-12-10 14:52:04.000000000 -0500 | |
5 | +++ net-tools-1.60/arp.c 2005-12-11 00:15:59.000000000 -0500 | |
6 | @@ -528,7 +528,7 @@ static int arp_show(char *name) | |
7 | int type, flags; | |
8 | FILE *fp; | |
9 | char *hostname; | |
10 | - int num, entries = 0, showed = 0; | |
11 | + int num, entries, showed = 0; | |
12 | ||
13 | host[0] = '\0'; | |
14 | ||
15 | @@ -546,18 +546,21 @@ static int arp_show(char *name) | |
16 | perror(_PATH_PROCNET_ARP); | |
17 | return (-1); | |
18 | } | |
19 | + /* Count number of entries, in case file changes */ | |
20 | + for (entries = 0; fgets(line, sizeof(line), fp); entries++); | |
21 | + entries--; | |
22 | + fseek (fp, 0L, SEEK_SET); | |
23 | /* Bypass header -- read until newline */ | |
24 | if (fgets(line, sizeof(line), fp) != (char *) NULL) { | |
25 | strcpy(mask, "-"); | |
26 | strcpy(dev, "-"); | |
27 | /* Read the ARP cache entries. */ | |
28 | - for (; fgets(line, sizeof(line), fp);) { | |
29 | - num = sscanf(line, "%s 0x%x 0x%x %100s %100s %100s\n", | |
30 | - ip, &type, &flags, hwa, mask, dev); | |
31 | - if (num < 4) | |
32 | + for (num = 0; num < entries; num++) { | |
33 | + fgets(line, sizeof(line), fp); | |
34 | + if (sscanf(line, "%s 0x%x 0x%x %100s %100s %100s\n", | |
35 | + ip, &type, &flags, hwa, mask, dev) < 4) | |
36 | break; | |
37 | ||
38 | - entries++; | |
39 | /* if the user specified hw-type differs, skip it */ | |
40 | if (hw_set && (type != hw->type)) | |
41 | continue; |