NAME
io_connect, io_accept, io_listen - a transparent TCP layer
SYNOPSIS
#include <peks.h>
int send (unsigned fd, const char *data, unsigned len,
unsigned flags);
int recv (unsigned fd, char *buffer, unsigned len,
unsigned flags);
int shutdown (unsigned fd, unsigned how);
int close (unsigned fd);
int io_connect (const char* server, unsigned tcp_port);
int io_listen (const char* bind_name, unsigned tcp_port);
int io_accept (int socket);
int io_connect_timeout,io_accept_timeout,io_listen_backlog;
DESCRIPTION
Make sure that the "#include <peks.h>" directive comes last of the include files. This include file replaces the functions send(), recv(), shutdown(), and close() by extended versions io_send(), io_recv(), io_shutdown(), and io_close().
By default, the extended versions of the io-functions just call the functions that they are hiding, passing arguments and returning the function value received.
Not until a cipher layer is (logically) pushed upon the io data stream, the extended io-functions become effective. Pushing a cipher layer upon the io data stream is typically done transparently while the session key is negotiated.
It may be nessary (but unlikely) that the cypher layer needs to be removed, or popped from the io stream without closing it. In that case, the extended io-functions act as described before, just passing arguments and return codes to and from the functions that they are hiding.
Io_connect() is a TCP convenience function wrapper around the connect() service from the operating system. The first argument server is the server name to connect to (see gethostbyname(2) for the name resolution) and the second argument typ_port is TCP port on that server.
By setting the global variable io_connect_timeout to some positive value n (default is 20), some timeout is imposed on how long the system waits fo data. This is unsally done by wating until the data arrive and installing an alarm() timer, while reading. So a signal SIGALRM will be sent after n seconds terminating a pending connect() call. Setting this variable to zero, this feature will be totally disabled, something negative allows to set a timeout (the absolute value of that) until the first data arrive, only. In any case of a timeout, global variable errno is set to the value EINTR.
Io_listen() is a TCP convenience function wrapper around the listen() service from the operating system. The first argument bind_name is a host name, the listener binds an address to the listener socket (see bind(2) for details.) The second argument tcp_port tells on which tcp port an incoming connection request is accepted (see listen(2) for details.)
By setting the global variable io_listen_backlog to some value n (default is 5), you can control how many connecting clients can be handled, simultaneously (see listen(2) for details.)
Io_accept() is a TCP convenience function wrapper around the accept() service from the operating system. The function argument is a listener socket number as returned from Io_listen().
By setting the global variable io_accept_timeout to some positive value n (default is 5), a signal SIGALRM will be sent after n seconds terminating a pending accept() call. Setting this variable to something non-positive, this feature will be disabled.
Example (client):
int socket ;
if ((socket = io_connect ("server.my.domain", 1234)) < 0)
return -1;
...
Example (server):
int socket, listen_socket ; if ((listen_spcket = io_listen (0, 1234)) < 0) return -1; ... if ((socket = io_accept (listen_socket)) < 0) return -1; ...
Note: It is safe, to use the "#include <peks.h>" directive all over the place provided this include directive comes last.
RETURN VALUE
The functions send(), recv(), shutdown(), and close() behave as described in the manual(2) from the operating system.
Upon success, Io_connect() and io_accept() return a open TCP socket number as described in connect(2) and accept(2), and Io_listen() a listener socket as described in listen.
Upon error, these functions return -1 while the global variable errno is set to indicate some explanation.
SEE ALSO
listen(2), accept(2), connect(2), socket(2), io_push(3), io_send(3), errno(3), peks-errnum(3, gethostbyname(3),
AUTHOR
The peks package where these functions belong to was written by Jordan Hrycaj <[email protected]>, originally to support the nessus security scanner.