Ok, it is a very weird problem. I was trying to create a raw socket ICMP packet to spoof the ping request.
int s;
s = socket(PF_INET, SOCK_RAW, IPPROTO_RAW);
And then
int one; // I should initialize it as 1, but I didn't.
const int *val = &one;
setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof(one));
....
It turns out that since I didn't initialize one as 1, the spoofed client cannot receive the ping reply. However, when I add a
unsigned char *ch = (unsigned char *)spoof;
just before the
close(s);
,
it turns out that the spoofed client can receive the ping reply. Why is that?