April 2012
Intermediate to advanced
352 pages
8h
English
To invoke a d_ioctl function, you’d use the ioctl(2) system call.
#include <sys/ioctl.h> int ioctl(int d, unsigned long request, ...);
The d argument, which stands for descriptor, expects a file descriptor for a device node. The request argument is the ioctl command to be issued (for example, ECHO_CLEAR_BUFFER). The remaining argument (...) is a pointer to the data that’ll be passed to the d_ioctl function.
Example 3-2 presents a command-line utility designed to invoke the echo_ioctl function in Example 3-1:
Example 3-2. echo_config.c
#include <sys/types.h>
#include <sys/ioctl.h>
#include <err.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define ECHO_CLEAR_BUFFER _IO('E', 1)