wpcap: Implement pcap_sendpacket.
[wine.git] / dlls / wpcap / wpcap.c
blobb1a2149e9e311de726b13c6ed8e9ea28a76be366
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>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(wpcap);
27 WINE_DECLARE_DEBUG_CHANNEL(winediag);
29 void CDECL wine_pcap_breakloop(pcap_t *p)
31 TRACE("(%p)\n", p);
32 return pcap_breakloop(p);
35 void CDECL wine_pcap_close(pcap_t *p)
37 TRACE("(%p)\n", p);
38 pcap_close(p);
41 int CDECL wine_pcap_compile(pcap_t *p, struct bpf_program *program, const char *buf, int optimize,
42 unsigned int mask)
44 TRACE("(%p %p %s %i %u)\n", p, program, debugstr_a(buf), optimize, mask);
45 return pcap_compile(p, program, buf, optimize, mask);
48 int CDECL wine_pcap_datalink(pcap_t *p)
50 TRACE("(%p)\n", p);
51 return pcap_datalink(p);
54 int CDECL wine_pcap_datalink_name_to_val(const char *name)
56 TRACE("(%s)\n", debugstr_a(name));
57 return pcap_datalink_name_to_val(name);
60 const char* CDECL wine_pcap_datalink_val_to_description(int dlt)
62 TRACE("(%i)\n", dlt);
63 return pcap_datalink_val_to_description(dlt);
66 const char* CDECL wine_pcap_datalink_val_to_name(int dlt)
68 TRACE("(%i)\n", dlt);
69 return pcap_datalink_val_to_name(dlt);
72 typedef struct
74 void (CALLBACK *pfn_cb)(u_char *, const struct pcap_pkthdr *, const u_char *);
75 void *user_data;
76 } PCAP_HANDLER_CALLBACK;
78 static void pcap_handler_callback(u_char *user_data, const struct pcap_pkthdr *h, const u_char *p)
80 PCAP_HANDLER_CALLBACK *pcb;
81 TRACE("(%p %p %p)\n", user_data, h, p);
82 pcb = (PCAP_HANDLER_CALLBACK *)user_data;
83 pcb->pfn_cb(pcb->user_data, h, p);
84 HeapFree(GetProcessHeap(), 0, pcb);
85 TRACE("Callback COMPLETED\n");
88 int CDECL wine_pcap_dispatch(pcap_t *p, int cnt,
89 void (CALLBACK *callback)(u_char *, const struct pcap_pkthdr *, const u_char *),
90 unsigned char *user)
92 TRACE("(%p %i %p %p)\n", p, cnt, callback, user);
94 if (callback)
96 PCAP_HANDLER_CALLBACK *pcb;
97 pcb = HeapAlloc(GetProcessHeap(), 0, sizeof(PCAP_HANDLER_CALLBACK));
98 pcb->pfn_cb = callback;
99 pcb->user_data = user;
100 return pcap_dispatch(p, cnt, pcap_handler_callback, (unsigned char*)pcb);
103 return pcap_dispatch(p, cnt, NULL, user);
106 int CDECL wine_pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
108 int ret;
110 TRACE("(%p %p)\n", alldevsp, errbuf);
111 ret = pcap_findalldevs(alldevsp, errbuf);
112 if(alldevsp && !*alldevsp)
113 ERR_(winediag)("Failed to access raw network (pcap), this requires special permissions.\n");
115 return ret;
118 void CDECL wine_pcap_freealldevs(pcap_if_t *alldevs)
120 TRACE("(%p)\n", alldevs);
121 pcap_freealldevs(alldevs);
124 void CDECL wine_pcap_freecode(struct bpf_program *fp)
126 TRACE("(%p)\n", fp);
127 return pcap_freecode(fp);
130 typedef struct _AirpcapHandle *PAirpcapHandle;
131 PAirpcapHandle CDECL wine_pcap_get_airpcap_handle(pcap_t *p)
133 TRACE("(%p)\n", p);
134 return NULL;
137 char* CDECL wine_pcap_geterr(pcap_t *p)
139 TRACE("(%p)\n", p);
140 return pcap_geterr(p);
143 int CDECL wine_pcap_getnonblock(pcap_t *p, char *errbuf)
145 TRACE("(%p %p)\n", p, errbuf);
146 return pcap_getnonblock(p, errbuf);
149 const char* CDECL wine_pcap_lib_version(void)
151 const char* ret = pcap_lib_version();
152 TRACE("%s\n", debugstr_a(ret));
153 return ret;
156 int CDECL wine_pcap_list_datalinks(pcap_t *p, int **dlt_buffer)
158 TRACE("(%p %p)\n", p, dlt_buffer);
159 return pcap_list_datalinks(p, dlt_buffer);
162 char* CDECL wine_pcap_lookupdev(char *errbuf)
164 TRACE("(%p)\n", errbuf);
165 return pcap_lookupdev(errbuf);
168 int CDECL wine_pcap_lookupnet(const char *device, unsigned int *netp, unsigned int *maskp,
169 char *errbuf)
171 TRACE("(%s %p %p %p)\n", debugstr_a(device), netp, maskp, errbuf);
172 return pcap_lookupnet(device, netp, maskp, errbuf);
175 int CDECL wine_pcap_loop(pcap_t *p, int cnt,
176 void (CALLBACK *callback)(u_char *, const struct pcap_pkthdr *, const u_char *),
177 unsigned char *user)
179 TRACE("(%p %i %p %p)\n", p, cnt, callback, user);
181 if (callback)
183 PCAP_HANDLER_CALLBACK *pcb;
184 pcb = HeapAlloc(GetProcessHeap(), 0, sizeof(PCAP_HANDLER_CALLBACK));
185 pcb->pfn_cb = callback;
186 pcb->user_data = user;
187 return pcap_loop(p, cnt, pcap_handler_callback, (unsigned char*)pcb);
190 return pcap_loop(p, cnt, NULL, user);
193 int CDECL wine_pcap_major_version(pcap_t *p)
195 TRACE("(%p)\n", p);
196 return pcap_major_version(p);
199 int CDECL wine_pcap_minor_version(pcap_t *p)
201 TRACE("(%p)\n", p);
202 return pcap_minor_version(p);
205 const unsigned char* CDECL wine_pcap_next(pcap_t *p, struct pcap_pkthdr *h)
207 TRACE("(%p %p)\n", p, h);
208 return pcap_next(p, h);
211 int CDECL wine_pcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header, const unsigned char **pkt_data)
213 TRACE("(%p %p %p)\n", p, pkt_header, pkt_data);
214 return pcap_next_ex(p, pkt_header, pkt_data);
217 #define PCAP_OPENFLAG_PROMISCUOUS 1
219 pcap_t* CDECL wine_pcap_open(const char *source, int snaplen, int flags, int read_timeout,
220 void *auth, char *errbuf)
222 int promisc = flags & PCAP_OPENFLAG_PROMISCUOUS;
223 FIXME("(%s %i %i %i %p %p): partial stub\n", debugstr_a(source), snaplen, flags, read_timeout,
224 auth, errbuf);
225 return pcap_open_live(source, snaplen, promisc, read_timeout, errbuf);
228 pcap_t* CDECL wine_pcap_open_live(const char *source, int snaplen, int promisc, int to_ms,
229 char *errbuf)
231 TRACE("(%s %i %i %i %p)\n", debugstr_a(source), snaplen, promisc, to_ms, errbuf);
232 return pcap_open_live(source, snaplen, promisc, to_ms, errbuf);
235 int CDECL wine_pcap_sendpacket(pcap_t *p, const unsigned char *buf, int size)
237 TRACE("(%p %p %i)\n", p, buf, size);
238 return pcap_sendpacket(p, buf, size);
241 int CDECL wine_pcap_set_datalink(pcap_t *p, int dlt)
243 TRACE("(%p %i)\n", p, dlt);
244 return pcap_set_datalink(p, dlt);
247 int CDECL wine_pcap_setbuff(pcap_t * p, int dim)
249 FIXME("(%p %i) stub\n", p, dim);
250 return 0;
253 int CDECL wine_pcap_setfilter(pcap_t *p, struct bpf_program *fp)
255 TRACE("(%p %p)\n", p, fp);
256 return pcap_setfilter(p, fp);
259 int CDECL wine_pcap_snapshot(pcap_t *p)
261 TRACE("(%p)\n", p);
262 return pcap_snapshot(p);
265 int CDECL wine_pcap_stats(pcap_t *p, struct pcap_stat *ps)
267 TRACE("(%p %p)\n", p, ps);
268 return pcap_stats(p, ps);