maintainers: Update the Direct3D section.
[wine.git] / dlls / wpcap / unixlib.c
bloba44627a7754b0752baf27d450f560f60b0f2e242
1 /*
2 * Copyright 2011, 2014 André Hentschel
3 * Copyright 2021 Hans Leidekker for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #if 0
21 #pragma makedep unix
22 #endif
24 #include "config.h"
26 #ifdef HAVE_PCAP_PCAP_H
27 #include <pcap/pcap.h>
29 #include <stdarg.h>
30 #include <stdlib.h>
31 #include <limits.h>
32 #include "ntstatus.h"
33 #define WIN32_NO_STATUS
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winternl.h"
38 #include "wine/unixlib.h"
39 #include "wine/debug.h"
40 #include "unixlib.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(wpcap);
43 WINE_DECLARE_DEBUG_CHANNEL(winediag);
45 static NTSTATUS wrap_activate( void *args )
47 struct pcap *pcap = args;
48 return pcap_activate( pcap->handle );
51 static NTSTATUS wrap_breakloop( void *args )
53 struct pcap *pcap = args;
54 pcap_breakloop( pcap->handle );
55 return STATUS_SUCCESS;
58 static NTSTATUS wrap_can_set_rfmon( void *args )
60 struct pcap *pcap = args;
61 return pcap_can_set_rfmon( pcap->handle );
64 static NTSTATUS wrap_close( void *args )
66 struct pcap *pcap = args;
67 pcap_close( pcap->handle );
68 free( pcap );
69 return STATUS_SUCCESS;
72 static NTSTATUS wrap_compile( void *args )
74 const struct compile_params *params = args;
75 return pcap_compile( params->pcap->handle, params->program, params->buf, params->optimize, params->mask );
78 static NTSTATUS wrap_create( void *args )
80 const struct create_params *params = args;
81 struct pcap *ret = malloc( sizeof(*ret) );
83 if (ret && !(ret->handle = pcap_create( params->src, params->errbuf )))
85 free( ret );
86 ret = NULL;
88 *params->ret = ret;
89 return STATUS_SUCCESS;
92 static NTSTATUS wrap_datalink( void *args )
94 struct pcap *pcap = args;
95 return pcap_datalink( pcap->handle );
98 static NTSTATUS wrap_datalink_name_to_val( void *args )
100 const struct datalink_name_to_val_params *params = args;
101 return pcap_datalink_name_to_val( params->name );
104 static NTSTATUS wrap_datalink_val_to_description( void *args )
106 const struct datalink_val_to_description_params *params = args;
107 *params->ret = pcap_datalink_val_to_description( params->link );
108 return STATUS_SUCCESS;
111 static NTSTATUS wrap_datalink_val_to_name( void *args )
113 const struct datalink_val_to_name_params *params = args;
114 *params->ret = pcap_datalink_val_to_name( params->link );
115 return STATUS_SUCCESS;
118 static NTSTATUS wrap_dump( void *args )
120 const struct dump_params *params = args;
121 struct pcap_pkthdr hdr_unix;
123 hdr_unix.ts.tv_sec = params->hdr->ts.tv_sec;
124 hdr_unix.ts.tv_usec = params->hdr->ts.tv_usec;
125 hdr_unix.caplen = params->hdr->caplen;
126 hdr_unix.len = params->hdr->len;
127 pcap_dump( params->user, &hdr_unix, params->packet );
128 return STATUS_SUCCESS;
131 static NTSTATUS wrap_dump_open( void *args )
133 const struct dump_open_params *params = args;
134 *params->ret = pcap_dump_open( params->pcap->handle, params->name );
135 return STATUS_SUCCESS;
138 static NTSTATUS wrap_findalldevs( void *args )
140 const struct findalldevs_params *params = args;
141 int ret;
142 ret = pcap_findalldevs( (pcap_if_t **)params->devs, params->errbuf );
143 if (params->devs && !*params->devs)
144 ERR_(winediag)( "Failed to access raw network (pcap), this requires special permissions.\n" );
145 return ret;
148 static NTSTATUS wrap_free_datalinks( void *args )
150 int *links = args;
151 pcap_free_datalinks( links );
152 return STATUS_SUCCESS;
155 static NTSTATUS wrap_free_tstamp_types( void *args )
157 int *types = args;
158 pcap_free_tstamp_types( types );
159 return STATUS_SUCCESS;
162 static NTSTATUS wrap_freealldevs( void *args )
164 struct pcap_interface *devs = args;
165 pcap_freealldevs( (pcap_if_t *)devs );
166 return STATUS_SUCCESS;
169 static NTSTATUS wrap_freecode( void *args )
171 void *program = args;
172 pcap_freecode( program );
173 return STATUS_SUCCESS;
176 static NTSTATUS wrap_get_tstamp_precision( void *args )
178 struct pcap *pcap = args;
179 return pcap_get_tstamp_precision( pcap->handle );
182 static NTSTATUS wrap_geterr( void *args )
184 const struct geterr_params *params = args;
185 *params->ret = pcap_geterr( params->pcap->handle );
186 return STATUS_SUCCESS;
189 static NTSTATUS wrap_getnonblock( void *args )
191 const struct getnonblock_params *params = args;
192 return pcap_getnonblock( params->pcap->handle, params->errbuf );
195 static NTSTATUS wrap_lib_version( void *args )
197 const struct lib_version_params *params = args;
198 const char *str = pcap_lib_version();
199 unsigned int len = min( strlen(str) + 1, params->size );
200 memcpy( params->version, str, len );
201 params->version[len - 1] = 0;
202 return STATUS_SUCCESS;
205 static NTSTATUS wrap_list_datalinks( void *args )
207 const struct list_datalinks_params *params = args;
208 return pcap_list_datalinks( params->pcap->handle, params->buf );
211 static NTSTATUS wrap_list_tstamp_types( void *args )
213 const struct list_tstamp_types_params *params = args;
214 return pcap_list_tstamp_types( params->pcap->handle, params->types );
217 static NTSTATUS wrap_lookupnet( void *args )
219 const struct lookupnet_params *params = args;
220 return pcap_lookupnet( params->device, params->net, params->mask, params->errbuf );
223 static NTSTATUS wrap_major_version( void *args )
225 struct pcap *pcap = args;
226 return pcap_major_version( pcap->handle );
229 static NTSTATUS wrap_minor_version( void *args )
231 struct pcap *pcap = args;
232 return pcap_minor_version( pcap->handle );
235 static NTSTATUS wrap_next_ex( void *args )
237 const struct next_ex_params *params = args;
238 struct pcap *pcap = params->pcap;
239 struct pcap_pkthdr *hdr_unix;
240 int ret;
242 if ((ret = pcap_next_ex( pcap->handle, &hdr_unix, params->data )) == 1)
244 if (hdr_unix->ts.tv_sec > INT_MAX || hdr_unix->ts.tv_usec > INT_MAX) WARN( "truncating timeval values(s)\n" );
245 pcap->hdr.ts.tv_sec = hdr_unix->ts.tv_sec;
246 pcap->hdr.ts.tv_usec = hdr_unix->ts.tv_usec;
247 pcap->hdr.caplen = hdr_unix->caplen;
248 pcap->hdr.len = hdr_unix->len;
249 *params->hdr = &pcap->hdr;
251 return ret;
254 static NTSTATUS wrap_open_live( void *args )
256 const struct open_live_params *params = args;
257 struct pcap *ret = malloc( sizeof(*ret) );
258 if (ret && !(ret->handle = pcap_open_live( params->source, params->snaplen, params->promisc,
259 params->to_ms, params->errbuf )))
261 free( ret );
262 ret = NULL;
264 *params->ret = ret;
265 return STATUS_SUCCESS;
268 static NTSTATUS wrap_sendpacket( void *args )
270 const struct sendpacket_params *params = args;
271 return pcap_sendpacket( params->pcap->handle, params->buf, params->size );
274 static NTSTATUS wrap_set_buffer_size( void *args )
276 const struct set_buffer_size_params *params = args;
277 return pcap_set_buffer_size( params->pcap->handle, params->size );
280 static NTSTATUS wrap_set_datalink( void *args )
282 const struct set_datalink_params *params = args;
283 return pcap_set_datalink( params->pcap->handle, params->link );
286 static NTSTATUS wrap_set_promisc( void *args )
288 const struct set_promisc_params *params = args;
289 return pcap_set_promisc( params->pcap->handle, params->enable );
292 static NTSTATUS wrap_set_rfmon( void *args )
294 const struct set_rfmon_params *params = args;
295 return pcap_set_rfmon( params->pcap->handle, params->enable );
298 static NTSTATUS wrap_set_snaplen( void *args )
300 const struct set_snaplen_params *params = args;
301 return pcap_set_snaplen( params->pcap->handle, params->len );
304 static NTSTATUS wrap_set_timeout( void *args )
306 const struct set_timeout_params *params = args;
307 return pcap_set_timeout( params->pcap->handle, params->timeout );
310 static NTSTATUS wrap_set_tstamp_precision( void *args )
312 const struct set_tstamp_precision_params *params = args;
313 return pcap_set_tstamp_precision( params->pcap->handle, params->precision );
316 static NTSTATUS wrap_set_tstamp_type( void *args )
318 const struct set_tstamp_type_params *params = args;
319 return pcap_set_tstamp_type( params->pcap->handle, params->type );
322 static NTSTATUS wrap_setfilter( void *args )
324 const struct setfilter_params *params = args;
325 return pcap_setfilter( params->pcap->handle, params->program );
328 static NTSTATUS wrap_setnonblock( void *args )
330 const struct setnonblock_params *params = args;
331 return pcap_setnonblock( params->pcap->handle, params->nonblock, params->errbuf );
334 static NTSTATUS wrap_snapshot( void *args )
336 struct pcap *pcap = args;
337 return pcap_snapshot( pcap->handle );
340 static NTSTATUS wrap_stats( void *args )
342 const struct stats_params *params = args;
343 return pcap_stats( params->pcap->handle, params->stats );
346 static NTSTATUS wrap_statustostr( void *args )
348 const struct statustostr_params *params = args;
349 *params->ret = pcap_statustostr( params->status );
350 return STATUS_SUCCESS;
353 static NTSTATUS wrap_tstamp_type_name_to_val( void *args )
355 const struct tstamp_type_name_to_val_params *params = args;
356 return pcap_tstamp_type_name_to_val( params->name );
359 static NTSTATUS wrap_tstamp_type_val_to_description( void *args )
361 const struct tstamp_type_val_to_description_params *params = args;
362 *params->ret = pcap_tstamp_type_val_to_description( params->val );
363 return STATUS_SUCCESS;
366 static NTSTATUS wrap_tstamp_type_val_to_name( void *args )
368 const struct tstamp_type_val_to_name_params *params = args;
369 *params->ret = pcap_tstamp_type_val_to_name( params->val );
370 return STATUS_SUCCESS;
373 const unixlib_entry_t __wine_unix_call_funcs[] =
375 wrap_activate,
376 wrap_breakloop,
377 wrap_can_set_rfmon,
378 wrap_close,
379 wrap_compile,
380 wrap_create,
381 wrap_datalink,
382 wrap_datalink_name_to_val,
383 wrap_datalink_val_to_description,
384 wrap_datalink_val_to_name,
385 /* wrap_dispatch, */
386 wrap_dump,
387 wrap_dump_open,
388 wrap_findalldevs,
389 wrap_free_datalinks,
390 wrap_free_tstamp_types,
391 wrap_freealldevs,
392 wrap_freecode,
393 wrap_get_tstamp_precision,
394 wrap_geterr,
395 wrap_getnonblock,
396 wrap_lib_version,
397 wrap_list_datalinks,
398 wrap_list_tstamp_types,
399 wrap_lookupnet,
400 /* wrap_loop, */
401 wrap_major_version,
402 wrap_minor_version,
403 wrap_next_ex,
404 wrap_open_live,
405 wrap_sendpacket,
406 wrap_set_buffer_size,
407 wrap_set_datalink,
408 wrap_set_promisc,
409 wrap_set_rfmon,
410 wrap_set_snaplen,
411 wrap_set_timeout,
412 wrap_set_tstamp_precision,
413 wrap_set_tstamp_type,
414 wrap_setfilter,
415 wrap_setnonblock,
416 wrap_snapshot,
417 wrap_stats,
418 wrap_statustostr,
419 wrap_tstamp_type_name_to_val,
420 wrap_tstamp_type_val_to_description,
421 wrap_tstamp_type_val_to_name,
424 #endif /* HAVE_PCAP_PCAP_H */