xmllite/writer: Implement WriteNodeShallow().
[wine.git] / dlls / wpcap / wpcap.c
blobdf35954bfa70c268ce5dce74cc036c41fc7afd52
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 <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winternl.h"
25 #include "winnls.h"
26 #include "winsock2.h"
27 #include "ws2ipdef.h"
28 #include "iphlpapi.h"
30 #include "wine/unixlib.h"
31 #include "wine/debug.h"
32 #include "unixlib.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(wpcap);
36 static unixlib_handle_t pcap_handle;
38 #define PCAP_CALL( func, params ) __wine_unix_call( pcap_handle, unix_ ## func, params )
40 int CDECL pcap_activate( struct pcap *pcap )
42 TRACE( "%p\n", pcap );
43 return PCAP_CALL( activate, pcap );
46 void CDECL pcap_breakloop( struct pcap *pcap )
48 TRACE( "%p\n", pcap );
49 PCAP_CALL( breakloop, pcap );
52 int CDECL pcap_can_set_rfmon( struct pcap *pcap )
54 TRACE( "%p\n", pcap );
55 return PCAP_CALL( can_set_rfmon, pcap );
58 void CDECL pcap_close( struct pcap *pcap )
60 TRACE( "%p\n", pcap );
61 PCAP_CALL( close, pcap );
64 int CDECL pcap_compile( struct pcap *pcap, void *program, const char *buf, int optimize, unsigned int mask )
66 struct compile_params params = { pcap, program, buf, optimize, mask };
67 TRACE( "%p, %p, %s, %d, %u\n", pcap, program, debugstr_a(buf), optimize, mask );
68 return PCAP_CALL( compile, &params );
71 int CDECL pcap_datalink( struct pcap *pcap )
73 TRACE( "%p\n", pcap );
74 return PCAP_CALL( datalink, pcap );
77 int CDECL pcap_datalink_name_to_val( const char *name )
79 struct datalink_name_to_val_params params = { name };
80 TRACE( "%s\n", debugstr_a(name) );
81 return PCAP_CALL( datalink_name_to_val, &params );
84 const char * CDECL pcap_datalink_val_to_description( int link )
86 const char *ret;
87 struct datalink_val_to_description_params params = { link, &ret };
88 TRACE( "%d\n", link );
89 PCAP_CALL( datalink_val_to_description, &params );
90 return ret;
93 const char * CDECL pcap_datalink_val_to_name( int link )
95 const char *ret;
96 struct datalink_val_to_name_params params = { link, &ret };
97 TRACE( "%d\n", link );
98 PCAP_CALL( datalink_val_to_name, &params );
99 return ret;
102 void CDECL pcap_dump( unsigned char *user, const struct pcap_pkthdr_win32 *hdr, const unsigned char *packet )
104 struct dump_params params = { user, hdr, packet };
105 TRACE( "%p, %p, %p\n", user, hdr, packet );
106 PCAP_CALL( dump, &params );
109 static inline WCHAR *strdupAW( const char *str )
111 WCHAR *ret = NULL;
112 if (str)
114 int len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
115 if ((ret = malloc( len * sizeof(WCHAR) ))) MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
117 return ret;
120 void * CDECL pcap_dump_open( struct pcap *pcap, const char *filename )
122 void *dumper;
123 WCHAR *filenameW;
124 char *unix_path;
125 struct dump_open_params params;
127 TRACE( "%p, %s\n", pcap, debugstr_a(filename) );
129 if (!(filenameW = strdupAW( filename ))) return NULL;
130 unix_path = wine_get_unix_file_name( filenameW );
131 free( filenameW );
132 if (!unix_path) return NULL;
134 TRACE( "unix_path %s\n", debugstr_a(unix_path) );
136 params.pcap = pcap;
137 params.name = unix_path;
138 params.ret = &dumper;
139 PCAP_CALL( dump_open, &params );
140 RtlFreeHeap( GetProcessHeap(), 0, unix_path );
141 return dumper;
144 static void free_addresses( struct pcap_address *addrs )
146 struct pcap_address *next, *cur = addrs;
147 if (!addrs) return;
150 free( cur->addr );
151 free( cur->netmask );
152 free( cur->broadaddr );
153 free( cur->dstaddr );
154 next = cur->next;
155 free( cur );
156 cur = next;
157 } while (next);
160 static void free_devices( struct pcap_interface *devs )
162 struct pcap_interface *next, *cur = devs;
163 if (!devs) return;
166 free( cur->name );
167 free( cur->description );
168 free_addresses( cur->addresses );
169 next = cur->next;
170 free( cur );
171 cur = next;
172 } while (next);
175 static IP_ADAPTER_ADDRESSES *get_adapters( void )
177 DWORD size = 0;
178 IP_ADAPTER_ADDRESSES *ret;
179 ULONG flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER;
181 if (GetAdaptersAddresses( AF_UNSPEC, flags, NULL, NULL, &size ) != ERROR_BUFFER_OVERFLOW) return NULL;
182 if (!(ret = malloc( size ))) return NULL;
183 if (GetAdaptersAddresses( AF_UNSPEC, flags, NULL, ret, &size ))
185 free( ret );
186 return NULL;
188 return ret;
191 static IP_ADAPTER_ADDRESSES *find_adapter( IP_ADAPTER_ADDRESSES *list, const char *name )
193 IP_ADAPTER_ADDRESSES *ret;
194 WCHAR *nameW;
196 if (!(nameW = strdupAW( name ))) return NULL;
197 for (ret = list; ret; ret = ret->Next)
199 if (!wcscmp( nameW, ret->FriendlyName )) break;
201 free( nameW);
202 return ret;
205 static char *build_win32_name( const char *source, const char *adapter_name )
207 const char prefix[] = "\\Device\\NPF_";
208 int len = sizeof(prefix) + strlen(adapter_name);
209 char *ret;
211 if (source) len += strlen( source );
212 if ((ret = malloc( len )))
214 ret[0] = 0;
215 if (source) strcat( ret, source );
216 strcat( ret, prefix );
217 strcat( ret, adapter_name );
219 return ret;
222 static char *build_win32_description( const struct pcap_interface *unix_dev )
224 int len = strlen(unix_dev->name) + 1;
225 char *ret;
227 if (unix_dev->description && unix_dev->description[0]) len += strlen(unix_dev->description) + 1;
228 if ((ret = malloc( len )))
230 if (unix_dev->description)
232 strcpy( ret, unix_dev->description );
233 strcat( ret, " " );
234 strcat( ret, unix_dev->name );
236 else strcpy( ret, unix_dev->name );
238 return ret;
241 static struct sockaddr_hdr *dup_sockaddr( const struct sockaddr_hdr *addr )
243 struct sockaddr_hdr *ret;
245 switch (addr->sa_family)
247 case AF_INET:
249 struct sockaddr_in *dst, *src = (struct sockaddr_in *)addr;
250 if (!(dst = calloc( 1, sizeof(*dst) ))) return NULL;
251 dst->sin_family = src->sin_family;
252 dst->sin_port = src->sin_port;
253 dst->sin_addr = src->sin_addr;
254 ret = (struct sockaddr_hdr *)dst;
255 break;
257 case AF_INET6:
259 struct sockaddr_in6 *dst, *src = (struct sockaddr_in6 *)addr;
260 if (!(dst = malloc( sizeof(*dst) ))) return NULL;
261 dst->sin6_family = src->sin6_family;
262 dst->sin6_port = src->sin6_port;
263 dst->sin6_flowinfo = src->sin6_flowinfo;
264 dst->sin6_addr = src->sin6_addr;
265 dst->sin6_scope_id = src->sin6_scope_id;
266 ret = (struct sockaddr_hdr *)dst;
267 break;
269 default:
270 FIXME( "address family %u not supported\n", addr->sa_family );
271 return NULL;
274 return ret;
277 static struct pcap_address *build_win32_address( struct pcap_address *src )
279 struct pcap_address *dst;
281 if (!(dst = calloc( 1, sizeof(*dst) ))) return NULL;
282 if (src->addr && !(dst->addr = dup_sockaddr( src->addr ))) goto err;
283 if (src->netmask && !(dst->netmask = dup_sockaddr( src->netmask ))) goto err;
284 if (src->broadaddr && !(dst->broadaddr = dup_sockaddr( src->broadaddr ))) goto err;
285 if (src->dstaddr && !(dst->dstaddr = dup_sockaddr( src->dstaddr ))) goto err;
286 return dst;
288 err:
289 free( dst->addr );
290 free( dst->netmask );
291 free( dst->broadaddr );
292 free( dst->dstaddr );
293 free( dst );
294 return NULL;
297 static void add_win32_address( struct pcap_address **list, struct pcap_address *addr )
299 struct pcap_address *cur = *list;
300 if (!cur) *list = addr;
301 else
303 while (cur->next) { cur = cur->next; }
304 cur->next = addr;
308 static struct pcap_address *build_win32_addresses( struct pcap_address *addrs )
310 struct pcap_address *src, *dst, *ret = NULL;
311 src = addrs;
312 while (src)
314 if ((dst = build_win32_address( src ))) add_win32_address( &ret, dst );
315 src = src->next;
317 return ret;
320 static struct pcap_interface *build_win32_device( const struct pcap_interface *unix_dev, const char *source,
321 const char *adapter_name )
323 struct pcap_interface *ret;
325 if (!(ret = calloc( 1, sizeof(*ret) ))) return NULL;
326 if (!(ret->name = build_win32_name( source, adapter_name ))) goto err;
327 if (!(ret->description = build_win32_description( unix_dev ))) goto err;
328 ret->addresses = build_win32_addresses( unix_dev->addresses );
329 ret->flags = unix_dev->flags;
330 return ret;
332 err:
333 free( ret->name );
334 free( ret->description );
335 free_addresses( ret->addresses );
336 free( ret );
337 return NULL;
340 static void add_win32_device( struct pcap_interface **list, struct pcap_interface *dev )
342 struct pcap_interface *cur = *list;
343 if (!cur) *list = dev;
344 else
346 while (cur->next) { cur = cur->next; }
347 cur->next = dev;
351 static int find_all_devices( const char *source, struct pcap_interface **devs, char *errbuf )
353 struct pcap_interface *unix_devs, *win32_devs = NULL, *cur, *dev;
354 IP_ADAPTER_ADDRESSES *ptr, *adapters = get_adapters();
355 struct findalldevs_params params = { &unix_devs, errbuf };
356 int ret;
358 if (!adapters)
360 if (errbuf) sprintf( errbuf, "Out of memory." );
361 return -1;
364 if (!(ret = PCAP_CALL( findalldevs, &params )))
366 cur = unix_devs;
367 while (cur)
369 if ((ptr = find_adapter( adapters, cur->name )) && (dev = build_win32_device( cur, source, ptr->AdapterName )))
371 add_win32_device( &win32_devs, dev );
373 cur = cur->next;
375 *devs = win32_devs;
376 PCAP_CALL( freealldevs, unix_devs );
379 free( adapters );
380 return ret;
383 int CDECL pcap_findalldevs( struct pcap_interface **devs, char *errbuf )
385 TRACE( "%p, %p\n", devs, errbuf );
386 return find_all_devices( NULL, devs, errbuf );
389 int CDECL pcap_findalldevs_ex( char *source, void *auth, struct pcap_interface **devs, char *errbuf )
391 FIXME( "%s, %p, %p, %p: partial stub\n", debugstr_a(source), auth, devs, errbuf );
392 return find_all_devices( source, devs, errbuf );
395 void CDECL pcap_free_datalinks( int *links )
397 TRACE( "%p\n", links );
398 PCAP_CALL( free_datalinks, links );
401 void CDECL pcap_free_tstamp_types( int *types )
403 TRACE( "%p\n", types );
404 PCAP_CALL( free_tstamp_types, types );
407 void CDECL pcap_freealldevs( struct pcap_interface *devs )
409 TRACE( "%p\n", devs );
410 free_devices( devs );
413 void CDECL pcap_freecode( void *program )
415 TRACE( "%p\n", program );
416 PCAP_CALL( freecode, program );
419 void * CDECL pcap_get_airpcap_handle( struct pcap *pcap )
421 TRACE( "%p\n", pcap );
422 return NULL;
425 int CDECL pcap_get_tstamp_precision( struct pcap *pcap )
427 TRACE( "%p\n", pcap );
428 return PCAP_CALL( get_tstamp_precision, pcap );
431 char * CDECL pcap_geterr( struct pcap *pcap )
433 char *ret;
434 struct geterr_params params = { pcap, &ret };
435 TRACE( "%p\n", pcap );
436 PCAP_CALL( geterr, &params );
437 return ret;
440 int CDECL pcap_getnonblock( struct pcap *pcap, char *errbuf )
442 struct getnonblock_params params = { pcap, errbuf };
443 TRACE( "%p, %p\n", pcap, errbuf );
444 return PCAP_CALL( getnonblock, &params );
447 static char lib_version[256];
448 static BOOL WINAPI init_lib_version( INIT_ONCE *once, void *param, void **ctx )
450 struct lib_version_params params = { lib_version, sizeof(lib_version) };
451 PCAP_CALL( lib_version, &params );
452 return TRUE;
455 const char * CDECL pcap_lib_version( void )
457 static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
458 if (!lib_version[0]) InitOnceExecuteOnce( &once, init_lib_version, NULL, NULL );
459 TRACE( "%s\n", debugstr_a(lib_version) );
460 return lib_version;
463 int CDECL pcap_list_datalinks( struct pcap *pcap, int **buf )
465 struct list_datalinks_params params = { pcap, buf };
466 TRACE( "%p, %p\n", pcap, buf );
467 return PCAP_CALL( list_datalinks, &params );
470 int CDECL pcap_list_tstamp_types( struct pcap *pcap, int **types )
472 struct list_tstamp_types_params params = { pcap, types };
473 TRACE( "%p, %p\n", pcap, types );
474 return PCAP_CALL( list_tstamp_types, &params );
477 char * CDECL pcap_lookupdev( char *errbuf )
479 static char *ret;
480 struct pcap_interface *devs;
482 TRACE( "%p\n", errbuf );
483 if (!ret)
485 if (pcap_findalldevs( &devs, errbuf ) == -1 || !devs) return NULL;
486 if ((ret = malloc( strlen(devs->name) + 1 ))) strcpy( ret, devs->name );
487 pcap_freealldevs( devs );
489 return ret;
492 int CDECL pcap_lookupnet( const char *device, unsigned int *net, unsigned int *mask, char *errbuf )
494 struct lookupnet_params params = { device, net, mask, errbuf };
495 TRACE( "%s, %p, %p, %p\n", debugstr_a(device), net, mask, errbuf );
496 return PCAP_CALL( lookupnet, &params );
499 int CDECL pcap_loop( struct pcap *pcap, int count,
500 void (CALLBACK *callback)(unsigned char *, const struct pcap_pkthdr_win32 *, const unsigned char *),
501 unsigned char *user)
503 /* FIXME: reimplement on top of pcap_next_ex */
504 FIXME( "%p, %d, %p, %p: not implemented\n", pcap, count, callback, user );
505 return -1;
508 int CDECL pcap_major_version( struct pcap *pcap )
510 TRACE( "%p\n", pcap );
511 return PCAP_CALL( major_version, pcap );
514 int CDECL pcap_minor_version( struct pcap *pcap )
516 TRACE( "%p\n", pcap );
517 return PCAP_CALL( minor_version, pcap );
520 int CDECL pcap_next_ex( struct pcap *pcap, struct pcap_pkthdr_win32 **hdr, const unsigned char **data )
522 struct next_ex_params params = { pcap, hdr, data };
523 TRACE( "%p, %p, %p\n", pcap, hdr, data );
524 return PCAP_CALL( next_ex, &params );
527 const unsigned char * CDECL pcap_next( struct pcap *pcap, struct pcap_pkthdr_win32 *hdr )
529 struct pcap_pkthdr_win32 *hdr_ptr;
530 const unsigned char *data;
532 pcap_next_ex( pcap, &hdr_ptr, &data );
533 *hdr = *hdr_ptr;
534 return data;
537 int CDECL pcap_dispatch( struct pcap *pcap, int count,
538 void (CALLBACK *callback)(unsigned char *, const struct pcap_pkthdr_win32 *, const unsigned char *),
539 unsigned char *user )
541 int processed = 0;
542 TRACE( "%p, %d, %p, %p\n", pcap, count, callback, user );
544 while (processed < count)
546 struct pcap_pkthdr_win32 *hdr = NULL;
547 const unsigned char *data = NULL;
549 int ret = pcap_next_ex( pcap, &hdr, &data );
551 if (ret == 1)
552 processed++;
553 else if (ret == 0)
554 break;
555 else if (ret == -2)
557 if (processed == 0) return -2;
558 break;
560 else
561 return ret;
563 callback( user, hdr, data );
566 return processed;
569 static char *strdupWA( const WCHAR *src )
571 char *dst;
572 int len = WideCharToMultiByte( CP_ACP, 0, src, -1, NULL, 0, NULL, NULL );
573 if ((dst = malloc( len ))) WideCharToMultiByte( CP_ACP, 0, src, -1, dst, len, NULL, NULL );
574 return dst;
577 static char *map_win32_device_name( const char *dev )
579 IP_ADAPTER_ADDRESSES *ptr, *adapters = get_adapters();
580 const char *name = strchr( dev, '{' );
581 char *ret = NULL;
583 if (!adapters || !name) return NULL;
584 for (ptr = adapters; ptr; ptr = ptr->Next)
586 if (!strcmp( name, ptr->AdapterName ))
588 ret = strdupWA( ptr->FriendlyName );
589 break;
592 free( adapters );
593 return ret;
596 struct pcap * CDECL pcap_create( const char *source, char *errbuf )
598 char *unix_dev;
599 struct pcap *ret;
600 TRACE( "%s, %p\n", source, errbuf );
602 if (!(unix_dev = map_win32_device_name( source )))
604 if (errbuf) sprintf( errbuf, "Unable to open the adapter." );
605 return NULL;
607 else
609 struct create_params params = { unix_dev, errbuf, &ret };
610 PCAP_CALL( create, &params );
612 free( unix_dev );
613 return ret;
616 static struct pcap *open_live( const char *source, int snaplen, int promisc, int timeout, char *errbuf )
618 char *unix_dev;
619 struct pcap *ret;
621 if (!(unix_dev = map_win32_device_name( source )))
623 if (errbuf) sprintf( errbuf, "Unable to open the adapter." );
624 return NULL;
626 else
628 struct open_live_params params = { unix_dev, snaplen, promisc, timeout, errbuf, &ret };
629 PCAP_CALL( open_live, &params );
631 free( unix_dev );
632 return ret;
635 #define PCAP_OPENFLAG_PROMISCUOUS 1
636 struct pcap * CDECL pcap_open( const char *source, int snaplen, int flags, int timeout, void *auth, char *errbuf )
638 FIXME( "%s, %d, %d, %d, %p, %p: partial stub\n", debugstr_a(source), snaplen, flags, timeout, auth, errbuf );
639 return open_live( source, snaplen, flags & PCAP_OPENFLAG_PROMISCUOUS, timeout, errbuf );
642 struct pcap * CDECL pcap_open_live( const char *source, int snaplen, int promisc, int to_ms, char *errbuf )
644 TRACE( "%s, %d, %d, %d, %p\n", debugstr_a(source), snaplen, promisc, to_ms, errbuf );
645 return open_live( source, snaplen, promisc, to_ms, errbuf );
648 #define PCAP_SRC_FILE 2
649 #define PCAP_SRC_IFLOCAL 3
651 int CDECL pcap_parsesrcstr( const char *source, int *type, char *host, char *port, char *name, char *errbuf )
653 int t = PCAP_SRC_IFLOCAL;
654 const char *p = source;
656 FIXME( "%s, %p, %p, %p, %p, %p: partial stub\n", debugstr_a(source), type, host, port, name, errbuf );
658 if (host)
659 *host = '\0';
660 if (port)
661 *port = '\0';
662 if (name)
663 *name = '\0';
665 if (!strncmp(p, "rpcap://", strlen("rpcap://")))
666 p += strlen("rpcap://");
667 else if (!strncmp(p, "file://", strlen("file://")))
669 p += strlen("file://");
670 t = PCAP_SRC_FILE;
673 if (type)
674 *type = t;
676 if (!*p)
678 if (errbuf)
679 sprintf(errbuf, "The name has not been specified in the source string.");
680 return -1;
683 if (name)
684 strcpy(name, p);
686 return 0;
689 int CDECL pcap_sendpacket( struct pcap *pcap, const unsigned char *buf, int size )
691 struct sendpacket_params params = { pcap, buf, size };
692 TRACE( "%p, %p, %d\n", pcap, buf, size );
693 return PCAP_CALL( sendpacket, &params );
696 int CDECL pcap_set_buffer_size( struct pcap *pcap, int size )
698 struct set_buffer_size_params params = { pcap, size };
699 TRACE( "%p, %d\n", pcap, size );
700 return PCAP_CALL( set_buffer_size, &params );
703 int CDECL pcap_set_datalink( struct pcap *pcap, int link )
705 struct set_datalink_params params = { pcap, link };
706 TRACE( "%p, %d\n", pcap, link );
707 return PCAP_CALL( set_datalink, &params );
710 int CDECL pcap_set_promisc( struct pcap *pcap, int enable )
712 struct set_promisc_params params = { pcap, enable };
713 TRACE( "%p, %d\n", pcap, enable );
714 return PCAP_CALL( set_promisc, &params );
717 int CDECL pcap_set_rfmon( struct pcap *pcap, int enable )
719 struct set_rfmon_params params = { pcap, enable };
720 TRACE( "%p, %d\n", pcap, enable );
721 return PCAP_CALL( set_rfmon, &params );
724 int CDECL pcap_set_snaplen( struct pcap *pcap, int len )
726 struct set_snaplen_params params = { pcap, len };
727 TRACE( "%p, %d\n", pcap, len );
728 return PCAP_CALL( set_snaplen, &params );
731 int CDECL pcap_set_timeout( struct pcap *pcap, int timeout )
733 struct set_timeout_params params = { pcap, timeout };
734 TRACE( "%p, %d\n", pcap, timeout );
735 return PCAP_CALL( set_timeout, &params );
738 int CDECL pcap_set_tstamp_precision( struct pcap *pcap, int precision )
740 struct set_tstamp_precision_params params = { pcap, precision };
741 TRACE( "%p, %d\n", pcap, precision );
742 return PCAP_CALL( set_tstamp_precision, &params );
745 int CDECL pcap_set_tstamp_type( struct pcap *pcap, int type )
747 struct set_tstamp_type_params params = { pcap, type };
748 TRACE( "%p, %d\n", pcap, type );
749 return PCAP_CALL( set_tstamp_type, &params );
752 int CDECL pcap_setbuff( struct pcap *pcap, int size )
754 FIXME( "%p, %d\n", pcap, size );
755 return 0;
758 int CDECL pcap_setfilter( struct pcap *pcap, void *program )
760 struct setfilter_params params = { pcap, program };
761 TRACE( "%p, %p\n", pcap, program );
762 return PCAP_CALL( setfilter, &params );
765 int CDECL pcap_setnonblock( struct pcap *pcap, int nonblock, char *errbuf )
767 struct setnonblock_params params = { pcap, nonblock, errbuf };
768 TRACE( "%p, %d, %p\n", pcap, nonblock, errbuf );
769 return PCAP_CALL( setnonblock, &params );
772 int CDECL pcap_snapshot( struct pcap *pcap )
774 TRACE( "%p\n", pcap );
775 return PCAP_CALL( snapshot, pcap );
778 int CDECL pcap_stats( struct pcap *pcap, void *stats )
780 struct stats_params params = { pcap, stats };
781 TRACE( "%p, %p\n", pcap, stats );
782 return PCAP_CALL( stats, &params );
785 const char * CDECL pcap_statustostr( int status )
787 const char *ret;
788 struct statustostr_params params = { status, &ret };
789 TRACE( "%d\n", status );
790 PCAP_CALL( statustostr, &params );
791 return ret;
794 int CDECL pcap_tstamp_type_name_to_val( const char *name )
796 struct tstamp_type_name_to_val_params params = { name };
797 TRACE( "%s\n", debugstr_a(name) );
798 return PCAP_CALL( tstamp_type_name_to_val, &params );
801 const char * CDECL pcap_tstamp_type_val_to_description( int val )
803 const char *ret;
804 struct tstamp_type_val_to_description_params params = { val, &ret };
805 TRACE( "%d\n", val );
806 PCAP_CALL( tstamp_type_val_to_description, &params );
807 return ret;
810 const char * CDECL pcap_tstamp_type_val_to_name( int val )
812 const char *ret;
813 struct tstamp_type_val_to_name_params params = { val, &ret };
814 TRACE( "%d\n", val );
815 PCAP_CALL( tstamp_type_val_to_name, &params );
816 return ret;
819 int CDECL wsockinit( void )
821 WSADATA wsadata;
822 TRACE( "\n" );
823 if (WSAStartup( MAKEWORD(1, 1), &wsadata )) return -1;
824 return 0;
827 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, void *reserved )
829 switch (reason)
831 case DLL_PROCESS_ATTACH:
832 DisableThreadLibraryCalls( hinst );
833 if (NtQueryVirtualMemory( GetCurrentProcess(), hinst, MemoryWineUnixFuncs,
834 &pcap_handle, sizeof(pcap_handle), NULL ))
835 ERR( "No pcap support, expect problems\n" );
836 break;
837 case DLL_PROCESS_DETACH:
838 break;
840 return TRUE;