wpcap: Convert the Unix library to the __wine_unix_call interface.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
37c4031645
commit
5784c80ba1
|
@ -1,4 +1,5 @@
|
|||
MODULE = wpcap.dll
|
||||
UNIXLIB = wpcap.so
|
||||
IMPORTS = iphlpapi
|
||||
DELAYIMPORTS = ws2_32
|
||||
EXTRALIBS = $(PCAP_LIBS)
|
||||
|
|
|
@ -35,332 +35,342 @@
|
|||
#include "winbase.h"
|
||||
#include "winternl.h"
|
||||
|
||||
#include "wine/unixlib.h"
|
||||
#include "wine/debug.h"
|
||||
#include "unixlib.h"
|
||||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(wpcap);
|
||||
WINE_DECLARE_DEBUG_CHANNEL(winediag);
|
||||
|
||||
static const struct pcap_callbacks *callbacks;
|
||||
|
||||
static int CDECL wrap_activate( struct pcap *pcap )
|
||||
static NTSTATUS wrap_activate( void *args )
|
||||
{
|
||||
struct pcap *pcap = args;
|
||||
return pcap_activate( pcap->handle );
|
||||
}
|
||||
|
||||
static void CDECL wrap_breakloop( struct pcap *pcap )
|
||||
static NTSTATUS wrap_breakloop( void *args )
|
||||
{
|
||||
return pcap_breakloop( pcap->handle );
|
||||
struct pcap *pcap = args;
|
||||
pcap_breakloop( pcap->handle );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static int CDECL wrap_can_set_rfmon( struct pcap *pcap )
|
||||
static NTSTATUS wrap_can_set_rfmon( void *args )
|
||||
{
|
||||
struct pcap *pcap = args;
|
||||
return pcap_can_set_rfmon( pcap->handle );
|
||||
}
|
||||
|
||||
static void CDECL wrap_close( struct pcap *pcap )
|
||||
static NTSTATUS wrap_close( void *args )
|
||||
{
|
||||
struct pcap *pcap = args;
|
||||
pcap_close( pcap->handle );
|
||||
free( pcap );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static int CDECL wrap_compile( struct pcap *pcap, void *program, const char *buf, int optimize, unsigned int mask )
|
||||
static NTSTATUS wrap_compile( void *args )
|
||||
{
|
||||
return pcap_compile( pcap->handle, program, buf, optimize, mask );
|
||||
const struct compile_params *params = args;
|
||||
return pcap_compile( params->pcap->handle, params->program, params->buf, params->optimize, params->mask );
|
||||
}
|
||||
|
||||
static struct pcap * CDECL wrap_create( const char *src, char *errbuf )
|
||||
static NTSTATUS wrap_create( void *args )
|
||||
{
|
||||
const struct create_params *params = args;
|
||||
struct pcap *ret = malloc( sizeof(*ret) );
|
||||
if (ret && !(ret->handle = pcap_create( src, errbuf )))
|
||||
|
||||
if (ret && !(ret->handle = pcap_create( params->src, params->errbuf )))
|
||||
{
|
||||
free( ret );
|
||||
return NULL;
|
||||
ret = NULL;
|
||||
}
|
||||
return ret;
|
||||
*params->ret = ret;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static int CDECL wrap_datalink( struct pcap *pcap )
|
||||
static NTSTATUS wrap_datalink( void *args )
|
||||
{
|
||||
struct pcap *pcap = args;
|
||||
return pcap_datalink( pcap->handle );
|
||||
}
|
||||
|
||||
static int CDECL wrap_datalink_name_to_val( const char *name )
|
||||
static NTSTATUS wrap_datalink_name_to_val( void *args )
|
||||
{
|
||||
return pcap_datalink_name_to_val( name );
|
||||
const struct datalink_name_to_val_params *params = args;
|
||||
return pcap_datalink_name_to_val( params->name );
|
||||
}
|
||||
|
||||
static const char * CDECL wrap_datalink_val_to_description( int link )
|
||||
static NTSTATUS wrap_datalink_val_to_description( void *args )
|
||||
{
|
||||
return pcap_datalink_val_to_description( link );
|
||||
const struct datalink_val_to_description_params *params = args;
|
||||
*params->ret = pcap_datalink_val_to_description( params->link );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static const char * CDECL wrap_datalink_val_to_name( int link )
|
||||
static NTSTATUS wrap_datalink_val_to_name( void *args )
|
||||
{
|
||||
return pcap_datalink_val_to_name( link );
|
||||
const struct datalink_val_to_name_params *params = args;
|
||||
*params->ret = pcap_datalink_val_to_name( params->link );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static void wrap_pcap_handler( unsigned char *user, const struct pcap_pkthdr *hdr, const unsigned char *packet )
|
||||
{
|
||||
struct handler_callback *cb = (struct handler_callback *)user;
|
||||
struct pcap_pkthdr_win32 hdr_win32;
|
||||
|
||||
if (hdr->ts.tv_sec > INT_MAX || hdr->ts.tv_usec > INT_MAX) WARN( "truncating timeval values(s)\n" );
|
||||
hdr_win32.ts.tv_sec = hdr->ts.tv_sec;
|
||||
hdr_win32.ts.tv_usec = hdr->ts.tv_usec;
|
||||
hdr_win32.caplen = hdr->caplen;
|
||||
hdr_win32.len = hdr->len;
|
||||
callbacks->handler( cb, &hdr_win32, packet );
|
||||
}
|
||||
|
||||
static int CDECL wrap_dispatch( struct pcap *pcap, int count,
|
||||
void (CALLBACK *callback)(unsigned char *, const struct pcap_pkthdr_win32 *,
|
||||
const unsigned char *), unsigned char *user )
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
struct handler_callback cb;
|
||||
cb.callback = callback;
|
||||
cb.user = user;
|
||||
return pcap_dispatch( pcap->handle, count, wrap_pcap_handler, (unsigned char *)&cb );
|
||||
}
|
||||
return pcap_dispatch( pcap->handle, count, NULL, user );
|
||||
}
|
||||
|
||||
static void CDECL wrap_dump( unsigned char *user, const struct pcap_pkthdr_win32 *hdr, const unsigned char *packet )
|
||||
static NTSTATUS wrap_dump( void *args )
|
||||
{
|
||||
const struct dump_params *params = args;
|
||||
struct pcap_pkthdr hdr_unix;
|
||||
|
||||
hdr_unix.ts.tv_sec = hdr->ts.tv_sec;
|
||||
hdr_unix.ts.tv_usec = hdr->ts.tv_usec;
|
||||
hdr_unix.caplen = hdr->caplen;
|
||||
hdr_unix.len = hdr->len;
|
||||
return pcap_dump( user, &hdr_unix, packet );
|
||||
hdr_unix.ts.tv_sec = params->hdr->ts.tv_sec;
|
||||
hdr_unix.ts.tv_usec = params->hdr->ts.tv_usec;
|
||||
hdr_unix.caplen = params->hdr->caplen;
|
||||
hdr_unix.len = params->hdr->len;
|
||||
pcap_dump( params->user, &hdr_unix, params->packet );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static void * CDECL wrap_dump_open( struct pcap *pcap, const char *name )
|
||||
static NTSTATUS wrap_dump_open( void *args )
|
||||
{
|
||||
return pcap_dump_open( pcap->handle, name );
|
||||
const struct dump_open_params *params = args;
|
||||
*params->ret = pcap_dump_open( params->pcap->handle, params->name );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static int CDECL wrap_findalldevs( struct pcap_interface **devs, char *errbuf )
|
||||
static NTSTATUS wrap_findalldevs( void *args )
|
||||
{
|
||||
const struct findalldevs_params *params = args;
|
||||
int ret;
|
||||
ret = pcap_findalldevs( (pcap_if_t **)devs, errbuf );
|
||||
if (devs && !*devs)
|
||||
ret = pcap_findalldevs( (pcap_if_t **)params->devs, params->errbuf );
|
||||
if (params->devs && !*params->devs)
|
||||
ERR_(winediag)( "Failed to access raw network (pcap), this requires special permissions.\n" );
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void CDECL wrap_free_datalinks( int *links )
|
||||
static NTSTATUS wrap_free_datalinks( void *args )
|
||||
{
|
||||
int *links = args;
|
||||
pcap_free_datalinks( links );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static void CDECL wrap_free_tstamp_types( int *types )
|
||||
static NTSTATUS wrap_free_tstamp_types( void *args )
|
||||
{
|
||||
int *types = args;
|
||||
pcap_free_tstamp_types( types );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static void CDECL wrap_freealldevs( struct pcap_interface *devs )
|
||||
static NTSTATUS wrap_freealldevs( void *args )
|
||||
{
|
||||
struct pcap_interface *devs = args;
|
||||
pcap_freealldevs( (pcap_if_t *)devs );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static void CDECL wrap_freecode( void *program )
|
||||
static NTSTATUS wrap_freecode( void *args )
|
||||
{
|
||||
return pcap_freecode( program );
|
||||
void *program = args;
|
||||
pcap_freecode( program );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static int CDECL wrap_get_tstamp_precision( struct pcap *pcap )
|
||||
static NTSTATUS wrap_get_tstamp_precision( void *args )
|
||||
{
|
||||
struct pcap *pcap = args;
|
||||
return pcap_get_tstamp_precision( pcap->handle );
|
||||
}
|
||||
|
||||
static char * CDECL wrap_geterr( struct pcap *pcap )
|
||||
static NTSTATUS wrap_geterr( void *args )
|
||||
{
|
||||
return pcap_geterr( pcap->handle );
|
||||
const struct geterr_params *params = args;
|
||||
*params->ret = pcap_geterr( params->pcap->handle );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static int CDECL wrap_getnonblock( struct pcap *pcap, char *errbuf )
|
||||
static NTSTATUS wrap_getnonblock( void *args )
|
||||
{
|
||||
return pcap_getnonblock( pcap->handle, errbuf );
|
||||
const struct getnonblock_params *params = args;
|
||||
return pcap_getnonblock( params->pcap->handle, params->errbuf );
|
||||
}
|
||||
|
||||
static const char * CDECL wrap_lib_version( void )
|
||||
static NTSTATUS wrap_lib_version( void *args )
|
||||
{
|
||||
return pcap_lib_version();
|
||||
const struct lib_version_params *params = args;
|
||||
const char *str = pcap_lib_version();
|
||||
unsigned int len = min( strlen(str) + 1, params->size );
|
||||
memcpy( params->version, str, len );
|
||||
params->version[len - 1] = 0;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static int CDECL wrap_list_datalinks( struct pcap *pcap, int **buf )
|
||||
static NTSTATUS wrap_list_datalinks( void *args )
|
||||
{
|
||||
return pcap_list_datalinks( pcap->handle, buf );
|
||||
const struct list_datalinks_params *params = args;
|
||||
return pcap_list_datalinks( params->pcap->handle, params->buf );
|
||||
}
|
||||
|
||||
static int CDECL wrap_list_tstamp_types( struct pcap *pcap, int **types )
|
||||
static NTSTATUS wrap_list_tstamp_types( void *args )
|
||||
{
|
||||
return pcap_list_tstamp_types( pcap->handle, types );
|
||||
const struct list_tstamp_types_params *params = args;
|
||||
return pcap_list_tstamp_types( params->pcap->handle, params->types );
|
||||
}
|
||||
|
||||
static int CDECL wrap_lookupnet( const char *device, unsigned int *net, unsigned int *mask, char *errbuf )
|
||||
static NTSTATUS wrap_lookupnet( void *args )
|
||||
{
|
||||
return pcap_lookupnet( device, net, mask, errbuf );
|
||||
const struct lookupnet_params *params = args;
|
||||
return pcap_lookupnet( params->device, params->net, params->mask, params->errbuf );
|
||||
}
|
||||
|
||||
static int CDECL wrap_loop( struct pcap *pcap, int count,
|
||||
void (CALLBACK *callback)(unsigned char *, const struct pcap_pkthdr_win32 *,
|
||||
const unsigned char *), unsigned char *user )
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
struct handler_callback cb;
|
||||
cb.callback = callback;
|
||||
cb.user = user;
|
||||
return pcap_loop( pcap->handle, count, wrap_pcap_handler, (unsigned char *)&cb );
|
||||
}
|
||||
return pcap_loop( pcap->handle, count, NULL, user );
|
||||
}
|
||||
|
||||
static int CDECL wrap_major_version( struct pcap *pcap )
|
||||
static NTSTATUS wrap_major_version( void *args )
|
||||
{
|
||||
struct pcap *pcap = args;
|
||||
return pcap_major_version( pcap->handle );
|
||||
}
|
||||
|
||||
static int CDECL wrap_minor_version( struct pcap *pcap )
|
||||
static NTSTATUS wrap_minor_version( void *args )
|
||||
{
|
||||
struct pcap *pcap = args;
|
||||
return pcap_minor_version( pcap->handle );
|
||||
}
|
||||
|
||||
static const unsigned char * CDECL wrap_next( struct pcap *pcap, struct pcap_pkthdr_win32 *hdr )
|
||||
{
|
||||
struct pcap_pkthdr hdr_unix;
|
||||
const unsigned char *ret;
|
||||
|
||||
if ((ret = pcap_next( pcap->handle, &hdr_unix )))
|
||||
{
|
||||
if (hdr_unix.ts.tv_sec > INT_MAX || hdr_unix.ts.tv_usec > INT_MAX) WARN( "truncating timeval values(s)\n" );
|
||||
hdr->ts.tv_sec = hdr_unix.ts.tv_sec;
|
||||
hdr->ts.tv_usec = hdr_unix.ts.tv_usec;
|
||||
hdr->caplen = hdr_unix.caplen;
|
||||
hdr->len = hdr_unix.len;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int CDECL wrap_next_ex( struct pcap *pcap, struct pcap_pkthdr_win32 **hdr, const unsigned char **data )
|
||||
static NTSTATUS wrap_next_ex( void *args )
|
||||
{
|
||||
const struct next_ex_params *params = args;
|
||||
struct pcap *pcap = params->pcap;
|
||||
struct pcap_pkthdr *hdr_unix;
|
||||
int ret;
|
||||
|
||||
if ((ret = pcap_next_ex( pcap->handle, &hdr_unix, data )) == 1)
|
||||
if ((ret = pcap_next_ex( pcap->handle, &hdr_unix, params->data )) == 1)
|
||||
{
|
||||
if (hdr_unix->ts.tv_sec > INT_MAX || hdr_unix->ts.tv_usec > INT_MAX) WARN( "truncating timeval values(s)\n" );
|
||||
pcap->hdr.ts.tv_sec = hdr_unix->ts.tv_sec;
|
||||
pcap->hdr.ts.tv_usec = hdr_unix->ts.tv_usec;
|
||||
pcap->hdr.caplen = hdr_unix->caplen;
|
||||
pcap->hdr.len = hdr_unix->len;
|
||||
*hdr = &pcap->hdr;
|
||||
*params->hdr = &pcap->hdr;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct pcap * CDECL wrap_open_live( const char *source, int snaplen, int promisc, int to_ms, char *errbuf )
|
||||
static NTSTATUS wrap_open_live( void *args )
|
||||
{
|
||||
const struct open_live_params *params = args;
|
||||
struct pcap *ret = malloc( sizeof(*ret) );
|
||||
if (ret && !(ret->handle = pcap_open_live( source, snaplen, promisc, to_ms, errbuf )))
|
||||
if (ret && !(ret->handle = pcap_open_live( params->source, params->snaplen, params->promisc,
|
||||
params->to_ms, params->errbuf )))
|
||||
{
|
||||
free( ret );
|
||||
return NULL;
|
||||
ret = NULL;
|
||||
}
|
||||
return ret;
|
||||
*params->ret = ret;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static int CDECL wrap_sendpacket( struct pcap *pcap, const unsigned char *buf, int size )
|
||||
static NTSTATUS wrap_sendpacket( void *args )
|
||||
{
|
||||
return pcap_sendpacket( pcap->handle, buf, size );
|
||||
const struct sendpacket_params *params = args;
|
||||
return pcap_sendpacket( params->pcap->handle, params->buf, params->size );
|
||||
}
|
||||
|
||||
static int CDECL wrap_set_buffer_size( struct pcap *pcap, int size )
|
||||
static NTSTATUS wrap_set_buffer_size( void *args )
|
||||
{
|
||||
return pcap_set_buffer_size( pcap->handle, size );
|
||||
const struct set_buffer_size_params *params = args;
|
||||
return pcap_set_buffer_size( params->pcap->handle, params->size );
|
||||
}
|
||||
|
||||
static int CDECL wrap_set_datalink( struct pcap *pcap, int link )
|
||||
static NTSTATUS wrap_set_datalink( void *args )
|
||||
{
|
||||
return pcap_set_datalink( pcap->handle, link );
|
||||
const struct set_datalink_params *params = args;
|
||||
return pcap_set_datalink( params->pcap->handle, params->link );
|
||||
}
|
||||
|
||||
static int CDECL wrap_set_promisc( struct pcap *pcap, int enable )
|
||||
static NTSTATUS wrap_set_promisc( void *args )
|
||||
{
|
||||
return pcap_set_promisc( pcap->handle, enable );
|
||||
const struct set_promisc_params *params = args;
|
||||
return pcap_set_promisc( params->pcap->handle, params->enable );
|
||||
}
|
||||
|
||||
static int CDECL wrap_set_rfmon( struct pcap *pcap, int enable )
|
||||
static NTSTATUS wrap_set_rfmon( void *args )
|
||||
{
|
||||
return pcap_set_rfmon( pcap->handle, enable );
|
||||
const struct set_rfmon_params *params = args;
|
||||
return pcap_set_rfmon( params->pcap->handle, params->enable );
|
||||
}
|
||||
|
||||
static int CDECL wrap_set_snaplen( struct pcap *pcap, int len )
|
||||
static NTSTATUS wrap_set_snaplen( void *args )
|
||||
{
|
||||
return pcap_set_snaplen( pcap->handle, len );
|
||||
const struct set_snaplen_params *params = args;
|
||||
return pcap_set_snaplen( params->pcap->handle, params->len );
|
||||
}
|
||||
|
||||
static int CDECL wrap_set_timeout( struct pcap *pcap, int timeout )
|
||||
static NTSTATUS wrap_set_timeout( void *args )
|
||||
{
|
||||
return pcap_set_timeout( pcap->handle, timeout );
|
||||
const struct set_timeout_params *params = args;
|
||||
return pcap_set_timeout( params->pcap->handle, params->timeout );
|
||||
}
|
||||
|
||||
static int CDECL wrap_set_tstamp_precision( struct pcap *pcap, int precision )
|
||||
static NTSTATUS wrap_set_tstamp_precision( void *args )
|
||||
{
|
||||
return pcap_set_tstamp_precision( pcap->handle, precision );
|
||||
const struct set_tstamp_precision_params *params = args;
|
||||
return pcap_set_tstamp_precision( params->pcap->handle, params->precision );
|
||||
}
|
||||
|
||||
static int CDECL wrap_set_tstamp_type( struct pcap *pcap, int type )
|
||||
static NTSTATUS wrap_set_tstamp_type( void *args )
|
||||
{
|
||||
return pcap_set_tstamp_type( pcap->handle, type );
|
||||
const struct set_tstamp_type_params *params = args;
|
||||
return pcap_set_tstamp_type( params->pcap->handle, params->type );
|
||||
}
|
||||
|
||||
static int CDECL wrap_setfilter( struct pcap *pcap, void *program )
|
||||
static NTSTATUS wrap_setfilter( void *args )
|
||||
{
|
||||
return pcap_setfilter( pcap->handle, program );
|
||||
const struct setfilter_params *params = args;
|
||||
return pcap_setfilter( params->pcap->handle, params->program );
|
||||
}
|
||||
|
||||
static int CDECL wrap_setnonblock( struct pcap *pcap, int nonblock, char *errbuf )
|
||||
static NTSTATUS wrap_setnonblock( void *args )
|
||||
{
|
||||
return pcap_setnonblock( pcap->handle, nonblock, errbuf );
|
||||
const struct setnonblock_params *params = args;
|
||||
return pcap_setnonblock( params->pcap->handle, params->nonblock, params->errbuf );
|
||||
}
|
||||
|
||||
static int CDECL wrap_snapshot( struct pcap *pcap )
|
||||
static NTSTATUS wrap_snapshot( void *args )
|
||||
{
|
||||
struct pcap *pcap = args;
|
||||
return pcap_snapshot( pcap->handle );
|
||||
}
|
||||
|
||||
static int CDECL wrap_stats( struct pcap *pcap, void *stats )
|
||||
static NTSTATUS wrap_stats( void *args )
|
||||
{
|
||||
return pcap_stats( pcap->handle, stats );
|
||||
const struct stats_params *params = args;
|
||||
return pcap_stats( params->pcap->handle, params->stats );
|
||||
}
|
||||
|
||||
static const char * CDECL wrap_statustostr( int status )
|
||||
static NTSTATUS wrap_statustostr( void *args )
|
||||
{
|
||||
return pcap_statustostr( status );
|
||||
const struct statustostr_params *params = args;
|
||||
*params->ret = pcap_statustostr( params->status );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static int CDECL wrap_tstamp_type_name_to_val( const char *name )
|
||||
static NTSTATUS wrap_tstamp_type_name_to_val( void *args )
|
||||
{
|
||||
return pcap_tstamp_type_name_to_val( name );
|
||||
const struct tstamp_type_name_to_val_params *params = args;
|
||||
return pcap_tstamp_type_name_to_val( params->name );
|
||||
}
|
||||
|
||||
static const char * CDECL wrap_tstamp_type_val_to_description( int val )
|
||||
static NTSTATUS wrap_tstamp_type_val_to_description( void *args )
|
||||
{
|
||||
return pcap_tstamp_type_val_to_description( val );
|
||||
const struct tstamp_type_val_to_description_params *params = args;
|
||||
*params->ret = pcap_tstamp_type_val_to_description( params->val );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static const char * CDECL wrap_tstamp_type_val_to_name( int val )
|
||||
static NTSTATUS wrap_tstamp_type_val_to_name( void *args )
|
||||
{
|
||||
return pcap_tstamp_type_val_to_name( val );
|
||||
const struct tstamp_type_val_to_name_params *params = args;
|
||||
*params->ret = pcap_tstamp_type_val_to_name( params->val );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static const struct pcap_funcs funcs =
|
||||
const unixlib_entry_t __wine_unix_call_funcs[] =
|
||||
{
|
||||
wrap_activate,
|
||||
wrap_breakloop,
|
||||
|
@ -372,7 +382,7 @@ static const struct pcap_funcs funcs =
|
|||
wrap_datalink_name_to_val,
|
||||
wrap_datalink_val_to_description,
|
||||
wrap_datalink_val_to_name,
|
||||
wrap_dispatch,
|
||||
/* wrap_dispatch, */
|
||||
wrap_dump,
|
||||
wrap_dump_open,
|
||||
wrap_findalldevs,
|
||||
|
@ -387,10 +397,9 @@ static const struct pcap_funcs funcs =
|
|||
wrap_list_datalinks,
|
||||
wrap_list_tstamp_types,
|
||||
wrap_lookupnet,
|
||||
wrap_loop,
|
||||
/* wrap_loop, */
|
||||
wrap_major_version,
|
||||
wrap_minor_version,
|
||||
wrap_next,
|
||||
wrap_next_ex,
|
||||
wrap_open_live,
|
||||
wrap_sendpacket,
|
||||
|
@ -412,11 +421,4 @@ static const struct pcap_funcs funcs =
|
|||
wrap_tstamp_type_val_to_name,
|
||||
};
|
||||
|
||||
NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
|
||||
{
|
||||
if (reason != DLL_PROCESS_ATTACH) return STATUS_SUCCESS;
|
||||
callbacks = ptr_in;
|
||||
*(const struct pcap_funcs **)ptr_out = &funcs;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
#endif /* HAVE_PCAP_PCAP_H */
|
||||
|
|
|
@ -57,69 +57,259 @@ struct pcap
|
|||
struct pcap_pkthdr_win32 hdr;
|
||||
};
|
||||
|
||||
struct handler_callback
|
||||
|
||||
struct compile_params
|
||||
{
|
||||
void (CALLBACK *callback)( unsigned char *, const struct pcap_pkthdr_win32 *, const unsigned char * );
|
||||
void *user;
|
||||
struct pcap *pcap;
|
||||
void *program;
|
||||
const char *buf;
|
||||
int optimize;
|
||||
unsigned int mask;
|
||||
};
|
||||
|
||||
struct pcap_funcs
|
||||
struct create_params
|
||||
{
|
||||
int (CDECL *activate)( struct pcap * );
|
||||
void (CDECL *breakloop)( struct pcap * );
|
||||
int (CDECL *can_set_rfmon)( struct pcap * );
|
||||
void (CDECL *close)( struct pcap * );
|
||||
int (CDECL *compile)( struct pcap *, void *, const char *, int, unsigned int );
|
||||
struct pcap * (CDECL *create)( const char *, char * );
|
||||
int (CDECL *datalink)( struct pcap * );
|
||||
int (CDECL *datalink_name_to_val)( const char * );
|
||||
const char * (CDECL *datalink_val_to_description)( int );
|
||||
const char * (CDECL *datalink_val_to_name)( int );
|
||||
int (CDECL *dispatch)( struct pcap *, int,
|
||||
void (CALLBACK *)(unsigned char *, const struct pcap_pkthdr_win32 *, const unsigned char *),
|
||||
unsigned char * );
|
||||
void (CDECL *dump)( unsigned char *, const struct pcap_pkthdr_win32 *, const unsigned char * );
|
||||
void * (CDECL *dump_open)( struct pcap *, const char * );
|
||||
int (CDECL *findalldevs)( struct pcap_interface **, char * );
|
||||
void (CDECL *free_datalinks)( int * );
|
||||
void (CDECL *free_tstamp_types)( int * );
|
||||
void (CDECL *freealldevs)( struct pcap_interface * );
|
||||
void (CDECL *freecode)( void * );
|
||||
int (CDECL *get_tstamp_precision)( struct pcap * );
|
||||
char * (CDECL *geterr)( struct pcap * );
|
||||
int (CDECL *getnonblock)( struct pcap *, char * );
|
||||
const char * (CDECL *lib_version)( void );
|
||||
int (CDECL *list_datalinks)( struct pcap *, int ** );
|
||||
int (CDECL *list_tstamp_types)( struct pcap *, int ** );
|
||||
int (CDECL *lookupnet)( const char *, unsigned int *, unsigned int *, char * );
|
||||
int (CDECL *loop)( struct pcap *, int,
|
||||
void (CALLBACK *)(unsigned char *, const struct pcap_pkthdr_win32 *, const unsigned char *),
|
||||
unsigned char * );
|
||||
int (CDECL *major_version)( struct pcap * );
|
||||
int (CDECL *minor_version)( struct pcap * );
|
||||
const unsigned char * (CDECL *next)( struct pcap *, struct pcap_pkthdr_win32 * );
|
||||
int (CDECL *next_ex)( struct pcap *, struct pcap_pkthdr_win32 **, const unsigned char ** );
|
||||
struct pcap * (CDECL *open_live)( const char *, int, int, int, char * );
|
||||
int (CDECL *sendpacket)( struct pcap *, const unsigned char *, int );
|
||||
int (CDECL *set_buffer_size)( struct pcap *, int );
|
||||
int (CDECL *set_datalink)( struct pcap *, int );
|
||||
int (CDECL *set_promisc)( struct pcap *, int );
|
||||
int (CDECL *set_rfmon)( struct pcap *, int );
|
||||
int (CDECL *set_snaplen)( struct pcap *, int );
|
||||
int (CDECL *set_timeout)( struct pcap *, int );
|
||||
int (CDECL *set_tstamp_precision)( struct pcap *, int );
|
||||
int (CDECL *set_tstamp_type)( struct pcap *, int );
|
||||
int (CDECL *setfilter)( struct pcap *, void * );
|
||||
int (CDECL *setnonblock)( struct pcap *, int, char * );
|
||||
int (CDECL *snapshot)( struct pcap * );
|
||||
int (CDECL *stats)( struct pcap *, void * );
|
||||
const char * (CDECL *statustostr)( int );
|
||||
int (CDECL *tstamp_type_name_to_val)( const char * );
|
||||
const char * (CDECL *tstamp_type_val_to_description)( int );
|
||||
const char * (CDECL *tstamp_type_val_to_name)( int );
|
||||
const char *src;
|
||||
char *errbuf;
|
||||
struct pcap **ret;
|
||||
};
|
||||
|
||||
struct pcap_callbacks
|
||||
struct datalink_name_to_val_params
|
||||
{
|
||||
void (CDECL *handler)( struct handler_callback *, const struct pcap_pkthdr_win32 *, const unsigned char * );
|
||||
const char *name;
|
||||
};
|
||||
|
||||
struct datalink_val_to_description_params
|
||||
{
|
||||
int link;
|
||||
const char **ret;
|
||||
};
|
||||
|
||||
struct datalink_val_to_name_params
|
||||
{
|
||||
int link;
|
||||
const char **ret;
|
||||
};
|
||||
|
||||
struct dump_params
|
||||
{
|
||||
unsigned char *user;
|
||||
const struct pcap_pkthdr_win32 *hdr;
|
||||
const unsigned char *packet;
|
||||
};
|
||||
|
||||
struct dump_open_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
const char *name;
|
||||
void **ret;
|
||||
};
|
||||
|
||||
struct findalldevs_params
|
||||
{
|
||||
struct pcap_interface **devs;
|
||||
char *errbuf;
|
||||
};
|
||||
|
||||
struct geterr_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
char **ret;
|
||||
};
|
||||
|
||||
struct getnonblock_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
char *errbuf;
|
||||
};
|
||||
|
||||
struct lib_version_params
|
||||
{
|
||||
char *version;
|
||||
unsigned int size;
|
||||
};
|
||||
|
||||
struct list_datalinks_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
int **buf;
|
||||
};
|
||||
|
||||
struct list_tstamp_types_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
int **types;
|
||||
};
|
||||
|
||||
struct lookupnet_params
|
||||
{
|
||||
const char *device;
|
||||
unsigned int *net;
|
||||
unsigned int *mask;
|
||||
char *errbuf;
|
||||
};
|
||||
|
||||
struct next_ex_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
struct pcap_pkthdr_win32 **hdr;
|
||||
const unsigned char **data;
|
||||
};
|
||||
|
||||
struct open_live_params
|
||||
{
|
||||
const char *source;
|
||||
int snaplen;
|
||||
int promisc;
|
||||
int to_ms;
|
||||
char *errbuf;
|
||||
struct pcap **ret;
|
||||
};
|
||||
|
||||
struct sendpacket_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
const unsigned char *buf;
|
||||
int size;
|
||||
};
|
||||
|
||||
struct set_buffer_size_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
int size;
|
||||
};
|
||||
|
||||
struct set_datalink_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
int link;
|
||||
};
|
||||
|
||||
struct set_promisc_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
int enable;
|
||||
};
|
||||
|
||||
struct set_rfmon_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
int enable;
|
||||
};
|
||||
|
||||
struct set_snaplen_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
int len;
|
||||
};
|
||||
|
||||
struct set_timeout_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
int timeout;
|
||||
};
|
||||
|
||||
struct set_tstamp_precision_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
int precision;
|
||||
};
|
||||
|
||||
struct set_tstamp_type_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
int type;
|
||||
};
|
||||
|
||||
struct setfilter_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
void *program;
|
||||
};
|
||||
|
||||
struct setnonblock_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
int nonblock;
|
||||
char *errbuf;
|
||||
};
|
||||
|
||||
struct stats_params
|
||||
{
|
||||
struct pcap *pcap;
|
||||
void *stats;
|
||||
};
|
||||
|
||||
struct statustostr_params
|
||||
{
|
||||
int status;
|
||||
const char **ret;
|
||||
};
|
||||
|
||||
struct tstamp_type_name_to_val_params
|
||||
{
|
||||
const char *name;
|
||||
};
|
||||
|
||||
struct tstamp_type_val_to_description_params
|
||||
{
|
||||
int val;
|
||||
const char **ret;
|
||||
};
|
||||
|
||||
struct tstamp_type_val_to_name_params
|
||||
{
|
||||
int val;
|
||||
const char **ret;
|
||||
};
|
||||
|
||||
enum pcap_funcs
|
||||
{
|
||||
unix_activate,
|
||||
unix_breakloop,
|
||||
unix_can_set_rfmon,
|
||||
unix_close,
|
||||
unix_compile,
|
||||
unix_create,
|
||||
unix_datalink,
|
||||
unix_datalink_name_to_val,
|
||||
unix_datalink_val_to_description,
|
||||
unix_datalink_val_to_name,
|
||||
/* unix_dispatch, */
|
||||
unix_dump,
|
||||
unix_dump_open,
|
||||
unix_findalldevs,
|
||||
unix_free_datalinks,
|
||||
unix_free_tstamp_types,
|
||||
unix_freealldevs,
|
||||
unix_freecode,
|
||||
unix_get_tstamp_precision,
|
||||
unix_geterr,
|
||||
unix_getnonblock,
|
||||
unix_lib_version,
|
||||
unix_list_datalinks,
|
||||
unix_list_tstamp_types,
|
||||
unix_lookupnet,
|
||||
/* unix_loop, */
|
||||
unix_major_version,
|
||||
unix_minor_version,
|
||||
unix_next_ex,
|
||||
unix_open_live,
|
||||
unix_sendpacket,
|
||||
unix_set_buffer_size,
|
||||
unix_set_datalink,
|
||||
unix_set_promisc,
|
||||
unix_set_rfmon,
|
||||
unix_set_snaplen,
|
||||
unix_set_timeout,
|
||||
unix_set_tstamp_precision,
|
||||
unix_set_tstamp_type,
|
||||
unix_setfilter,
|
||||
unix_setnonblock,
|
||||
unix_snapshot,
|
||||
unix_stats,
|
||||
unix_statustostr,
|
||||
unix_tstamp_type_name_to_val,
|
||||
unix_tstamp_type_val_to_description,
|
||||
unix_tstamp_type_val_to_name,
|
||||
};
|
||||
|
|
|
@ -27,85 +27,101 @@
|
|||
#include "ws2ipdef.h"
|
||||
#include "iphlpapi.h"
|
||||
|
||||
#include "wine/unixlib.h"
|
||||
#include "wine/debug.h"
|
||||
#include "unixlib.h"
|
||||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(wpcap);
|
||||
|
||||
const struct pcap_funcs *pcap_funcs = NULL;
|
||||
static unixlib_handle_t pcap_handle;
|
||||
|
||||
#define PCAP_CALL( func, params ) __wine_unix_call( pcap_handle, unix_ ## func, params )
|
||||
|
||||
int CDECL pcap_activate( struct pcap *pcap )
|
||||
{
|
||||
TRACE( "%p\n", pcap );
|
||||
return pcap_funcs->activate( pcap );
|
||||
return PCAP_CALL( activate, pcap );
|
||||
}
|
||||
|
||||
void CDECL pcap_breakloop( struct pcap *pcap )
|
||||
{
|
||||
TRACE( "%p\n", pcap );
|
||||
pcap_funcs->breakloop( pcap );
|
||||
PCAP_CALL( breakloop, pcap );
|
||||
}
|
||||
|
||||
int CDECL pcap_can_set_rfmon( struct pcap *pcap )
|
||||
{
|
||||
TRACE( "%p\n", pcap );
|
||||
return pcap_funcs->can_set_rfmon( pcap );
|
||||
return PCAP_CALL( can_set_rfmon, pcap );
|
||||
}
|
||||
|
||||
void CDECL pcap_close( struct pcap *pcap )
|
||||
{
|
||||
TRACE( "%p\n", pcap );
|
||||
pcap_funcs->close( pcap );
|
||||
PCAP_CALL( close, pcap );
|
||||
}
|
||||
|
||||
int CDECL pcap_compile( struct pcap *pcap, void *program, const char *buf, int optimize, unsigned int mask )
|
||||
{
|
||||
struct compile_params params = { pcap, program, buf, optimize, mask };
|
||||
TRACE( "%p, %p, %s, %d, %u\n", pcap, program, debugstr_a(buf), optimize, mask );
|
||||
return pcap_funcs->compile( pcap, program, buf, optimize, mask );
|
||||
return PCAP_CALL( compile, ¶ms );
|
||||
}
|
||||
|
||||
struct pcap * CDECL pcap_create( const char *src, char *errbuf )
|
||||
{
|
||||
struct pcap *ret;
|
||||
struct create_params params = { src, errbuf, &ret };
|
||||
TRACE( "%s, %p\n", src, errbuf );
|
||||
return pcap_funcs->create( src, errbuf );
|
||||
PCAP_CALL( create, ¶ms );
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CDECL pcap_datalink( struct pcap *pcap )
|
||||
{
|
||||
TRACE( "%p\n", pcap );
|
||||
return pcap_funcs->datalink( pcap );
|
||||
return PCAP_CALL( datalink, pcap );
|
||||
}
|
||||
|
||||
int CDECL pcap_datalink_name_to_val( const char *name )
|
||||
{
|
||||
struct datalink_name_to_val_params params = { name };
|
||||
TRACE( "%s\n", debugstr_a(name) );
|
||||
return pcap_funcs->datalink_name_to_val( name );
|
||||
return PCAP_CALL( datalink_name_to_val, ¶ms );
|
||||
}
|
||||
|
||||
const char * CDECL pcap_datalink_val_to_description( int link )
|
||||
{
|
||||
const char *ret;
|
||||
struct datalink_val_to_description_params params = { link, &ret };
|
||||
TRACE( "%d\n", link );
|
||||
return pcap_funcs->datalink_val_to_description( link );
|
||||
PCAP_CALL( datalink_val_to_description, ¶ms );
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char * CDECL pcap_datalink_val_to_name( int link )
|
||||
{
|
||||
const char *ret;
|
||||
struct datalink_val_to_name_params params = { link, &ret };
|
||||
TRACE( "%d\n", link );
|
||||
return pcap_funcs->datalink_val_to_name( link );
|
||||
PCAP_CALL( datalink_val_to_name, ¶ms );
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CDECL pcap_dispatch( struct pcap *pcap, int count,
|
||||
void (CALLBACK *callback)(unsigned char *, const struct pcap_pkthdr_win32 *, const unsigned char *),
|
||||
unsigned char *user )
|
||||
{
|
||||
TRACE( "%p, %d, %p, %p\n", pcap, count, callback, user );
|
||||
return pcap_funcs->dispatch( pcap, count, callback, user );
|
||||
/* FIXME: reimplement on top of pcap_next_ex */
|
||||
FIXME( "%p, %d, %p, %p: not implemented\n", pcap, count, callback, user );
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CDECL pcap_dump( unsigned char *user, const struct pcap_pkthdr_win32 *hdr, const unsigned char *packet )
|
||||
{
|
||||
struct dump_params params = { user, hdr, packet };
|
||||
TRACE( "%p, %p, %p\n", user, hdr, packet );
|
||||
pcap_funcs->dump( user, hdr, packet );
|
||||
PCAP_CALL( dump, ¶ms );
|
||||
}
|
||||
|
||||
static inline WCHAR *strdupAW( const char *str )
|
||||
|
@ -124,6 +140,7 @@ void * CDECL pcap_dump_open( struct pcap *pcap, const char *filename )
|
|||
void *dumper;
|
||||
WCHAR *filenameW;
|
||||
char *unix_path;
|
||||
struct dump_open_params params;
|
||||
|
||||
TRACE( "%p, %s\n", pcap, debugstr_a(filename) );
|
||||
|
||||
|
@ -134,7 +151,10 @@ void * CDECL pcap_dump_open( struct pcap *pcap, const char *filename )
|
|||
|
||||
TRACE( "unix_path %s\n", debugstr_a(unix_path) );
|
||||
|
||||
dumper = pcap_funcs->dump_open( pcap, unix_path );
|
||||
params.pcap = pcap;
|
||||
params.name = unix_path;
|
||||
params.ret = &dumper;
|
||||
PCAP_CALL( dump_open, ¶ms );
|
||||
RtlFreeHeap( GetProcessHeap(), 0, unix_path );
|
||||
return dumper;
|
||||
}
|
||||
|
@ -350,6 +370,7 @@ static int find_all_devices( const char *source, struct pcap_interface **devs, c
|
|||
{
|
||||
struct pcap_interface *unix_devs, *win32_devs = NULL, *cur, *dev;
|
||||
IP_ADAPTER_ADDRESSES *ptr, *adapters = get_adapters();
|
||||
struct findalldevs_params params = { &unix_devs, errbuf };
|
||||
int ret;
|
||||
|
||||
if (!adapters)
|
||||
|
@ -358,7 +379,7 @@ static int find_all_devices( const char *source, struct pcap_interface **devs, c
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (!(ret = pcap_funcs->findalldevs( &unix_devs, errbuf )))
|
||||
if (!(ret = PCAP_CALL( findalldevs, ¶ms )))
|
||||
{
|
||||
cur = unix_devs;
|
||||
while (cur)
|
||||
|
@ -370,7 +391,7 @@ static int find_all_devices( const char *source, struct pcap_interface **devs, c
|
|||
cur = cur->next;
|
||||
}
|
||||
*devs = win32_devs;
|
||||
pcap_funcs->freealldevs( unix_devs );
|
||||
PCAP_CALL( freealldevs, unix_devs );
|
||||
}
|
||||
|
||||
free( adapters );
|
||||
|
@ -392,13 +413,13 @@ int CDECL pcap_findalldevs_ex( char *source, void *auth, struct pcap_interface *
|
|||
void CDECL pcap_free_datalinks( int *links )
|
||||
{
|
||||
TRACE( "%p\n", links );
|
||||
pcap_funcs->free_datalinks( links );
|
||||
PCAP_CALL( free_datalinks, links );
|
||||
}
|
||||
|
||||
void CDECL pcap_free_tstamp_types( int *types )
|
||||
{
|
||||
TRACE( "%p\n", types );
|
||||
pcap_funcs->free_tstamp_types( types );
|
||||
PCAP_CALL( free_tstamp_types, types );
|
||||
}
|
||||
|
||||
void CDECL pcap_freealldevs( struct pcap_interface *devs )
|
||||
|
@ -410,7 +431,7 @@ void CDECL pcap_freealldevs( struct pcap_interface *devs )
|
|||
void CDECL pcap_freecode( void *program )
|
||||
{
|
||||
TRACE( "%p\n", program );
|
||||
pcap_funcs->freecode( program );
|
||||
PCAP_CALL( freecode, program );
|
||||
}
|
||||
|
||||
void * CDECL pcap_get_airpcap_handle( struct pcap *pcap )
|
||||
|
@ -422,26 +443,30 @@ void * CDECL pcap_get_airpcap_handle( struct pcap *pcap )
|
|||
int CDECL pcap_get_tstamp_precision( struct pcap *pcap )
|
||||
{
|
||||
TRACE( "%p\n", pcap );
|
||||
return pcap_funcs->get_tstamp_precision( pcap );
|
||||
return PCAP_CALL( get_tstamp_precision, pcap );
|
||||
}
|
||||
|
||||
char * CDECL pcap_geterr( struct pcap *pcap )
|
||||
{
|
||||
char *ret;
|
||||
struct geterr_params params = { pcap, &ret };
|
||||
TRACE( "%p\n", pcap );
|
||||
return pcap_funcs->geterr( pcap );
|
||||
PCAP_CALL( geterr, ¶ms );
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CDECL pcap_getnonblock( struct pcap *pcap, char *errbuf )
|
||||
{
|
||||
struct getnonblock_params params = { pcap, errbuf };
|
||||
TRACE( "%p, %p\n", pcap, errbuf );
|
||||
return pcap_funcs->getnonblock( pcap, errbuf );
|
||||
return PCAP_CALL( getnonblock, ¶ms );
|
||||
}
|
||||
|
||||
static char lib_version[256];
|
||||
static BOOL WINAPI init_lib_version( INIT_ONCE *once, void *param, void **ctx )
|
||||
{
|
||||
const char *str = pcap_funcs->lib_version();
|
||||
if (strlen( str ) < sizeof(lib_version)) strcpy( lib_version, str );
|
||||
struct lib_version_params params = { lib_version, sizeof(lib_version) };
|
||||
PCAP_CALL( lib_version, ¶ms );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -455,14 +480,16 @@ const char * CDECL pcap_lib_version( void )
|
|||
|
||||
int CDECL pcap_list_datalinks( struct pcap *pcap, int **buf )
|
||||
{
|
||||
struct list_datalinks_params params = { pcap, buf };
|
||||
TRACE( "%p, %p\n", pcap, buf );
|
||||
return pcap_funcs->list_datalinks( pcap, buf );
|
||||
return PCAP_CALL( list_datalinks, ¶ms );
|
||||
}
|
||||
|
||||
int CDECL pcap_list_tstamp_types( struct pcap *pcap, int **types )
|
||||
{
|
||||
struct list_tstamp_types_params params = { pcap, types };
|
||||
TRACE( "%p, %p\n", pcap, types );
|
||||
return pcap_funcs->list_tstamp_types( pcap, types );
|
||||
return PCAP_CALL( list_tstamp_types, ¶ms );
|
||||
}
|
||||
|
||||
char * CDECL pcap_lookupdev( char *errbuf )
|
||||
|
@ -473,7 +500,7 @@ char * CDECL pcap_lookupdev( char *errbuf )
|
|||
TRACE( "%p\n", errbuf );
|
||||
if (!ret)
|
||||
{
|
||||
if (pcap_findalldevs( &devs, errbuf ) == -1 || devs) return NULL;
|
||||
if (pcap_findalldevs( &devs, errbuf ) == -1 || !devs) return NULL;
|
||||
if ((ret = malloc( strlen(devs->name) + 1 ))) strcpy( ret, devs->name );
|
||||
pcap_freealldevs( devs );
|
||||
}
|
||||
|
@ -482,40 +509,47 @@ char * CDECL pcap_lookupdev( char *errbuf )
|
|||
|
||||
int CDECL pcap_lookupnet( const char *device, unsigned int *net, unsigned int *mask, char *errbuf )
|
||||
{
|
||||
struct lookupnet_params params = { device, net, mask, errbuf };
|
||||
TRACE( "%s, %p, %p, %p\n", debugstr_a(device), net, mask, errbuf );
|
||||
return pcap_funcs->lookupnet( device, net, mask, errbuf );
|
||||
return PCAP_CALL( lookupnet, ¶ms );
|
||||
}
|
||||
|
||||
int CDECL pcap_loop( struct pcap *pcap, int count,
|
||||
void (CALLBACK *callback)(unsigned char *, const struct pcap_pkthdr_win32 *, const unsigned char *),
|
||||
unsigned char *user)
|
||||
{
|
||||
TRACE( "%p, %d, %p, %p\n", pcap, count, callback, user );
|
||||
return pcap_funcs->loop( pcap, count, callback, user );
|
||||
/* FIXME: reimplement on top of pcap_next_ex */
|
||||
FIXME( "%p, %d, %p, %p: not implemented\n", pcap, count, callback, user );
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CDECL pcap_major_version( struct pcap *pcap )
|
||||
{
|
||||
TRACE( "%p\n", pcap );
|
||||
return pcap_funcs->major_version( pcap );
|
||||
return PCAP_CALL( major_version, pcap );
|
||||
}
|
||||
|
||||
int CDECL pcap_minor_version( struct pcap *pcap )
|
||||
{
|
||||
TRACE( "%p\n", pcap );
|
||||
return pcap_funcs->minor_version( pcap );
|
||||
}
|
||||
|
||||
const unsigned char * CDECL pcap_next( struct pcap *pcap, struct pcap_pkthdr_win32 *hdr )
|
||||
{
|
||||
TRACE( "%p, %p\n", pcap, hdr );
|
||||
return pcap_funcs->next( pcap, hdr );
|
||||
return PCAP_CALL( minor_version, pcap );
|
||||
}
|
||||
|
||||
int CDECL pcap_next_ex( struct pcap *pcap, struct pcap_pkthdr_win32 **hdr, const unsigned char **data )
|
||||
{
|
||||
struct next_ex_params params = { pcap, hdr, data };
|
||||
TRACE( "%p, %p, %p\n", pcap, hdr, data );
|
||||
return pcap_funcs->next_ex( pcap, hdr, data );
|
||||
return PCAP_CALL( next_ex, ¶ms );
|
||||
}
|
||||
|
||||
const unsigned char * CDECL pcap_next( struct pcap *pcap, struct pcap_pkthdr_win32 *hdr )
|
||||
{
|
||||
struct pcap_pkthdr_win32 *hdr_ptr;
|
||||
const unsigned char *data;
|
||||
|
||||
pcap_next_ex( pcap, &hdr_ptr, &data );
|
||||
*hdr = *hdr_ptr;
|
||||
return data;
|
||||
}
|
||||
|
||||
static char *strdupWA( const WCHAR *src )
|
||||
|
@ -555,8 +589,11 @@ static struct pcap *open_live( const char *source, int snaplen, int promisc, int
|
|||
if (errbuf) sprintf( errbuf, "Unable to open the adapter." );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = pcap_funcs->open_live( unix_dev, snaplen, promisc, timeout, errbuf );
|
||||
else
|
||||
{
|
||||
struct open_live_params params = { unix_dev, snaplen, promisc, timeout, errbuf, &ret };
|
||||
PCAP_CALL( open_live, ¶ms );
|
||||
}
|
||||
free( unix_dev );
|
||||
return ret;
|
||||
}
|
||||
|
@ -617,56 +654,65 @@ int CDECL pcap_parsesrcstr( const char *source, int *type, char *host, char *por
|
|||
|
||||
int CDECL pcap_sendpacket( struct pcap *pcap, const unsigned char *buf, int size )
|
||||
{
|
||||
struct sendpacket_params params = { pcap, buf, size };
|
||||
TRACE( "%p, %p, %d\n", pcap, buf, size );
|
||||
return pcap_funcs->sendpacket( pcap, buf, size );
|
||||
return PCAP_CALL( sendpacket, ¶ms );
|
||||
}
|
||||
|
||||
int CDECL pcap_set_buffer_size( struct pcap *pcap, int size )
|
||||
{
|
||||
struct set_buffer_size_params params = { pcap, size };
|
||||
TRACE( "%p, %d\n", pcap, size );
|
||||
return pcap_funcs->set_buffer_size( pcap, size );
|
||||
return PCAP_CALL( set_buffer_size, ¶ms );
|
||||
}
|
||||
|
||||
int CDECL pcap_set_datalink( struct pcap *pcap, int link )
|
||||
{
|
||||
struct set_datalink_params params = { pcap, link };
|
||||
TRACE( "%p, %d\n", pcap, link );
|
||||
return pcap_funcs->set_datalink( pcap, link );
|
||||
return PCAP_CALL( set_datalink, ¶ms );
|
||||
}
|
||||
|
||||
int CDECL pcap_set_promisc( struct pcap *pcap, int enable )
|
||||
{
|
||||
struct set_promisc_params params = { pcap, enable };
|
||||
TRACE( "%p, %d\n", pcap, enable );
|
||||
return pcap_funcs->set_promisc( pcap, enable );
|
||||
return PCAP_CALL( set_promisc, ¶ms );
|
||||
}
|
||||
|
||||
int CDECL pcap_set_rfmon( struct pcap *pcap, int enable )
|
||||
{
|
||||
struct set_rfmon_params params = { pcap, enable };
|
||||
TRACE( "%p, %d\n", pcap, enable );
|
||||
return pcap_funcs->set_rfmon( pcap, enable );
|
||||
return PCAP_CALL( set_rfmon, ¶ms );
|
||||
}
|
||||
|
||||
int CDECL pcap_set_snaplen( struct pcap *pcap, int len )
|
||||
{
|
||||
struct set_snaplen_params params = { pcap, len };
|
||||
TRACE( "%p, %d\n", pcap, len );
|
||||
return pcap_funcs->set_snaplen( pcap, len );
|
||||
return PCAP_CALL( set_snaplen, ¶ms );
|
||||
}
|
||||
|
||||
int CDECL pcap_set_timeout( struct pcap *pcap, int timeout )
|
||||
{
|
||||
struct set_timeout_params params = { pcap, timeout };
|
||||
TRACE( "%p, %d\n", pcap, timeout );
|
||||
return pcap_funcs->set_timeout( pcap, timeout );
|
||||
return PCAP_CALL( set_timeout, ¶ms );
|
||||
}
|
||||
|
||||
int CDECL pcap_set_tstamp_precision( struct pcap *pcap, int precision )
|
||||
{
|
||||
struct set_tstamp_precision_params params = { pcap, precision };
|
||||
TRACE( "%p, %d\n", pcap, precision );
|
||||
return pcap_funcs->set_tstamp_precision( pcap, precision );
|
||||
return PCAP_CALL( set_tstamp_precision, ¶ms );
|
||||
}
|
||||
|
||||
int CDECL pcap_set_tstamp_type( struct pcap *pcap, int type )
|
||||
{
|
||||
struct set_tstamp_type_params params = { pcap, type };
|
||||
TRACE( "%p, %d\n", pcap, type );
|
||||
return pcap_funcs->set_tstamp_type( pcap, type );
|
||||
return PCAP_CALL( set_tstamp_type, ¶ms );
|
||||
}
|
||||
|
||||
int CDECL pcap_setbuff( struct pcap *pcap, int size )
|
||||
|
@ -677,50 +723,63 @@ int CDECL pcap_setbuff( struct pcap *pcap, int size )
|
|||
|
||||
int CDECL pcap_setfilter( struct pcap *pcap, void *program )
|
||||
{
|
||||
struct setfilter_params params = { pcap, program };
|
||||
TRACE( "%p, %p\n", pcap, program );
|
||||
return pcap_funcs->setfilter( pcap, program );
|
||||
return PCAP_CALL( setfilter, ¶ms );
|
||||
}
|
||||
|
||||
int CDECL pcap_setnonblock( struct pcap *pcap, int nonblock, char *errbuf )
|
||||
{
|
||||
struct setnonblock_params params = { pcap, nonblock, errbuf };
|
||||
TRACE( "%p, %d, %p\n", pcap, nonblock, errbuf );
|
||||
return pcap_funcs->setnonblock( pcap, nonblock, errbuf );
|
||||
return PCAP_CALL( setnonblock, ¶ms );
|
||||
}
|
||||
|
||||
int CDECL pcap_snapshot( struct pcap *pcap )
|
||||
{
|
||||
TRACE( "%p\n", pcap );
|
||||
return pcap_funcs->snapshot( pcap );
|
||||
return PCAP_CALL( snapshot, pcap );
|
||||
}
|
||||
|
||||
int CDECL pcap_stats( struct pcap *pcap, void *stats )
|
||||
{
|
||||
struct stats_params params = { pcap, stats };
|
||||
TRACE( "%p, %p\n", pcap, stats );
|
||||
return pcap_funcs->stats( pcap, stats );
|
||||
return PCAP_CALL( stats, ¶ms );
|
||||
}
|
||||
|
||||
const char * CDECL pcap_statustostr( int status )
|
||||
{
|
||||
const char *ret;
|
||||
struct statustostr_params params = { status, &ret };
|
||||
TRACE( "%d\n", status );
|
||||
return pcap_funcs->statustostr( status );
|
||||
PCAP_CALL( statustostr, ¶ms );
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CDECL pcap_tstamp_type_name_to_val( const char *name )
|
||||
{
|
||||
struct tstamp_type_name_to_val_params params = { name };
|
||||
TRACE( "%s\n", debugstr_a(name) );
|
||||
return pcap_funcs->tstamp_type_name_to_val( name );
|
||||
return PCAP_CALL( tstamp_type_name_to_val, ¶ms );
|
||||
}
|
||||
|
||||
const char * CDECL pcap_tstamp_type_val_to_description( int val )
|
||||
{
|
||||
const char *ret;
|
||||
struct tstamp_type_val_to_description_params params = { val, &ret };
|
||||
TRACE( "%d\n", val );
|
||||
return pcap_funcs->tstamp_type_val_to_description( val );
|
||||
PCAP_CALL( tstamp_type_val_to_description, ¶ms );
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char * CDECL pcap_tstamp_type_val_to_name( int val )
|
||||
{
|
||||
const char *ret;
|
||||
struct tstamp_type_val_to_name_params params = { val, &ret };
|
||||
TRACE( "%d\n", val );
|
||||
return pcap_funcs->tstamp_type_val_to_name( val );
|
||||
PCAP_CALL( tstamp_type_val_to_name, ¶ms );
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CDECL wsockinit( void )
|
||||
|
@ -731,26 +790,14 @@ int CDECL wsockinit( void )
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void CDECL pcap_handler_cb( struct handler_callback *cb, const struct pcap_pkthdr_win32 *hdr,
|
||||
const unsigned char *packet )
|
||||
{
|
||||
TRACE( "%p, %p, %p\n", cb, hdr, packet );
|
||||
cb->callback( cb->user, hdr, packet );
|
||||
TRACE( "callback completed\n" );
|
||||
}
|
||||
|
||||
const struct pcap_callbacks pcap_callbacks =
|
||||
{
|
||||
pcap_handler_cb
|
||||
};
|
||||
|
||||
BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, void *reserved )
|
||||
{
|
||||
switch (reason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
DisableThreadLibraryCalls( hinst );
|
||||
if (__wine_init_unix_lib( hinst, reason, &pcap_callbacks, &pcap_funcs ))
|
||||
if (NtQueryVirtualMemory( GetCurrentProcess(), hinst, MemoryWineUnixFuncs,
|
||||
&pcap_handle, sizeof(pcap_handle), NULL ))
|
||||
ERR( "No pcap support, expect problems\n" );
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
|
|
Loading…
Reference in New Issue