Home > other >  Consult, recv () read a non-blocking socket can't read the data
Consult, recv () read a non-blocking socket can't read the data

Time:10-10

IP layer raw socket, receives the icmp port unreachable message, when you recv () the fourth parameter is set to the MSG_DONTWAIT doesn't receive the data, but can receive data, when they set to block is a code, please everyone help
Int fd=socket (AF_INET SOCK_RAW, IPPROTO_ICMP);
If (fd<0)
{
Perror (" socket () ");
return -1;
}

While (1)
{

Int len=recv (fd, recv_buff, sizeof (recv_buff), the MSG_DONTWAIT);
If (len<0)
{
Perror (" recv () ");
Printf (" error is % d \ n ", errno);
}

If (len> 0)
{
Printf (" success to recieve data \ n ");
Int v=udp_unpack (recv_buff, len, IP, result);
If (n==1)
break;
}

}
}