mirror of
git://source.winehq.org/git/wine.git
synced 2024-09-15 04:34:48 +00:00
263 lines
6.7 KiB
C
263 lines
6.7 KiB
C
|
/*
|
||
|
* Copyright 2011, 2014 André Hentschel
|
||
|
* Copyright 2021 Hans Leidekker for CodeWeavers
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Lesser General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2.1 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Lesser General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Lesser General Public
|
||
|
* License along with this library; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||
|
*/
|
||
|
|
||
|
#if 0
|
||
|
#pragma makedep unix
|
||
|
#endif
|
||
|
|
||
|
#include "config.h"
|
||
|
|
||
|
#ifdef HAVE_PCAP_PCAP_H
|
||
|
#include <pcap/pcap.h>
|
||
|
|
||
|
#include <stdarg.h>
|
||
|
#include "ntstatus.h"
|
||
|
#define WIN32_NO_STATUS
|
||
|
#include "windef.h"
|
||
|
#include "winbase.h"
|
||
|
#include "winternl.h"
|
||
|
|
||
|
#include "wine/debug.h"
|
||
|
#include "unixlib.h"
|
||
|
|
||
|
WINE_DECLARE_DEBUG_CHANNEL(winediag);
|
||
|
|
||
|
static const struct pcap_callbacks *callbacks;
|
||
|
|
||
|
static void CDECL wrap_breakloop( void *handle )
|
||
|
{
|
||
|
return pcap_breakloop( handle );
|
||
|
}
|
||
|
|
||
|
static void CDECL wrap_close( void *handle )
|
||
|
{
|
||
|
pcap_close( handle );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_compile( void *handle, void *program, const char *buf, int optimize, unsigned int mask )
|
||
|
{
|
||
|
return pcap_compile( handle, program, buf, optimize, mask );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_datalink( void *handle )
|
||
|
{
|
||
|
return pcap_datalink( handle );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_datalink_name_to_val( const char *name )
|
||
|
{
|
||
|
return pcap_datalink_name_to_val( name );
|
||
|
}
|
||
|
|
||
|
static const char * CDECL wrap_datalink_val_to_description( int link )
|
||
|
{
|
||
|
return pcap_datalink_val_to_description( link );
|
||
|
}
|
||
|
|
||
|
static const char * CDECL wrap_datalink_val_to_name( int link )
|
||
|
{
|
||
|
return pcap_datalink_val_to_name( link );
|
||
|
}
|
||
|
|
||
|
void wrap_pcap_handler( unsigned char *user, const struct pcap_pkthdr *hdr, const unsigned char *packet )
|
||
|
{
|
||
|
struct handler_callback *cb = (struct handler_callback *)user;
|
||
|
callbacks->handler( cb, hdr, packet );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_dispatch( void *handle, int count,
|
||
|
void (CALLBACK *callback)(unsigned char *, const void *, const unsigned char *),
|
||
|
unsigned char *user )
|
||
|
{
|
||
|
if (callback)
|
||
|
{
|
||
|
struct handler_callback cb;
|
||
|
cb.callback = callback;
|
||
|
cb.user = user;
|
||
|
return pcap_dispatch( handle, count, wrap_pcap_handler, (unsigned char *)&cb );
|
||
|
}
|
||
|
return pcap_dispatch( handle, count, NULL, user );
|
||
|
}
|
||
|
|
||
|
static void CDECL wrap_dump( unsigned char *user, const void *hdr, const unsigned char *packet )
|
||
|
{
|
||
|
return pcap_dump( user, hdr, packet );
|
||
|
}
|
||
|
|
||
|
static void * CDECL wrap_dump_open( void *handle, const char *name )
|
||
|
{
|
||
|
return pcap_dump_open( handle, name );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_findalldevs( struct pcap_if_hdr **devs, char *errbuf )
|
||
|
{
|
||
|
int ret;
|
||
|
ret = pcap_findalldevs( (pcap_if_t **)devs, errbuf );
|
||
|
if (devs && !*devs)
|
||
|
ERR_(winediag)( "Failed to access raw network (pcap), this requires special permissions.\n" );
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
static void CDECL wrap_freealldevs( struct pcap_if_hdr *devs )
|
||
|
{
|
||
|
pcap_freealldevs( (pcap_if_t *)devs );
|
||
|
}
|
||
|
|
||
|
static void CDECL wrap_freecode( void *program )
|
||
|
{
|
||
|
return pcap_freecode( program );
|
||
|
}
|
||
|
|
||
|
static char * CDECL wrap_geterr( void *handle )
|
||
|
{
|
||
|
return pcap_geterr( handle );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_getnonblock( void *handle, char *errbuf )
|
||
|
{
|
||
|
return pcap_getnonblock( handle, errbuf );
|
||
|
}
|
||
|
|
||
|
static const char * CDECL wrap_lib_version( void )
|
||
|
{
|
||
|
return pcap_lib_version();
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_list_datalinks( void *handle, int **buf )
|
||
|
{
|
||
|
return pcap_list_datalinks( handle, buf );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_lookupnet( const char *device, unsigned int *net, unsigned int *mask, char *errbuf )
|
||
|
{
|
||
|
return pcap_lookupnet( device, net, mask, errbuf );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_loop( void *handle, int count,
|
||
|
void (CALLBACK *callback)(unsigned char *, const void *, const unsigned char *),
|
||
|
unsigned char *user )
|
||
|
{
|
||
|
if (callback)
|
||
|
{
|
||
|
struct handler_callback cb;
|
||
|
cb.callback = callback;
|
||
|
cb.user = user;
|
||
|
return pcap_loop( handle, count, wrap_pcap_handler, (unsigned char *)&cb );
|
||
|
}
|
||
|
return pcap_loop( handle, count, NULL, user );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_major_version( void *handle )
|
||
|
{
|
||
|
return pcap_major_version( handle );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_minor_version( void *handle )
|
||
|
{
|
||
|
return pcap_minor_version( handle );
|
||
|
}
|
||
|
|
||
|
static const unsigned char * CDECL wrap_next( void *handle, void *hdr )
|
||
|
{
|
||
|
return pcap_next( handle, hdr );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_next_ex( void *handle, void **hdr, const unsigned char **data )
|
||
|
{
|
||
|
return pcap_next_ex( handle, (struct pcap_pkthdr **)hdr, data );
|
||
|
}
|
||
|
|
||
|
static void * CDECL wrap_open_live( const char *source, int snaplen, int promisc, int to_ms, char *errbuf )
|
||
|
{
|
||
|
return pcap_open_live( source, snaplen, promisc, to_ms, errbuf );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_sendpacket( void *handle, const unsigned char *buf, int size )
|
||
|
{
|
||
|
return pcap_sendpacket( handle, buf, size );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_set_datalink( void *handle, int link )
|
||
|
{
|
||
|
return pcap_set_datalink( handle, link );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_setfilter( void *handle, void *program )
|
||
|
{
|
||
|
return pcap_setfilter( handle, program );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_setnonblock( void *handle, int nonblock, char *errbuf )
|
||
|
{
|
||
|
return pcap_setnonblock( handle, nonblock, errbuf );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_snapshot( void *handle )
|
||
|
{
|
||
|
return pcap_snapshot( handle );
|
||
|
}
|
||
|
|
||
|
static int CDECL wrap_stats( void *handle, void *stats )
|
||
|
{
|
||
|
return pcap_stats( handle, stats );
|
||
|
}
|
||
|
|
||
|
static const struct pcap_funcs funcs =
|
||
|
{
|
||
|
wrap_breakloop,
|
||
|
wrap_close,
|
||
|
wrap_compile,
|
||
|
wrap_datalink,
|
||
|
wrap_datalink_name_to_val,
|
||
|
wrap_datalink_val_to_description,
|
||
|
wrap_datalink_val_to_name,
|
||
|
wrap_dispatch,
|
||
|
wrap_dump,
|
||
|
wrap_dump_open,
|
||
|
wrap_findalldevs,
|
||
|
wrap_freealldevs,
|
||
|
wrap_freecode,
|
||
|
wrap_geterr,
|
||
|
wrap_getnonblock,
|
||
|
wrap_lib_version,
|
||
|
wrap_list_datalinks,
|
||
|
wrap_lookupnet,
|
||
|
wrap_loop,
|
||
|
wrap_major_version,
|
||
|
wrap_minor_version,
|
||
|
wrap_next,
|
||
|
wrap_next_ex,
|
||
|
wrap_open_live,
|
||
|
wrap_sendpacket,
|
||
|
wrap_set_datalink,
|
||
|
wrap_setfilter,
|
||
|
wrap_setnonblock,
|
||
|
wrap_snapshot,
|
||
|
wrap_stats,
|
||
|
};
|
||
|
|
||
|
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 */
|