// -- code snipped
buf = (char*) malloc(sizeof(struct ip)+sizeof(struct icmp));
sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
for (;;) { n = recv(sockfd, buf, sizeof(buf),0);
looks like the memory you allocate with malloc() is initialized to zero ... ICMP_ECHOREPLY is zero ...ip = (struct ip *) buf; ip_len = ip->ip_hl << 2; // ip header length
icmp = (struct icmp *) (buf + ip_len);
printf("n= %d\n",n); if (icmp->icmp_type == ICMP_ECHO) { printf("ping request arrived\n"); } }
It seems that the kernel donot pass ICMP_ECHO to raw socket if i use ICMP_ECHOREPLY, it will work,
David Lamparter
----- 17yr old high school student