1335640Shselasky/* 2335640Shselasky * Copyright (c) 2002 - 2003 3335640Shselasky * NetGroup, Politecnico di Torino (Italy) 4335640Shselasky * All rights reserved. 5335640Shselasky * 6335640Shselasky * Redistribution and use in source and binary forms, with or without 7335640Shselasky * modification, are permitted provided that the following conditions 8335640Shselasky * are met: 9335640Shselasky * 10335640Shselasky * 1. Redistributions of source code must retain the above copyright 11335640Shselasky * notice, this list of conditions and the following disclaimer. 12335640Shselasky * 2. Redistributions in binary form must reproduce the above copyright 13335640Shselasky * notice, this list of conditions and the following disclaimer in the 14335640Shselasky * documentation and/or other materials provided with the distribution. 15335640Shselasky * 3. Neither the name of the Politecnico di Torino nor the names of its 16335640Shselasky * contributors may be used to endorse or promote products derived from 17335640Shselasky * this software without specific prior written permission. 18335640Shselasky * 19335640Shselasky * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20335640Shselasky * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21335640Shselasky * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22335640Shselasky * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23335640Shselasky * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24335640Shselasky * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25335640Shselasky * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26335640Shselasky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27335640Shselasky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28335640Shselasky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29335640Shselasky * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30335640Shselasky * 31335640Shselasky */ 32335640Shselasky 33335640Shselasky#ifndef __SOCKUTILS_H__ 34335640Shselasky#define __SOCKUTILS_H__ 35335640Shselasky 36335640Shselasky#ifdef _MSC_VER 37335640Shselasky#pragma once 38335640Shselasky#endif 39335640Shselasky 40356341Scy#include "pcap/socket.h" 41335640Shselasky 42356341Scy#ifndef _WIN32 43335640Shselasky /* UN*X */ 44335640Shselasky #include <unistd.h> /* close() */ 45335640Shselasky 46335640Shselasky /*! 47335640Shselasky * \brief In Winsock, the close() call cannot be used on a socket; 48335640Shselasky * closesocket() must be used. 49335640Shselasky * We define closesocket() to be a wrapper around close() on UN*X, 50335640Shselasky * so that it can be used on both platforms. 51335640Shselasky */ 52335640Shselasky #define closesocket(a) close(a) 53335640Shselasky#endif 54335640Shselasky 55335640Shselasky/* 56335640Shselasky * MingW headers include this definition, but only for Windows XP and above. 57335640Shselasky * MSDN states that this function is available for most versions on Windows. 58335640Shselasky */ 59335640Shselasky#if ((defined(__MINGW32__)) && (_WIN32_WINNT < 0x0501)) 60335640Shselaskyint WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD, 61335640Shselasky char*,DWORD,int); 62335640Shselasky#endif 63335640Shselasky 64335640Shselasky/* 65335640Shselasky * \defgroup SockUtils Cross-platform socket utilities (IPv4-IPv6) 66335640Shselasky */ 67335640Shselasky 68335640Shselasky/* 69335640Shselasky * \addtogroup SockUtils 70335640Shselasky * \{ 71335640Shselasky */ 72335640Shselasky 73335640Shselasky/* 74335640Shselasky * \defgroup ExportedStruct Exported Structures and Definitions 75335640Shselasky */ 76335640Shselasky 77335640Shselasky/* 78335640Shselasky * \addtogroup ExportedStruct 79335640Shselasky * \{ 80335640Shselasky */ 81335640Shselasky 82335640Shselasky/**************************************************** 83335640Shselasky * * 84335640Shselasky * Exported functions / definitions * 85335640Shselasky * * 86335640Shselasky ****************************************************/ 87335640Shselasky 88335640Shselasky/* 'checkonly' flag, into the rpsock_bufferize() */ 89335640Shselasky#define SOCKBUF_CHECKONLY 1 90335640Shselasky/* no 'checkonly' flag, into the rpsock_bufferize() */ 91335640Shselasky#define SOCKBUF_BUFFERIZE 0 92335640Shselasky 93335640Shselasky/* no 'server' flag; it opens a client socket */ 94335640Shselasky#define SOCKOPEN_CLIENT 0 95335640Shselasky/* 'server' flag; it opens a server socket */ 96335640Shselasky#define SOCKOPEN_SERVER 1 97335640Shselasky 98335640Shselasky/* 99335640Shselasky * Flags for sock_recv(). 100335640Shselasky */ 101335640Shselasky#define SOCK_RECEIVEALL_NO 0x00000000 /* Don't wait to receive all data */ 102335640Shselasky#define SOCK_RECEIVEALL_YES 0x00000001 /* Wait to receive all data */ 103335640Shselasky 104335640Shselasky#define SOCK_EOF_ISNT_ERROR 0x00000000 /* Return 0 on EOF */ 105335640Shselasky#define SOCK_EOF_IS_ERROR 0x00000002 /* Return an error on EOF */ 106335640Shselasky 107335640Shselasky/* 108335640Shselasky * \} 109335640Shselasky */ 110335640Shselasky 111335640Shselasky#ifdef __cplusplus 112335640Shselaskyextern "C" { 113335640Shselasky#endif 114335640Shselasky 115335640Shselasky/* 116335640Shselasky * \defgroup ExportedFunc Exported Functions 117335640Shselasky */ 118335640Shselasky 119335640Shselasky/* 120335640Shselasky * \addtogroup ExportedFunc 121335640Shselasky * \{ 122335640Shselasky */ 123335640Shselasky 124335640Shselaskyint sock_init(char *errbuf, int errbuflen); 125335640Shselaskyvoid sock_cleanup(void); 126335640Shselaskyvoid sock_fmterror(const char *caller, int errcode, char *errbuf, int errbuflen); 127335640Shselaskyvoid sock_geterror(const char *caller, char *errbuf, int errbufsize); 128335640Shselaskyint sock_initaddress(const char *address, const char *port, 129335640Shselasky struct addrinfo *hints, struct addrinfo **addrinfo, 130335640Shselasky char *errbuf, int errbuflen); 131335640Shselaskyint sock_recv(SOCKET sock, void *buffer, size_t size, int receiveall, 132335640Shselasky char *errbuf, int errbuflen); 133335640Shselaskyint sock_recv_dgram(SOCKET sock, void *buffer, size_t size, 134335640Shselasky char *errbuf, int errbuflen); 135335640ShselaskySOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf, int errbuflen); 136335640Shselaskyint sock_close(SOCKET sock, char *errbuf, int errbuflen); 137335640Shselasky 138335640Shselaskyint sock_send(SOCKET sock, const char *buffer, size_t size, 139335640Shselasky char *errbuf, int errbuflen); 140335640Shselaskyint sock_bufferize(const char *buffer, int size, char *tempbuf, int *offset, int totsize, int checkonly, char *errbuf, int errbuflen); 141335640Shselaskyint sock_discard(SOCKET sock, int size, char *errbuf, int errbuflen); 142335640Shselaskyint sock_check_hostlist(char *hostlist, const char *sep, struct sockaddr_storage *from, char *errbuf, int errbuflen); 143335640Shselaskyint sock_cmpaddr(struct sockaddr_storage *first, struct sockaddr_storage *second); 144335640Shselasky 145335640Shselaskyint sock_getmyinfo(SOCKET sock, char *address, int addrlen, char *port, int portlen, int flags, char *errbuf, int errbuflen); 146335640Shselasky 147335640Shselaskyint sock_getascii_addrport(const struct sockaddr_storage *sockaddr, char *address, int addrlen, char *port, int portlen, int flags, char *errbuf, int errbuflen); 148335640Shselaskyint sock_present2network(const char *address, struct sockaddr_storage *sockaddr, int addr_family, char *errbuf, int errbuflen); 149335640Shselasky 150335640Shselasky#ifdef __cplusplus 151335640Shselasky} 152335640Shselasky#endif 153335640Shselasky 154335640Shselasky/* 155335640Shselasky * \} 156335640Shselasky */ 157335640Shselasky 158335640Shselasky/* 159335640Shselasky * \} 160335640Shselasky */ 161335640Shselasky 162335640Shselasky#endif 163