Parse The Received Packet (Cont.)
// verify that it's an ICMP echo request, with the expected seq. num + id.
icmphdr = (struct icmphdr*)(rbuf + (iphdr->ihl * 4));
if (icmphdr->type != ICMP_ECHOREPLY) {
fprintf(stderr, "Expected ICMP echo-reply, got %u\n", icmphdr->type);
exit(1);
}
if (icmphdr->un.echo.sequence != 50) {
fprintf(stderr,
"Expected sequence 50, got %d\n", icmphdr->un.echo.sequence);
exit(1);
}
if (icmphdr->un.echo.id != 48) {
fprintf(stderr,
"Expected id 48, got %d\n", icmphdr->un.echo.id);
exit(1);
}
printf("Got the expected ICMP echo-request\n");
Originally written by
guy keren