struct globals {
char *hostname;
char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
+ uint16_t myid;
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
pkt = (struct icmp *) G.packet;
/*memset(pkt, 0, sizeof(G.packet)); already is */
pkt->icmp_type = ICMP_ECHO;
+ pkt->icmp_id = G.myid;
pkt->icmp_cksum = inet_cksum((uint16_t *) pkt, sizeof(G.packet));
xsendto(pingsock, G.packet, DEFDATALEN + ICMP_MINLEN, &lsa->u.sa, lsa->len);
struct iphdr *iphdr = (struct iphdr *) G.packet;
pkt = (struct icmp *) (G.packet + (iphdr->ihl << 2)); /* skip ip hdr */
+ if (pkt->icmp_id != G.myid)
+ continue; /* not our ping */
if (pkt->icmp_type == ICMP_ECHOREPLY)
break;
}
pkt = (struct icmp6_hdr *) G.packet;
/*memset(pkt, 0, sizeof(G.packet)); already is */
pkt->icmp6_type = ICMP6_ECHO_REQUEST;
+ pkt->icmp6_id = G.myid;
sockopt = offsetof(struct icmp6_hdr, icmp6_cksum);
setsockopt_int(pingsock, SOL_RAW, IPV6_CHECKSUM, sockopt);
continue;
}
if (c >= ICMP_MINLEN) { /* icmp6_hdr */
+ if (pkt->icmp6_id != G.myid)
+ continue; /* not our ping */
if (pkt->icmp6_type == ICMP6_ECHO_REPLY)
break;
}
alarm(5); /* give the host 5000ms to respond */
create_icmp_socket(lsa);
+ G.myid = (uint16_t) getpid();
#if ENABLE_PING6
if (lsa->u.sa.sa_family == AF_INET6)
ping6(lsa);