Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

porting ioctl() calls from unix to linux, error with FIONBIO

i want to use ioctl() to get the number of bytes ready to be read

the way I did it is:

mysocket=socket(....);
ioctl(mysocket, FIONBIO, &zero);    
connect(.....);
ioctl( mysocket, FIONREAD, &numBytes );
read(mysocket, buffer, numBytes);

this was working fine in unix, now i have to port it to linux i keep getting ERROR

error: 'FIONBIO' was not declared in this scope

Is there some header file specific for linux? or 'FIOBIO' doesnt work at all in linux?

I have following headers included:

#include <cstring>
#include <sys/socket.h>
#include <stropts.h>
#include <fcntl.h>
#include <stddef.h>
#include <sys/un.h>
#include <sys/types.h>
#include <stdlib.h> 
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/select.h>
#include <fstream>

and i removed

#include <sys/filio.h>

since it was throwing errors saying sys/filio.h not found

like image 737
maheshg Avatar asked Mar 07 '12 22:03

maheshg


1 Answers

Have you tried including sys/ioctl.h?

This code works for me:

#include <sys/ioctl.h>
#include <stdio.h>

int main() {
    printf("FIONBIO value %d\n", FIONBIO);
}

When I execute grep -R FIONBIO /usr/include, it's found here:

/usr/include/asm-generic/ioctls.h:#define FIONBIO 0x5421
like image 64
mfontanini Avatar answered Sep 22 '22 02:09

mfontanini