Main Page Modules Data Structures File List Data Fields Globals Related Pages

# sockutils.h File Reference

`#include <winsock2.h>`
`#include <ws2tcpip.h>`
`#include <assert.h>`

Go to the source code of this file.

## Defines
#define | SOCKET unsigned int
| In Win32, sockets use unsigned integers; in UNIX, they use signed integer.
#define | SOCK_ASSERT(msg, expr) { fprintf(stderr, "%s\n", msg); assert(expr); }
| DEBUG facility: it prints an error message on the screen (stderr).
#define | SOCKBUF_CHECKONLY 1
| 'checkonly' flag, into the rpsock_bufferize()
#define | SOCKBUF_BUFFERIZE 0
| no 'checkonly' flag, into the rpsock_bufferize()
#define | SOCKOPEN_CLIENT 0
| no 'server' flag; it opens a client socket
#define | SOCKOPEN_SERVER 1
| 'server' flag; it opens a server socket
#define | SOCK_RECEIVEALL_NO 0
| Changes the behaviour of the sock_recv(); it does not wait to receive all data.
#define | SOCK_RECEIVEALL_YES 1
| Changes the behaviour of the sock_recv(); it waits to receive all data.
## Functions
int | sock_init (char *errbuf, int errbuflen)
| It initializes sockets.
void | sock_cleanup ()
| It deallocates sockets.
void | sock_geterror (const char *caller, char *errbuf, int errbufsize)
| It retrieves the error message after an error occurred in the socket interface.
int | sock_initaddress (const char *address, const char *port, struct addrinfo *hints, struct addrinfo **addrinfo, char *errbuf, int errbuflen)
| Checks that the address, port and flags given are valids and it returns an 'addrinfo' stucture.
int | sock_recv (SOCKET socket, char *buffer, int size, int receiveall, char *errbuf, int errbuflen)
| It waits on a connected socket and it manages to receive data.
SOCKET | sock_open (struct addrinfo *addrinfo, int server, int nconn, char *errbuf, int errbuflen)
| It initializes a network connection both from the client and the server side.
int | sock_close (SOCKET sock, char *errbuf, int errbuflen)
| Closes the present (TCP and UDP) socket connection.
int | sock_send (SOCKET socket, const char *buffer, int size, char *errbuf, int errbuflen)
| It sends the amount of data contained into 'buffer' on the given socket.
int | sock_bufferize (const char *buffer, int size, char *tempbuf, int *offset, int totsize, int checkonly, char *errbuf, int errbuflen)
| It copies the amount of data contained into 'buffer' into 'tempbuf'. and it checks for buffer overflows.
int | sock_discard (SOCKET socket, int size, char *errbuf, int errbuflen)
| It discards N bytes that are currently waiting to be read on the current socket.
int | sock_check_hostlist (char *hostlist, const char *sep, struct sockaddr_storage *from, char *errbuf, int errbuflen)
| Checks that one host (identified by the sockaddr_storage structure) belongs to an 'allowed list'.
int | sock_cmpaddr (struct sockaddr_storage *first, struct sockaddr_storage *second)
| Compares two addresses contained into two sockaddr_storage structures.
int | sock_getmyinfo (SOCKET sock, char *address, int addrlen, char *port, int portlen, int flags, char *errbuf, int errbuflen)
| It gets the address/port the system picked for this socket (on connected sockets).
int | sock_getascii_addrport (const struct sockaddr_storage *sockaddr, char *address, int addrlen, char *port, int portlen, int flags, char *errbuf, int errbuflen)
| It retrieves two strings containing the address and the port of a given 'sockaddr' variable.
int | sock_present2network (const char *address, struct sockaddr_storage *sockaddr, int addr_family, char *errbuf, int errbuflen)
| It translates an address from the 'presentation' form into the 'network' form.

documentation. Copyright (c) 2002-2003 Politecnico di Torino. All rights reserved.