I’m in the process of porting some (socket-related) Windows C code to Linux/Android and I’m running into an issue with the ioctl command:
unsigned long u;
if(sockfd != -1 && !ioctl(sockfd, FIONREAD, &u))
{
return((long) u);
}
...
// throw exception
When I check errno, I see EINVAL, but I don’t see why the call to ioctl failed with these arguments. I even tried to declare u as an int instead and it still failed. I have no idea what is wrong. This code works perfectly fine on Windows (ioctlsocket instead of ioctl).
Here’s an strace from Linux:
socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 3
bind(3, {sa_family=AF_INET, sin_port=htons(9099), sin_addr=inet_addr("0.0.0.0")}, 16) = 0
listen(3, 5) = 0
ioctl(3, FIONREAD, [1]) = -1 EINVAL (Invalid argument)
write(2, "Exception code: 00000503, data: "..., 52Exception code: 00000503, data: 00000000 ((null):0)
) = 52
shutdown(3, 2 /* send and receive */) = 0
close(3) = 0
exit_group(1) = ?
Linux doesn’t support
FIONREAD/SIOCINQon listening sockets. Seetcp(7):