]> The Tcpdump Group git mirrors - libpcap/blob - sockutils.h
f39ad0002de18f36b84e88a907e88c0bf7fe6944
[libpcap] / sockutils.h
1 /*
2 * Copyright (c) 2002 - 2003
3 * NetGroup, Politecnico di Torino (Italy)
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Politecnico di Torino nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32
33 #ifndef __SOCKUTILS_H__
34 #define __SOCKUTILS_H__
35
36 #ifdef _MSC_VER
37 #pragma once
38 #endif
39
40 #include "pcap/socket.h"
41 #include "pcap/funcattrs.h"
42
43 #ifndef _WIN32
44 /* UN*X */
45 #include <unistd.h> /* close() */
46
47 /*!
48 * \brief In Winsock, the close() call cannot be used on a socket;
49 * closesocket() must be used.
50 * We define closesocket() to be a wrapper around close() on UN*X,
51 * so that it can be used on both platforms.
52 */
53 #define closesocket(a) close(a)
54 #endif
55
56 #include "sslutils.h" // for SSL type, whatever that turns out to be
57
58 /*
59 * MingW headers include this definition, but only for Windows XP and above.
60 * MSDN states that this function is available for most versions on Windows.
61 */
62 #if ((defined(__MINGW32__)) && (_WIN32_WINNT < 0x0501))
63 PCAP_UNEXPORTED_C_FUNC int WSAAPI getnameinfo(const struct sockaddr*, socklen_t, char*,
64 DWORD, char*, DWORD, int);
65 #endif
66
67 /*
68 * \defgroup SockUtils Cross-platform socket utilities (IPv4-IPv6)
69 */
70
71 /*
72 * \addtogroup SockUtils
73 * \{
74 */
75
76 /*
77 * \defgroup ExportedStruct Exported Structures and Definitions
78 */
79
80 /*
81 * \addtogroup ExportedStruct
82 * \{
83 */
84
85 /****************************************************
86 * *
87 * Exported functions / definitions *
88 * *
89 ****************************************************/
90
91 /* 'checkonly' flag, into the rpsock_bufferize() */
92 #define SOCKBUF_CHECKONLY 1
93 /* no 'checkonly' flag, into the rpsock_bufferize() */
94 #define SOCKBUF_BUFFERIZE 0
95
96 /* no 'server' flag; it opens a client socket */
97 #define SOCKOPEN_CLIENT 0
98 /* 'server' flag; it opens a server socket */
99 #define SOCKOPEN_SERVER 1
100
101 /*
102 * Flags for sock_recv().
103 */
104 #define SOCK_RECEIVEALL_NO 0x00000000 /* Don't wait to receive all data */
105 #define SOCK_RECEIVEALL_YES 0x00000001 /* Wait to receive all data */
106
107 #define SOCK_EOF_ISNT_ERROR 0x00000000 /* Return 0 on EOF */
108 #define SOCK_EOF_IS_ERROR 0x00000002 /* Return an error on EOF */
109
110 #define SOCK_MSG_PEEK 0x00000004 /* Return data but leave it in the socket queue */
111
112 /*
113 * \}
114 */
115
116 /*
117 * \defgroup ExportedFunc Exported Functions
118 */
119
120 /*
121 * \addtogroup ExportedFunc
122 * \{
123 */
124
125 PCAP_UNEXPORTED_C_FUNC int sock_init(char *errbuf, int errbuflen);
126 PCAP_UNEXPORTED_C_FUNC void sock_cleanup(void);
127 PCAP_UNEXPORTED_C_FUNC void sock_fmterror(const char *caller, int errcode, char *errbuf,
128 int errbuflen);
129 PCAP_UNEXPORTED_C_FUNC void sock_geterror(const char *caller, char *errbuf,
130 int errbufsize);
131 PCAP_UNEXPORTED_C_FUNC int sock_initaddress(const char *address, const char *port,
132 struct addrinfo *hints, struct addrinfo **addrinfo,
133 char *errbuf, int errbuflen);
134 PCAP_UNEXPORTED_C_FUNC int sock_recv(SOCKET sock, SSL *, void *buffer, size_t size,
135 int receiveall, char *errbuf, int errbuflen);
136 PCAP_UNEXPORTED_C_FUNC int sock_recv_dgram(SOCKET sock, SSL *, void *buffer, size_t size,
137 char *errbuf, int errbuflen);
138 PCAP_UNEXPORTED_C_FUNC SOCKET sock_open(struct addrinfo *addrinfo, int server,
139 int nconn, char *errbuf, int errbuflen);
140 PCAP_UNEXPORTED_C_FUNC int sock_close(SOCKET sock, char *errbuf, int errbuflen);
141
142 PCAP_UNEXPORTED_C_FUNC int sock_send(SOCKET sock, SSL *, const char *buffer, size_t size,
143 char *errbuf, int errbuflen);
144 PCAP_UNEXPORTED_C_FUNC int sock_bufferize(const char *buffer, int size, char *tempbuf,
145 int *offset, int totsize, int checkonly, char *errbuf, int errbuflen);
146 PCAP_UNEXPORTED_C_FUNC int sock_discard(SOCKET sock, SSL *, int size, char *errbuf,
147 int errbuflen);
148 PCAP_UNEXPORTED_C_FUNC int sock_check_hostlist(char *hostlist, const char *sep,
149 struct sockaddr_storage *from, char *errbuf, int errbuflen);
150 PCAP_UNEXPORTED_C_FUNC int sock_cmpaddr(struct sockaddr_storage *first,
151 struct sockaddr_storage *second);
152
153 PCAP_UNEXPORTED_C_FUNC int sock_getmyinfo(SOCKET sock, char *address, int addrlen,
154 char *port, int portlen, int flags, char *errbuf, int errbuflen);
155
156 PCAP_UNEXPORTED_C_FUNC int sock_getascii_addrport(const struct sockaddr_storage *sockaddr,
157 char *address, int addrlen, char *port, int portlen, int flags,
158 char *errbuf, int errbuflen);
159 PCAP_UNEXPORTED_C_FUNC int sock_present2network(const char *address,
160 struct sockaddr_storage *sockaddr, int addr_family, char *errbuf,
161 int errbuflen);
162
163 /*
164 * \}
165 */
166
167 /*
168 * \}
169 */
170
171 #endif