This function affects an open file referenced by the
fd argument.
#include <unistd.h> |
int ioctl(int fd , int request , ... /* void * arg */ ); |
Returns:0 if OK, -1 on error |
The third argument is always a pointer, but the type of pointer depends on the
request .
4.4BSD defines the second argument to be an unsigned long instead of an int, but that is not a problem since header files define the constants that are used for this argument. As long as the prototype is in scope (i.e., the program using ioctl has included <unistd.h>), the correct type for the system will be used.
Some implementations specify the third argument as a void * pointer instead of the ANSI C ellipsis notation.
There is no standard for the header to include to define the function prototype for ioctl since it is not standardized by POSIX. Many systems define it in <unistd.h>, as we show, but traditional BSD systems define it in <sys/ioctl.h>.
We can divide the
requests related to networking into six categories:
Socket operations
File operations
Interface operations
ARP cache operations
Routing table operations
STREAMS system (Chapter 31)
Recall from Figure 7.20 that not only do some of the ioctl operations overlap some of the fcntl operations (e.g., setting a socket to nonblocking), but there are also some operations that can be specified more than one way using ioctl (e.g., setting the process group ownership of a socket).
Figure 17.1 lists the
requests , along with the datatype of what the
arg address must point to. The following sections describe these requests in more detail.