comctl32/tests: Remove some workarounds that no longer apply.
[wine.git] / dlls / wpcap / wpcap.c
blobfe469031be349b6fb15091a866458e7e705e4132
1 /*
2 * WPcap.dll Proxy.
4 * Copyright 2011, 2014 André Hentschel
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <pcap/pcap.h>
23 /* pcap.h might define those: */
24 #undef SOCKET
25 #undef INVALID_SOCKET
27 #include "winsock2.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(wpcap);
33 WINE_DECLARE_DEBUG_CHANNEL(winediag);
35 #ifndef PCAP_SRC_FILE_STRING
36 #define PCAP_SRC_FILE_STRING "file://"
37 #endif
38 #ifndef PCAP_SRC_FILE
39 #define PCAP_SRC_FILE 2
40 #endif
41 #ifndef PCAP_SRC_IF_STRING
42 #define PCAP_SRC_IF_STRING "rpcap://"
43 #endif
44 #ifndef PCAP_SRC_IFLOCAL
45 #define PCAP_SRC_IFLOCAL 3
46 #endif
48 void CDECL wine_pcap_breakloop(pcap_t *p)
50 TRACE("(%p)\n", p);
51 return pcap_breakloop(p);
54 void CDECL wine_pcap_close(pcap_t *p)
56 TRACE("(%p)\n", p);
57 pcap_close(p);
60 int CDECL wine_pcap_compile(pcap_t *p, struct bpf_program *program, const char *buf, int optimize,
61 unsigned int mask)
63 TRACE("(%p %p %s %i %u)\n", p, program, debugstr_a(buf), optimize, mask);
64 return pcap_compile(p, program, buf, optimize, mask);
67 int CDECL wine_pcap_datalink(pcap_t *p)
69 TRACE("(%p)\n", p);
70 return pcap_datalink(p);
73 int CDECL wine_pcap_datalink_name_to_val(const char *name)
75 TRACE("(%s)\n", debugstr_a(name));
76 return pcap_datalink_name_to_val(name);
79 const char* CDECL wine_pcap_datalink_val_to_description(int dlt)
81 TRACE("(%i)\n", dlt);
82 return pcap_datalink_val_to_description(dlt);
85 const char* CDECL wine_pcap_datalink_val_to_name(int dlt)
87 TRACE("(%i)\n", dlt);
88 return pcap_datalink_val_to_name(dlt);
91 typedef struct
93 void (CALLBACK *pfn_cb)(u_char *, const struct pcap_pkthdr *, const u_char *);
94 void *user_data;
95 } PCAP_HANDLER_CALLBACK;
97 static void pcap_handler_callback(u_char *user_data, const struct pcap_pkthdr *h, const u_char *p)
99 PCAP_HANDLER_CALLBACK *pcb;
100 TRACE("(%p %p %p)\n", user_data, h, p);
101 pcb = (PCAP_HANDLER_CALLBACK *)user_data;
102 pcb->pfn_cb(pcb->user_data, h, p);
103 TRACE("Callback COMPLETED\n");
106 int CDECL wine_pcap_dispatch(pcap_t *p, int cnt,
107 void (CALLBACK *callback)(u_char *, const struct pcap_pkthdr *, const u_char *),
108 unsigned char *user)
110 TRACE("(%p %i %p %p)\n", p, cnt, callback, user);
112 if (callback)
114 PCAP_HANDLER_CALLBACK pcb;
115 pcb.pfn_cb = callback;
116 pcb.user_data = user;
117 return pcap_dispatch(p, cnt, pcap_handler_callback, (unsigned char *)&pcb);
120 return pcap_dispatch(p, cnt, NULL, user);
123 int CDECL wine_pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
125 int ret;
127 TRACE("(%p %p)\n", alldevsp, errbuf);
128 ret = pcap_findalldevs(alldevsp, errbuf);
129 if(alldevsp && !*alldevsp)
130 ERR_(winediag)("Failed to access raw network (pcap), this requires special permissions.\n");
132 return ret;
135 int CDECL wine_pcap_findalldevs_ex(char *source, void *auth, pcap_if_t **alldevs, char *errbuf)
137 FIXME("(%s %p %p %p): partial stub\n", debugstr_a(source), auth, alldevs, errbuf);
138 return wine_pcap_findalldevs(alldevs, errbuf);
141 void CDECL wine_pcap_freealldevs(pcap_if_t *alldevs)
143 TRACE("(%p)\n", alldevs);
144 pcap_freealldevs(alldevs);
147 void CDECL wine_pcap_freecode(struct bpf_program *fp)
149 TRACE("(%p)\n", fp);
150 return pcap_freecode(fp);
153 typedef struct _AirpcapHandle *PAirpcapHandle;
154 PAirpcapHandle CDECL wine_pcap_get_airpcap_handle(pcap_t *p)
156 TRACE("(%p)\n", p);
157 return NULL;
160 char* CDECL wine_pcap_geterr(pcap_t *p)
162 TRACE("(%p)\n", p);
163 return pcap_geterr(p);
166 int CDECL wine_pcap_getnonblock(pcap_t *p, char *errbuf)
168 TRACE("(%p %p)\n", p, errbuf);
169 return pcap_getnonblock(p, errbuf);
172 const char* CDECL wine_pcap_lib_version(void)
174 const char* ret = pcap_lib_version();
175 TRACE("%s\n", debugstr_a(ret));
176 return ret;
179 int CDECL wine_pcap_list_datalinks(pcap_t *p, int **dlt_buffer)
181 TRACE("(%p %p)\n", p, dlt_buffer);
182 return pcap_list_datalinks(p, dlt_buffer);
185 char* CDECL wine_pcap_lookupdev(char *errbuf)
187 TRACE("(%p)\n", errbuf);
188 return pcap_lookupdev(errbuf);
191 int CDECL wine_pcap_lookupnet(const char *device, unsigned int *netp, unsigned int *maskp,
192 char *errbuf)
194 TRACE("(%s %p %p %p)\n", debugstr_a(device), netp, maskp, errbuf);
195 return pcap_lookupnet(device, netp, maskp, errbuf);
198 int CDECL wine_pcap_loop(pcap_t *p, int cnt,
199 void (CALLBACK *callback)(u_char *, const struct pcap_pkthdr *, const u_char *),
200 unsigned char *user)
202 TRACE("(%p %i %p %p)\n", p, cnt, callback, user);
204 if (callback)
206 PCAP_HANDLER_CALLBACK pcb;
207 pcb.pfn_cb = callback;
208 pcb.user_data = user;
209 return pcap_loop(p, cnt, pcap_handler_callback, (unsigned char *)&pcb);
212 return pcap_loop(p, cnt, NULL, user);
215 int CDECL wine_pcap_major_version(pcap_t *p)
217 TRACE("(%p)\n", p);
218 return pcap_major_version(p);
221 int CDECL wine_pcap_minor_version(pcap_t *p)
223 TRACE("(%p)\n", p);
224 return pcap_minor_version(p);
227 const unsigned char* CDECL wine_pcap_next(pcap_t *p, struct pcap_pkthdr *h)
229 TRACE("(%p %p)\n", p, h);
230 return pcap_next(p, h);
233 int CDECL wine_pcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header, const unsigned char **pkt_data)
235 TRACE("(%p %p %p)\n", p, pkt_header, pkt_data);
236 return pcap_next_ex(p, pkt_header, pkt_data);
239 #define PCAP_OPENFLAG_PROMISCUOUS 1
241 pcap_t* CDECL wine_pcap_open(const char *source, int snaplen, int flags, int read_timeout,
242 void *auth, char *errbuf)
244 int promisc = flags & PCAP_OPENFLAG_PROMISCUOUS;
245 FIXME("(%s %i %i %i %p %p): partial stub\n", debugstr_a(source), snaplen, flags, read_timeout,
246 auth, errbuf);
247 return pcap_open_live(source, snaplen, promisc, read_timeout, errbuf);
250 pcap_t* CDECL wine_pcap_open_live(const char *source, int snaplen, int promisc, int to_ms,
251 char *errbuf)
253 TRACE("(%s %i %i %i %p)\n", debugstr_a(source), snaplen, promisc, to_ms, errbuf);
254 return pcap_open_live(source, snaplen, promisc, to_ms, errbuf);
257 int CDECL wine_pcap_parsesrcstr(const char *source, int *type, char *host, char *port, char *name, char *errbuf)
259 int t = PCAP_SRC_IFLOCAL;
260 const char *p = source;
262 FIXME("(%s %p %p %p %p %p): partial stub\n", debugstr_a(source), type, host, port, name, errbuf);
264 if (host)
265 *host = '\0';
266 if (port)
267 *port = '\0';
268 if (name)
269 *name = '\0';
271 if (!strncmp(p, PCAP_SRC_IF_STRING, strlen(PCAP_SRC_IF_STRING)))
272 p += strlen(PCAP_SRC_IF_STRING);
273 else if (!strncmp(p, PCAP_SRC_FILE_STRING, strlen(PCAP_SRC_FILE_STRING)))
275 p += strlen(PCAP_SRC_FILE_STRING);
276 t = PCAP_SRC_FILE;
279 if (type)
280 *type = t;
282 if (!*p)
284 if (errbuf)
285 sprintf(errbuf, "The name has not been specified in the source string.");
286 return -1;
289 if (name)
290 strcpy(name, p);
292 return 0;
295 int CDECL wine_pcap_sendpacket(pcap_t *p, const unsigned char *buf, int size)
297 TRACE("(%p %p %i)\n", p, buf, size);
298 return pcap_sendpacket(p, buf, size);
301 int CDECL wine_pcap_set_datalink(pcap_t *p, int dlt)
303 TRACE("(%p %i)\n", p, dlt);
304 return pcap_set_datalink(p, dlt);
307 int CDECL wine_pcap_setbuff(pcap_t * p, int dim)
309 FIXME("(%p %i) stub\n", p, dim);
310 return 0;
313 int CDECL wine_pcap_setfilter(pcap_t *p, struct bpf_program *fp)
315 TRACE("(%p %p)\n", p, fp);
316 return pcap_setfilter(p, fp);
319 int CDECL wine_pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf)
321 TRACE("(%p %i %p)\n", p, nonblock, errbuf);
322 return pcap_setnonblock(p, nonblock, errbuf);
325 int CDECL wine_pcap_snapshot(pcap_t *p)
327 TRACE("(%p)\n", p);
328 return pcap_snapshot(p);
331 int CDECL wine_pcap_stats(pcap_t *p, struct pcap_stat *ps)
333 TRACE("(%p %p)\n", p, ps);
334 return pcap_stats(p, ps);
337 int CDECL wine_wsockinit(void)
339 WSADATA wsadata;
340 TRACE("()\n");
341 if (WSAStartup(MAKEWORD(1,1), &wsadata)) return -1;
342 return 0;