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>
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(wpcap
);
28 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
30 void CDECL
wine_pcap_breakloop(pcap_t
*p
)
33 return pcap_breakloop(p
);
36 void CDECL
wine_pcap_close(pcap_t
*p
)
42 int CDECL
wine_pcap_compile(pcap_t
*p
, struct bpf_program
*program
, const char *buf
, int optimize
,
45 TRACE("(%p %p %s %i %u)\n", p
, program
, debugstr_a(buf
), optimize
, mask
);
46 return pcap_compile(p
, program
, buf
, optimize
, mask
);
49 int CDECL
wine_pcap_datalink(pcap_t
*p
)
52 return pcap_datalink(p
);
55 int CDECL
wine_pcap_datalink_name_to_val(const char *name
)
57 TRACE("(%s)\n", debugstr_a(name
));
58 return pcap_datalink_name_to_val(name
);
61 const char* CDECL
wine_pcap_datalink_val_to_description(int dlt
)
64 return pcap_datalink_val_to_description(dlt
);
67 const char* CDECL
wine_pcap_datalink_val_to_name(int dlt
)
70 return pcap_datalink_val_to_name(dlt
);
75 void (CALLBACK
*pfn_cb
)(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
77 } PCAP_HANDLER_CALLBACK
;
79 static void pcap_handler_callback(u_char
*user_data
, const struct pcap_pkthdr
*h
, const u_char
*p
)
81 PCAP_HANDLER_CALLBACK
*pcb
;
82 TRACE("(%p %p %p)\n", user_data
, h
, p
);
83 pcb
= (PCAP_HANDLER_CALLBACK
*)user_data
;
84 pcb
->pfn_cb(pcb
->user_data
, h
, p
);
85 HeapFree(GetProcessHeap(), 0, pcb
);
86 TRACE("Callback COMPLETED\n");
89 int CDECL
wine_pcap_dispatch(pcap_t
*p
, int cnt
,
90 void (CALLBACK
*callback
)(u_char
*, const struct pcap_pkthdr
*, const u_char
*),
93 TRACE("(%p %i %p %p)\n", p
, cnt
, callback
, user
);
97 PCAP_HANDLER_CALLBACK
*pcb
;
98 pcb
= HeapAlloc(GetProcessHeap(), 0, sizeof(PCAP_HANDLER_CALLBACK
));
99 pcb
->pfn_cb
= callback
;
100 pcb
->user_data
= user
;
101 return pcap_dispatch(p
, cnt
, pcap_handler_callback
, (unsigned char*)pcb
);
104 return pcap_dispatch(p
, cnt
, NULL
, user
);
107 int CDECL
wine_pcap_findalldevs(pcap_if_t
**alldevsp
, char *errbuf
)
111 TRACE("(%p %p)\n", alldevsp
, errbuf
);
112 ret
= pcap_findalldevs(alldevsp
, errbuf
);
113 if(alldevsp
&& !*alldevsp
)
114 ERR_(winediag
)("Failed to access raw network (pcap), this requires special permissions.\n");
119 int CDECL
wine_pcap_findalldevs_ex(char *source
, void *auth
, pcap_if_t
**alldevs
, char *errbuf
)
121 FIXME("(%s %p %p %p): partial stub\n", debugstr_a(source
), auth
, alldevs
, errbuf
);
122 return wine_pcap_findalldevs(alldevs
, errbuf
);
125 void CDECL
wine_pcap_freealldevs(pcap_if_t
*alldevs
)
127 TRACE("(%p)\n", alldevs
);
128 pcap_freealldevs(alldevs
);
131 void CDECL
wine_pcap_freecode(struct bpf_program
*fp
)
134 return pcap_freecode(fp
);
137 typedef struct _AirpcapHandle
*PAirpcapHandle
;
138 PAirpcapHandle CDECL
wine_pcap_get_airpcap_handle(pcap_t
*p
)
144 char* CDECL
wine_pcap_geterr(pcap_t
*p
)
147 return pcap_geterr(p
);
150 int CDECL
wine_pcap_getnonblock(pcap_t
*p
, char *errbuf
)
152 TRACE("(%p %p)\n", p
, errbuf
);
153 return pcap_getnonblock(p
, errbuf
);
156 const char* CDECL
wine_pcap_lib_version(void)
158 const char* ret
= pcap_lib_version();
159 TRACE("%s\n", debugstr_a(ret
));
163 int CDECL
wine_pcap_list_datalinks(pcap_t
*p
, int **dlt_buffer
)
165 TRACE("(%p %p)\n", p
, dlt_buffer
);
166 return pcap_list_datalinks(p
, dlt_buffer
);
169 char* CDECL
wine_pcap_lookupdev(char *errbuf
)
171 TRACE("(%p)\n", errbuf
);
172 return pcap_lookupdev(errbuf
);
175 int CDECL
wine_pcap_lookupnet(const char *device
, unsigned int *netp
, unsigned int *maskp
,
178 TRACE("(%s %p %p %p)\n", debugstr_a(device
), netp
, maskp
, errbuf
);
179 return pcap_lookupnet(device
, netp
, maskp
, errbuf
);
182 int CDECL
wine_pcap_loop(pcap_t
*p
, int cnt
,
183 void (CALLBACK
*callback
)(u_char
*, const struct pcap_pkthdr
*, const u_char
*),
186 TRACE("(%p %i %p %p)\n", p
, cnt
, callback
, user
);
190 PCAP_HANDLER_CALLBACK
*pcb
;
191 pcb
= HeapAlloc(GetProcessHeap(), 0, sizeof(PCAP_HANDLER_CALLBACK
));
192 pcb
->pfn_cb
= callback
;
193 pcb
->user_data
= user
;
194 return pcap_loop(p
, cnt
, pcap_handler_callback
, (unsigned char*)pcb
);
197 return pcap_loop(p
, cnt
, NULL
, user
);
200 int CDECL
wine_pcap_major_version(pcap_t
*p
)
203 return pcap_major_version(p
);
206 int CDECL
wine_pcap_minor_version(pcap_t
*p
)
209 return pcap_minor_version(p
);
212 const unsigned char* CDECL
wine_pcap_next(pcap_t
*p
, struct pcap_pkthdr
*h
)
214 TRACE("(%p %p)\n", p
, h
);
215 return pcap_next(p
, h
);
218 int CDECL
wine_pcap_next_ex(pcap_t
*p
, struct pcap_pkthdr
**pkt_header
, const unsigned char **pkt_data
)
220 TRACE("(%p %p %p)\n", p
, pkt_header
, pkt_data
);
221 return pcap_next_ex(p
, pkt_header
, pkt_data
);
224 #define PCAP_OPENFLAG_PROMISCUOUS 1
226 pcap_t
* CDECL
wine_pcap_open(const char *source
, int snaplen
, int flags
, int read_timeout
,
227 void *auth
, char *errbuf
)
229 int promisc
= flags
& PCAP_OPENFLAG_PROMISCUOUS
;
230 FIXME("(%s %i %i %i %p %p): partial stub\n", debugstr_a(source
), snaplen
, flags
, read_timeout
,
232 return pcap_open_live(source
, snaplen
, promisc
, read_timeout
, errbuf
);
235 pcap_t
* CDECL
wine_pcap_open_live(const char *source
, int snaplen
, int promisc
, int to_ms
,
238 TRACE("(%s %i %i %i %p)\n", debugstr_a(source
), snaplen
, promisc
, to_ms
, errbuf
);
239 return pcap_open_live(source
, snaplen
, promisc
, to_ms
, errbuf
);
242 int CDECL
wine_pcap_sendpacket(pcap_t
*p
, const unsigned char *buf
, int size
)
244 TRACE("(%p %p %i)\n", p
, buf
, size
);
245 return pcap_sendpacket(p
, buf
, size
);
248 int CDECL
wine_pcap_set_datalink(pcap_t
*p
, int dlt
)
250 TRACE("(%p %i)\n", p
, dlt
);
251 return pcap_set_datalink(p
, dlt
);
254 int CDECL
wine_pcap_setbuff(pcap_t
* p
, int dim
)
256 FIXME("(%p %i) stub\n", p
, dim
);
260 int CDECL
wine_pcap_setfilter(pcap_t
*p
, struct bpf_program
*fp
)
262 TRACE("(%p %p)\n", p
, fp
);
263 return pcap_setfilter(p
, fp
);
266 int CDECL
wine_pcap_setnonblock(pcap_t
*p
, int nonblock
, char *errbuf
)
268 TRACE("(%p %i %p)\n", p
, nonblock
, errbuf
);
269 return pcap_setnonblock(p
, nonblock
, errbuf
);
272 int CDECL
wine_pcap_snapshot(pcap_t
*p
)
275 return pcap_snapshot(p
);
278 int CDECL
wine_pcap_stats(pcap_t
*p
, struct pcap_stat
*ps
)
280 TRACE("(%p %p)\n", p
, ps
);
281 return pcap_stats(p
, ps
);
284 int CDECL
wine_wsockinit(void)
288 if (WSAStartup(MAKEWORD(1,1), &wsadata
)) return -1;