Add a function to check if a packet is ours
This allows the ping socket codepaths to be simpler.
Bug: 9469682
Change-Id: I05174cafd74ad5de5e867af8a3a3ac19439034b4
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);