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
#define | SOCKBUF_BUFFERIZE 0
#define | SOCKOPEN_CLIENT 0
#define | SOCKOPEN_SERVER 1
#define | SOCK_ERRBUF_SIZE 256
## Functions
void | sock_geterror (const char *caller, char *string, int size)
| It retrieves the error message after an error occurred in the socket interface.
int | sock_init (char *errbuf)
| It initializes sockets.
void | sock_cleanup ()
| It deallocates sockets.
int | sock_validaddr (const char *address, const char *port, struct addrinfo *hints, struct addrinfo **addrinfo, char *errbuf)
| 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, char *errbuf)
| It waits on a connected socket and it manages to receive exactly 'size' bytes.
int | sock_recv_dgram (SOCKET sock, char *buffer, int size, char *errbuf)
| It waits on a connected socket and it manages to receive one message.
int | sock_open (struct addrinfo *addrinfo, int server, int nconn, char *errbuf)
| It initializes a network connection both from the client and the server side.
int | sock_close (SOCKET sock, char *errbuf)
| Closes the present (TCP and UDP) socket connection.
int | sock_send (SOCKET socket, const char *buffer, int size, char *errbuf)
| 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)
| 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)
| 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)
| 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.

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