ioctl()

NAME

ioctl() - control a socket or file

SYNOPSIS

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

int ioctl (int fd, int command, ...);

DESCRIPTION

The ioctl(2) function manipulates the underlying device parameters. In particular, many operating characteristics of terminals and sockets may be controlled with ioctl(2) requests. The argument fd must be an open file descriptor.

Encoded in an ioctl(2) request is whether the argument is an in parameter or an out parameter, and the size of the remaining arguments in bytes.

The possible values for command are defined in <sys/ioctl.h> and include:

FIONBIO
Sets or clears on-blocking I/O. The arg should point to an int. If the int is non-zero, the flag is set and non-blocking mode is enabled; if it is zero, the flag is cleared, and non-blocking mode is disabled.
FIONREAD
Returns in arg the number of bytes available to read from fd; arg should point to an int.
SIOCATMARK
For sockets; this boolean returns true if the socket's read pointer is at the out-of-band mark.
TIOCEXT
For pseudo terminals only; when this flag is non-zero (on), external processing mode is enabled. When zero, external processing mode is disabled. External processing mode places the terminal in a mode where characters are never echoed, special characters are enver processed, and no characters are erased. This mode is often used in programs like telnetd(1).
TIOCSIG
For pseudo terminals only; the arg should point to an int. Specifies a signal that can be applied to the terminal as if the signal were to be keyboard-generated. Valid signals are SIGTSTP, SIGINT, and SIGQUIT.

The call

ioctl(d, FIONBIO, NULL)

is equivalent to a call to

fcntl(d, F_SETFL, O_NONBLOCK)

except that for each fcntl(2) call, all of the flag values must set, while the ioctl(2) call allows you to set only one flag.

RETURN VALUE

The return value of the ioctl(2) depends upon the command. If an error occurs, it returns -1 and sets errno to indicate the error.

ERRORS

The ioctl(2) call will fail if:

[EAGAIN]
A device opened for non-blocking i/o is not yet ready.
[EBADF]
Fd is not a valid open file descriptor.
[EINTR]
The function was interrupted by a signal.
[EINVAL]
the data to which arg points is not valid.

NOTES

Traditional implementations of ioctl(2) also handle the terminal interface. For terminal manipulation (traditionally handled with TIOCGETD, TIOCSETD, TIOCGETP, and TIOCSETP or with stty() and gtty()), use the POSIX calls tcgetattr(2), tcsetattr(2), cfgetispeed(3), cfsetispeed(3), cfgetospeed(3), and cfsetospeed(3) to manipulate the termios structure, instead.

SEE ALSO

execve(2)

fcntl(2)