How to use ioctl FIONREAD with PX4?

I have a very specific motor driver that I must connect to with a serial connection, to use its API.
I can connect this motor driver on my Linux PC with no problem to both send information to the driver and retrieve information from the driver.
Now, I have to do the same with PX4. I can send messages to the driver with no problem, but when I code my readMessage method on PC, I can’t use the following line of code:

unsigned long int num_bytes;
ioctl(dev_fd_, FIONREAD, &num_bytes);

The error I get is that ioctl’s 3rd argument, on the PX4, expects an unsigned long int and not a pointer, which is weird since on Linux I can send a pointer (so I can retrieve the number of bytes to be read with the FIONREAD option).

I would like to know how to solve this, and if there’s some other thing I can use instead of ioctl on px4 to do the same task.

Thanks a lot!

You should cast the pointer to an unsigned long int.
This is the prototype of the function which is variable arg, so it is inherently not type safe:

int ioctl(int fd , unsigned long request , …);