Merge "Add a function to check if a packet is ours"
diff --git a/ping.c b/ping.c
index 5c5d09e..7f7ef82 100644
--- a/ping.c
+++ b/ping.c
@@ -690,7 +690,7 @@
 		if (res < sizeof(icmph) ||
 		    target.sin_addr.s_addr != whereto.sin_addr.s_addr ||
 		    icmph.type != ICMP_ECHO ||
-		    icmph.un.echo.id != ident) {
+		    !is_ours(icmph.un.echo.id)) {
 			/* Not our error, not an error at all. Clear. */
 			saved_errno = 0;
 			goto out;
@@ -860,7 +860,7 @@
 	csfailed = in_cksum((u_short *)icp, cc, 0);
 
 	if (icp->type == ICMP_ECHOREPLY) {
-		if (icp->un.echo.id != ident)
+		if (!is_ours(icp->un.echo.id))
 			return 1;			/* 'Twas not our ECHO */
 		if (gather_statistics((__u8*)icp, sizeof(*icp), cc,
 				      ntohs(icp->un.echo.sequence),
@@ -890,7 +890,7 @@
 					return 1;
 				if (icp1->type != ICMP_ECHO ||
 				    iph->daddr != whereto.sin_addr.s_addr ||
-				    icp1->un.echo.id != ident)
+				    !is_ours(icp1->un.echo.id))
 					return 1;
 				error_pkt = (icp->type != ICMP_REDIRECT &&
 					     icp->type != ICMP_SOURCE_QUENCH);
diff --git a/ping6.c b/ping6.c
index c39864d..019d9e4 100644
--- a/ping6.c
+++ b/ping6.c
@@ -1305,7 +1305,7 @@
 		if (res < sizeof(icmph) ||
 		    memcmp(&target.sin6_addr, &whereto.sin6_addr, 16) ||
 		    icmph.icmp6_type != ICMP6_ECHO_REQUEST ||
-		    icmph.icmp6_id != ident) {
+		    !is_ours(icmph.icmp6_id)) {
 			/* Not our error, not an error at all. Clear. */
 			saved_errno = 0;
 			goto out;
@@ -1602,7 +1602,7 @@
 	}
 
 	if (icmph->icmp6_type == ICMP6_ECHO_REPLY) {
-		if (icmph->icmp6_id != ident)
+		if (!is_ours(icmph->icmp6_id))
 			return 1;
 		if (gather_statistics((__u8*)icmph, sizeof(*icmph), cc,
 				      ntohs(icmph->icmp6_seq),
@@ -1645,7 +1645,7 @@
 		}
 		if (nexthdr == IPPROTO_ICMPV6) {
 			if (icmph1->icmp6_type != ICMP6_ECHO_REQUEST ||
-			    icmph1->icmp6_id != ident)
+			    !is_ours(icmph1->icmp6_id))
 				return 1;
 			acknowledge(ntohs(icmph1->icmp6_seq));
 			if (working_recverr)
diff --git a/ping_common.c b/ping_common.c
index 0342e1a..124270a 100644
--- a/ping_common.c
+++ b/ping_common.c
@@ -1073,3 +1073,7 @@
 	fprintf(stderr, "\n");
 }
 
+inline int is_ours(uint16_t id) {
+	return id == ident;
+}
+
diff --git a/ping_common.h b/ping_common.h
index 9cdb07b..f917315 100644
--- a/ping_common.h
+++ b/ping_common.h
@@ -277,6 +277,7 @@
 extern int receive_error_msg(void);
 extern int parse_reply(struct msghdr *msg, int len, void *addr, struct timeval *);
 extern void install_filter(void);
+extern int is_ours(uint16_t id);
 
 extern int pinger(void);
 extern void sock_setbufs(int icmp_sock, int alloc);