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 #ifndef PCAP_SRC_FILE_STRING
31 #define PCAP_SRC_FILE_STRING "file://"
34 #define PCAP_SRC_FILE 2
36 #ifndef PCAP_SRC_IF_STRING
37 #define PCAP_SRC_IF_STRING "rpcap://"
39 #ifndef PCAP_SRC_IFLOCAL
40 #define PCAP_SRC_IFLOCAL 3
43 void CDECL
wine_pcap_breakloop(pcap_t
*p
)
46 return pcap_breakloop(p
);
49 void CDECL
wine_pcap_close(pcap_t
*p
)
55 int CDECL
wine_pcap_compile(pcap_t
*p
, struct bpf_program
*program
, const char *buf
, int optimize
,
58 TRACE("(%p %p %s %i %u)\n", p
, program
, debugstr_a(buf
), optimize
, mask
);
59 return pcap_compile(p
, program
, buf
, optimize
, mask
);
62 int CDECL
wine_pcap_datalink(pcap_t
*p
)
65 return pcap_datalink(p
);
68 int CDECL
wine_pcap_datalink_name_to_val(const char *name
)
70 TRACE("(%s)\n", debugstr_a(name
));
71 return pcap_datalink_name_to_val(name
);
74 const char* CDECL
wine_pcap_datalink_val_to_description(int dlt
)
77 return pcap_datalink_val_to_description(dlt
);
80 const char* CDECL
wine_pcap_datalink_val_to_name(int dlt
)
83 return pcap_datalink_val_to_name(dlt
);
88 void (CALLBACK
*pfn_cb
)(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
90 } PCAP_HANDLER_CALLBACK
;
92 static void pcap_handler_callback(u_char
*user_data
, const struct pcap_pkthdr
*h
, const u_char
*p
)
94 PCAP_HANDLER_CALLBACK
*pcb
;
95 TRACE("(%p %p %p)\n", user_data
, h
, p
);
96 pcb
= (PCAP_HANDLER_CALLBACK
*)user_data
;
97 pcb
->pfn_cb(pcb
->user_data
, h
, p
);
98 TRACE("Callback COMPLETED\n");
101 int CDECL
wine_pcap_dispatch(pcap_t
*p
, int cnt
,
102 void (CALLBACK
*callback
)(u_char
*, const struct pcap_pkthdr
*, const u_char
*),
105 TRACE("(%p %i %p %p)\n", p
, cnt
, callback
, user
);
109 PCAP_HANDLER_CALLBACK pcb
;
110 pcb
.pfn_cb
= callback
;
111 pcb
.user_data
= user
;
112 return pcap_dispatch(p
, cnt
, pcap_handler_callback
, (unsigned char *)&pcb
);
115 return pcap_dispatch(p
, cnt
, NULL
, user
);
118 int CDECL
wine_pcap_findalldevs(pcap_if_t
**alldevsp
, char *errbuf
)
122 TRACE("(%p %p)\n", alldevsp
, errbuf
);
123 ret
= pcap_findalldevs(alldevsp
, errbuf
);
124 if(alldevsp
&& !*alldevsp
)
125 ERR_(winediag
)("Failed to access raw network (pcap), this requires special permissions.\n");
130 int CDECL
wine_pcap_findalldevs_ex(char *source
, void *auth
, pcap_if_t
**alldevs
, char *errbuf
)
132 FIXME("(%s %p %p %p): partial stub\n", debugstr_a(source
), auth
, alldevs
, errbuf
);
133 return wine_pcap_findalldevs(alldevs
, errbuf
);
136 void CDECL
wine_pcap_freealldevs(pcap_if_t
*alldevs
)
138 TRACE("(%p)\n", alldevs
);
139 pcap_freealldevs(alldevs
);
142 void CDECL
wine_pcap_freecode(struct bpf_program
*fp
)
145 return pcap_freecode(fp
);
148 typedef struct _AirpcapHandle
*PAirpcapHandle
;
149 PAirpcapHandle CDECL
wine_pcap_get_airpcap_handle(pcap_t
*p
)
155 char* CDECL
wine_pcap_geterr(pcap_t
*p
)
158 return pcap_geterr(p
);
161 int CDECL
wine_pcap_getnonblock(pcap_t
*p
, char *errbuf
)
163 TRACE("(%p %p)\n", p
, errbuf
);
164 return pcap_getnonblock(p
, errbuf
);
167 const char* CDECL
wine_pcap_lib_version(void)
169 const char* ret
= pcap_lib_version();
170 TRACE("%s\n", debugstr_a(ret
));
174 int CDECL
wine_pcap_list_datalinks(pcap_t
*p
, int **dlt_buffer
)
176 TRACE("(%p %p)\n", p
, dlt_buffer
);
177 return pcap_list_datalinks(p
, dlt_buffer
);
180 char* CDECL
wine_pcap_lookupdev(char *errbuf
)
182 TRACE("(%p)\n", errbuf
);
183 return pcap_lookupdev(errbuf
);
186 int CDECL
wine_pcap_lookupnet(const char *device
, unsigned int *netp
, unsigned int *maskp
,
189 TRACE("(%s %p %p %p)\n", debugstr_a(device
), netp
, maskp
, errbuf
);
190 return pcap_lookupnet(device
, netp
, maskp
, errbuf
);
193 int CDECL
wine_pcap_loop(pcap_t
*p
, int cnt
,
194 void (CALLBACK
*callback
)(u_char
*, const struct pcap_pkthdr
*, const u_char
*),
197 TRACE("(%p %i %p %p)\n", p
, cnt
, callback
, user
);
201 PCAP_HANDLER_CALLBACK pcb
;
202 pcb
.pfn_cb
= callback
;
203 pcb
.user_data
= user
;
204 return pcap_loop(p
, cnt
, pcap_handler_callback
, (unsigned char *)&pcb
);
207 return pcap_loop(p
, cnt
, NULL
, user
);
210 int CDECL
wine_pcap_major_version(pcap_t
*p
)
213 return pcap_major_version(p
);
216 int CDECL
wine_pcap_minor_version(pcap_t
*p
)
219 return pcap_minor_version(p
);
222 const unsigned char* CDECL
wine_pcap_next(pcap_t
*p
, struct pcap_pkthdr
*h
)
224 TRACE("(%p %p)\n", p
, h
);
225 return pcap_next(p
, h
);
228 int CDECL
wine_pcap_next_ex(pcap_t
*p
, struct pcap_pkthdr
**pkt_header
, const unsigned char **pkt_data
)
230 TRACE("(%p %p %p)\n", p
, pkt_header
, pkt_data
);
231 return pcap_next_ex(p
, pkt_header
, pkt_data
);
234 #define PCAP_OPENFLAG_PROMISCUOUS 1
236 pcap_t
* CDECL
wine_pcap_open(const char *source
, int snaplen
, int flags
, int read_timeout
,
237 void *auth
, char *errbuf
)
239 int promisc
= flags
& PCAP_OPENFLAG_PROMISCUOUS
;
240 FIXME("(%s %i %i %i %p %p): partial stub\n", debugstr_a(source
), snaplen
, flags
, read_timeout
,
242 return pcap_open_live(source
, snaplen
, promisc
, read_timeout
, errbuf
);
245 pcap_t
* CDECL
wine_pcap_open_live(const char *source
, int snaplen
, int promisc
, int to_ms
,
248 TRACE("(%s %i %i %i %p)\n", debugstr_a(source
), snaplen
, promisc
, to_ms
, errbuf
);
249 return pcap_open_live(source
, snaplen
, promisc
, to_ms
, errbuf
);
252 int CDECL
wine_pcap_parsesrcstr(const char *source
, int *type
, char *host
, char *port
, char *name
, char *errbuf
)
254 int t
= PCAP_SRC_IFLOCAL
;
255 const char *p
= source
;
257 FIXME("(%s %p %p %p %p %p): partial stub\n", debugstr_a(source
), type
, host
, port
, name
, errbuf
);
266 if (!strncmp(p
, PCAP_SRC_IF_STRING
, strlen(PCAP_SRC_IF_STRING
)))
267 p
+= strlen(PCAP_SRC_IF_STRING
);
268 else if (!strncmp(p
, PCAP_SRC_FILE_STRING
, strlen(PCAP_SRC_FILE_STRING
)))
270 p
+= strlen(PCAP_SRC_FILE_STRING
);
280 sprintf(errbuf
, "The name has not been specified in the source string.");
290 int CDECL
wine_pcap_sendpacket(pcap_t
*p
, const unsigned char *buf
, int size
)
292 TRACE("(%p %p %i)\n", p
, buf
, size
);
293 return pcap_sendpacket(p
, buf
, size
);
296 int CDECL
wine_pcap_set_datalink(pcap_t
*p
, int dlt
)
298 TRACE("(%p %i)\n", p
, dlt
);
299 return pcap_set_datalink(p
, dlt
);
302 int CDECL
wine_pcap_setbuff(pcap_t
* p
, int dim
)
304 FIXME("(%p %i) stub\n", p
, dim
);
308 int CDECL
wine_pcap_setfilter(pcap_t
*p
, struct bpf_program
*fp
)
310 TRACE("(%p %p)\n", p
, fp
);
311 return pcap_setfilter(p
, fp
);
314 int CDECL
wine_pcap_setnonblock(pcap_t
*p
, int nonblock
, char *errbuf
)
316 TRACE("(%p %i %p)\n", p
, nonblock
, errbuf
);
317 return pcap_setnonblock(p
, nonblock
, errbuf
);
320 int CDECL
wine_pcap_snapshot(pcap_t
*p
)
323 return pcap_snapshot(p
);
326 int CDECL
wine_pcap_stats(pcap_t
*p
, struct pcap_stat
*ps
)
328 TRACE("(%p %p)\n", p
, ps
);
329 return pcap_stats(p
, ps
);
332 int CDECL
wine_wsockinit(void)
336 if (WSAStartup(MAKEWORD(1,1), &wsadata
)) return -1;