NAME
io_push, io_pop, io_enable, io_suspend - create a socket io replacement layer
SYNOPSIS
#include <peks.h>
void *io_push (unsigned fd, unsigned context_size,
int (*rdwr_fn)
(void *context,
char *data, unsigned len, int flags),
int (*ioctl_fn)
(void *context,
io_ctrl_request request, int *arg),
void (*destroy_fn) (void *context),
unsigned how);
void io_pop (unsigned fd, unsigned how);
void io_enable (unsigned fd, unsigned how);
void io_suspend (unsigned fd, unsigned how);
DESCRIPTION
Io_push() creates a new io data stream diversion for the open file descriptor fd according to the argument how:
- 0 divert incoming data stream (like stdin)
-
1 divert outgoing data stream (like stdout).
The function creates a data area of size contextsize and zero initialises it. If also registeres the call back functions, given as argument. When this is done, a pointer of the data area allocated is returned, or NULL if an error occurs while the variable errno is set, accordingly.
If there has been a layer pushed on the current io data stream, already it is replaced unless the flag IO_PUSH_EXCLUSIVELY is xored with the argument how. In the latter case, an error is detected.
Io_pop() removes the diversion from the io data stream and calls
- (*destroy_fn)(desc)
where desc = desc (fd, how) is the data area also pointed to by the return code of io_push(). Finally, io_pop() frees desc.
Io_suspend() disables a diversion from the io data stream in which case it behaves as if the diversion had been io_pop ()-ed.
Io_enable() undoes the effect of io_suspend(). By default, io_enable() is automatically activated by io_push().
It is save calling the functions io_pop(), io_enable() and io_suspend() without having installed a data stream diversion using io_push().
CAVEAT
The data area returned by io_push() must never be deallocated using free(). It should be initialized immediately after returned successfully by io_push().
SEE ALSO
AUTHOR
The peks package where these functions belong to was written by Jordan Hrycaj <[email protected]>, originally to support the nessus security scanner.