Commit 67b95d4a authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

wpcap: Move pcap support to a new Unix library.

parent 7aba0e54
......@@ -3,6 +3,7 @@ DELAYIMPORTS = ws2_32
EXTRALIBS = $(PCAP_LIBS)
C_SRCS = \
unixlib.c \
wpcap.c
RC_SRCS = version.rc
/*
* 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 */
/*
* 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
*/
struct pcap_if_hdr
{
struct pcap_if_hdr *next;
char *name;
};
struct handler_callback
{
void (CALLBACK *callback)( unsigned char *, const void *, const unsigned char * );
void *user;
};
struct pcap_funcs
{
void (CDECL *breakloop)( void * );
void (CDECL *close)( void * );
int (CDECL *compile)( void *, void *, const char *, int, unsigned int );
int (CDECL *datalink)( void * );
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)( void *, int, void (CALLBACK *)(unsigned char *, const void *, const unsigned char *),
unsigned char * );
void (CDECL *dump)( unsigned char *, const void *, const unsigned char * );
void * (CDECL *dump_open)( void *, const char * );
int (CDECL *findalldevs)( struct pcap_if_hdr **, char * );
void (CDECL *freealldevs)( struct pcap_if_hdr * );
void (CDECL *freecode)( void * );
char * (CDECL *geterr)( void * );
int (CDECL *getnonblock)( void *, char * );
const char * (CDECL *lib_version)( void );
int (CDECL *list_datalinks)( void *, int ** );
int (CDECL *lookupnet)( const char *, unsigned int *, unsigned int *, char * );
int (CDECL *loop)( void *, int, void (CALLBACK *)(unsigned char *, const void *, const unsigned char *),
unsigned char * );
int (CDECL *major_version)( void * );
int (CDECL *minor_version)( void * );
const unsigned char * (CDECL *next)( void *, void * );
int (CDECL *next_ex)( void *, void **, const unsigned char ** );
void * (CDECL *open_live)( const char *, int, int, int, char * );
int (CDECL *sendpacket)( void *, const unsigned char *, int );
int (CDECL *set_datalink)( void *, int );
int (CDECL *setfilter)( void *, void * );
int (CDECL *setnonblock)( void *, int, char * );
int (CDECL *snapshot)( void * );
int (CDECL *stats)( void *, void * );
};
struct pcap_callbacks
{
void (CDECL *handler)( struct handler_callback *, const void *, const unsigned char * );
};
......@@ -75,4 +75,4 @@
@ cdecl pcap_stats(ptr ptr) wine_pcap_stats
@ stub pcap_stats_ex
@ cdecl pcap_strerror(long) msvcrt.strerror
@ cdecl wsockinit() wine_wsockinit
@ cdecl wsockinit()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment