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>
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
)
32 return pcap_breakloop(p
);
35 void CDECL
wine_pcap_close(pcap_t
*p
)
41 int CDECL
wine_pcap_compile(pcap_t
*p
, struct bpf_program
*program
, const char *buf
, int optimize
,
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
)
51 return pcap_datalink(p
);
54 const char* CDECL
wine_pcap_datalink_val_to_name(int dlt
)
57 return pcap_datalink_val_to_name(dlt
);
62 void (CALLBACK
*pfn_cb
)(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
64 } PCAP_HANDLER_CALLBACK
;
66 static void pcap_handler_callback(u_char
*user_data
, const struct pcap_pkthdr
*h
, const u_char
*p
)
68 PCAP_HANDLER_CALLBACK
*pcb
;
69 TRACE("(%p %p %p)\n", user_data
, h
, p
);
70 pcb
= (PCAP_HANDLER_CALLBACK
*)user_data
;
71 pcb
->pfn_cb(pcb
->user_data
, h
, p
);
72 HeapFree(GetProcessHeap(), 0, pcb
);
73 TRACE("Callback COMPLETED\n");
76 int CDECL
wine_pcap_dispatch(pcap_t
*p
, int cnt
,
77 void (CALLBACK
*callback
)(u_char
*, const struct pcap_pkthdr
*, const u_char
*),
80 TRACE("(%p %i %p %p)\n", p
, cnt
, callback
, user
);
84 PCAP_HANDLER_CALLBACK
*pcb
;
85 pcb
= HeapAlloc(GetProcessHeap(), 0, sizeof(PCAP_HANDLER_CALLBACK
));
86 pcb
->pfn_cb
= callback
;
87 pcb
->user_data
= user
;
88 return pcap_dispatch(p
, cnt
, pcap_handler_callback
, (unsigned char*)pcb
);
91 return pcap_dispatch(p
, cnt
, NULL
, user
);
94 int CDECL
wine_pcap_findalldevs(pcap_if_t
**alldevsp
, char *errbuf
)
98 TRACE("(%p %p)\n", alldevsp
, errbuf
);
99 ret
= pcap_findalldevs(alldevsp
, errbuf
);
100 if(alldevsp
&& !*alldevsp
)
101 ERR_(winediag
)("Failed to access raw network (pcap), this requires special permissions.\n");
106 void CDECL
wine_pcap_freealldevs(pcap_if_t
*alldevs
)
108 TRACE("(%p)\n", alldevs
);
109 pcap_freealldevs(alldevs
);
112 void CDECL
wine_pcap_freecode(struct bpf_program
*fp
)
115 return pcap_freecode(fp
);
118 char* CDECL
wine_pcap_geterr(pcap_t
*p
)
121 return pcap_geterr(p
);
124 const char* CDECL
wine_pcap_lib_version(void)
126 const char* ret
= pcap_lib_version();
127 TRACE("%s\n", debugstr_a(ret
));
131 char* CDECL
wine_pcap_lookupdev(char *errbuf
)
133 TRACE("(%p)\n", errbuf
);
134 return pcap_lookupdev(errbuf
);
137 int CDECL
wine_pcap_lookupnet(const char *device
, unsigned int *netp
, unsigned int *maskp
,
140 TRACE("(%s %p %p %p)\n", debugstr_a(device
), netp
, maskp
, errbuf
);
141 return pcap_lookupnet(device
, netp
, maskp
, errbuf
);
144 int CDECL
wine_pcap_loop(pcap_t
*p
, int cnt
,
145 void (CALLBACK
*callback
)(u_char
*, const struct pcap_pkthdr
*, const u_char
*),
148 TRACE("(%p %i %p %p)\n", p
, cnt
, callback
, user
);
152 PCAP_HANDLER_CALLBACK
*pcb
;
153 pcb
= HeapAlloc(GetProcessHeap(), 0, sizeof(PCAP_HANDLER_CALLBACK
));
154 pcb
->pfn_cb
= callback
;
155 pcb
->user_data
= user
;
156 return pcap_loop(p
, cnt
, pcap_handler_callback
, (unsigned char*)pcb
);
159 return pcap_loop(p
, cnt
, NULL
, user
);
162 int CDECL
wine_pcap_major_version(pcap_t
*p
)
165 return pcap_major_version(p
);
168 int CDECL
wine_pcap_minor_version(pcap_t
*p
)
171 return pcap_minor_version(p
);
174 pcap_t
* CDECL
wine_pcap_open_live(const char *source
, int snaplen
, int promisc
, int to_ms
,
177 TRACE("(%s %i %i %i %p)\n", debugstr_a(source
), snaplen
, promisc
, to_ms
, errbuf
);
178 return pcap_open_live(source
, snaplen
, promisc
, to_ms
, errbuf
);
181 int CDECL
wine_pcap_setbuff(pcap_t
* p
, int dim
)
183 FIXME("(%p %i) stub\n", p
, dim
);
187 int CDECL
wine_pcap_setfilter(pcap_t
*p
, struct bpf_program
*fp
)
189 TRACE("(%p %p)\n", p
, fp
);
190 return pcap_setfilter(p
, fp
);
193 int CDECL
wine_pcap_snapshot(pcap_t
*p
)
196 return pcap_snapshot(p
);
199 int CDECL
wine_pcap_stats(pcap_t
*p
, struct pcap_stat
*ps
)
201 TRACE("(%p %p)\n", p
, ps
);
202 return pcap_stats(p
, ps
);