Hi,

I've attached an updated patch that does things a little more
efficiently. I didn't spot this easier solution at first.

Thanks,
Steven.
Treat DNS lookup caches as invalid when the IP address being looked up
changes.
--- a/ping.c
+++ b/ping.c
@@ -1244,10 +1244,13 @@
 {
 	struct hostent *hp;
 	static char buf[4096] = "";
+	static __u32 last_addr = 0;
 
-	if (*buf)
+	if (*buf && addr == last_addr)
 		return(buf);
 
+	last_addr = addr;
+
 	in_pr_addr = !setjmp(pr_addr_jmp);
 
 	if (exiting || (options & F_NUMERIC) ||
--- a/ping6.c
+++ b/ping6.c
@@ -1796,6 +1796,7 @@
 {
 	static struct hostent *hp = NULL;
 	static char *s;
+	static struct in6_addr last_addr;
 
 #ifdef USE_IDN
 	free(s);
@@ -1803,8 +1804,11 @@
 
 	in_pr_addr = !setjmp(pr_addr_jmp);
 
-	if (!hp && !(exiting || options&F_NUMERIC))
+	if (!(hp && memcmp(addr, &last_addr, sizeof(struct in6_addr))) &&
+	    !(exiting || options&F_NUMERIC)) {
 		hp = gethostbyaddr((__u8*)addr, sizeof(struct in6_addr), AF_INET6);
+		memcpy(&last_addr, addr, sizeof(struct in6_addr));
+	}
 
 	in_pr_addr = 0;
 

Reply via email to