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

sockutils.c File Reference

#include "sockutils.h"
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Defines

#define WINSOCK_MAJOR_VERSION   2 /*!< Ask for Winsock 2.2 */
#define WINSOCK_MINOR_VERSION   2 /*!< Ask for Winsock 2.2 */
#define SHUT_WR   SD_SEND /*!< The control code for shutdown() is different in Win32 */
#define snprintf   _snprintf /*!< The snprintf is called _snprintf() in Win32 */
#define SOCK_ERRBUF_SIZE   1024
 Size of the buffer that has to keep error messages.

#define SOCKET_NO_NAME_AVAILABLE   "No name available"
#define SOCKET_NO_PORT_AVAILABLE   "No port available"
#define SOCKET_NAME_NULL_DAD   "Null address (possibly DAD Phase)"
#define TEMP_BUF_SIZE   32768

Functions

int sock_ismcastaddr (const struct sockaddr *saddr)
 It checks if the sockaddr variable contains a multicast address.

void sock_geterror (const char *caller, char *errbuf, int errbuflen)
 It retrieves the error message after an error occurred in the socket interface.

int sock_init (char *errbuf, int errbuflen)
 It initializes sockets.

void sock_cleanup ()
 It deallocates sockets.

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_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_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_recv (SOCKET sock, char *buffer, int size, int receiveall, char *errbuf, int errbuflen)
 It waits on a connected socket and it manages to receive data.

int sock_discard (SOCKET sock, 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.


Variables

int sockcount = 0


Detailed Description

The goal of this file is to provide a common set of primitives for socket manipulation. Although the socket interface defined in the RFC 2553 (and its updates) is excellent, several minor issues are still hidden in supporting several operating systems.

These calls do not want to provide a better socket interface; vice versa, they intend to provide a set of calls that is portable among several operating systems, hiding their differences.

Definition in file sockutils.c.


Define Documentation

#define SHUT_WR   SD_SEND /*!< The control code for shutdown() is different in Win32 */
 

The control code for shutdown() is different in Win32

Definition at line 68 of file sockutils.c.

Referenced by sock_close().

#define snprintf   _snprintf /*!< The snprintf is called _snprintf() in Win32 */
 

The snprintf is called _snprintf() in Win32

Definition at line 69 of file sockutils.c.

Referenced by add_addr_to_iflist(), add_or_find_if(), bpf_image(), daemon_AuthUserPwd(), daemon_checkauth(), daemon_startcapture(), daemon_thrdatamain(), daemon_unpackapplyfilter(), fileconf_read(), main(), main_active(), main_passive(), pcap_compile(), pcap_createfilter_norpcappkt(), pcap_createsrcstr(), pcap_dump_open(), pcap_findalldevs_ex(), pcap_list_datalinks(), pcap_lookupdev(), pcap_open(), pcap_open_live(), pcap_open_offline(), pcap_opensource_remote(), pcap_parsesrcstr(), pcap_read_nocb_remote(), pcap_read_win32(), pcap_remoteact_accept(), pcap_remoteact_close(), pcap_remoteact_list(), pcap_sendpacket(), pcap_sendqueue_transmit(), pcap_set_datalink(), pcap_setbuff(), pcap_setfilter_win32(), pcap_setmintocopy(), pcap_setmode(), pcap_setnonblock_win32(), pcap_startcapture_remote(), pcap_stats_dead(), pcap_stats_ex(), pcap_stats_win32(), pcap_strerror(), rpcap_checkmsg(), rpcap_checkver(), rpcap_deseraddr(), rpcap_remoteact_getsock(), rpcap_sendauth(), rpcap_stats_remote(), sf_next_packet(), sf_stats(), sock_bufferize(), sock_check_hostlist(), sock_geterror(), sock_init(), sock_initaddress(), sock_open(), sock_present2network(), sock_recv(), and svc_geterr().

#define SOCK_ERRBUF_SIZE   1024
 

Size of the buffer that has to keep error messages.

Definition at line 74 of file sockutils.c.

Referenced by sock_geterror(), and sock_open().

#define SOCKET_NAME_NULL_DAD   "Null address (possibly DAD Phase)"
 

Definition at line 80 of file sockutils.c.

Referenced by sock_getascii_addrport().

#define SOCKET_NO_NAME_AVAILABLE   "No name available"
 

Definition at line 78 of file sockutils.c.

Referenced by sock_getascii_addrport().

#define SOCKET_NO_PORT_AVAILABLE   "No port available"
 

Definition at line 79 of file sockutils.c.

Referenced by sock_getascii_addrport().

#define TEMP_BUF_SIZE   32768
 

Referenced by sock_discard().

#define WINSOCK_MAJOR_VERSION   2 /*!< Ask for Winsock 2.2 */
 

Ask for Winsock 2.2

Definition at line 61 of file sockutils.c.

#define WINSOCK_MINOR_VERSION   2 /*!< Ask for Winsock 2.2 */
 

Ask for Winsock 2.2

Definition at line 62 of file sockutils.c.


Function Documentation

int sock_ismcastaddr const struct sockaddr *  saddr  ) 
 

It checks if the sockaddr variable contains a multicast address.

Returns:
'0' if the address is multicast, '-1' if it is not.

Definition at line 255 of file sockutils.c.

Referenced by sock_initaddress().


Variable Documentation

int sockcount = 0
 

Variable that allows calling the WSAStartup() only one time

Definition at line 63 of file sockutils.c.

Referenced by sock_cleanup(), and sock_init().


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