[PATCH 1/2] wpcap: Implement pcap_dump_open and pcap_dump(try 3)

Sebastian Lackner sebastian at fds-team.de
Thu Feb 11 23:50:21 CST 2016


On 12.02.2016 06:31, Jianqiu Zhang wrote:
> From ba4fa665f40975587c8aeb132f853afa4c28b4ca Mon Sep 17 00:00:00 2001
> From: Jianqiu Zhang <zhangjianqiu_133 at yeah.net>
> Date: Thu, 29 Oct 2015 15:33:28 +0800
> Subject: [PATCH 1/2] wpcap: Implement pcap_dump_open and pcap_dump
> 
> Signed-off-by: Jianqiu Zhang <zhangjianqiu_133 at yeah.net>
> ---
>  dlls/wpcap/wpcap.c    | 43 +++++++++++++++++++++++++++++++++++++++++++
>  dlls/wpcap/wpcap.spec |  4 ++--
>  2 files changed, 45 insertions(+), 2 deletions(-)
> 
> diff --git a/dlls/wpcap/wpcap.c b/dlls/wpcap/wpcap.c
> index ae9e482..074c495 100644
> --- a/dlls/wpcap/wpcap.c
> +++ b/dlls/wpcap/wpcap.c
> @@ -22,6 +22,8 @@
>  #include "winsock2.h"
>  #include "windef.h"
>  #include "winbase.h"
> +#include "winternl.h"
> +#include "ntstatus.h"

As you already found out, this leads to build failures / warnings.
You have to include "ntstatus.h" in the beginning, and then

#define WIN32_NO_STATUS

to avoid the duplicate definitions from other files.

>  #include "wine/debug.h"
>  
>  WINE_DEFAULT_DEBUG_CHANNEL(wpcap);
> @@ -339,3 +341,44 @@ int CDECL wine_wsockinit(void)
>      if (WSAStartup(MAKEWORD(1,1), &wsadata)) return -1;
>      return 0;
>  }
> +

The code below should be technically fine, so it depends on André if its acceptable
as-is or if more cleanup is necessary. I would like to point out a couple more opportunities
to make it easier to read.

> +pcap_dumper_t* CDECL wine_pcap_dump_open(pcap_t *p, const char *fname)
> +{
> +    UNICODE_STRING nt_name, dospathW;

With more consistent variable names it would be easier to recognize W and ansi strings.

> +    ANSI_STRING fname_dos;
> +    ANSI_STRING fname_unix;

This could go into a single line.

> +    pcap_dumper_t *dumper_data;
> +    NTSTATUS status;
> +    TRACE("(%p %s)\n", p, fname);

Some linebreaks in front and after the TRACE would not hurt, to make it more readable.

> +    RtlInitAnsiString(&fname_dos, fname);
> +    status = RtlAnsiStringToUnicodeString(&dospathW, &fname_dos, TRUE);
> +    if (status)
> +    {
> +        SetLastError(RtlNtStatusToDosError(status));
> +        return NULL;
> +    }
> +    if (!RtlDosPathNameToNtPathName_U(dospathW.Buffer, &nt_name, NULL, NULL))
> +    {
> +        RtlFreeUnicodeString(&dospathW);
> +        SetLastError(ERROR_PATH_NOT_FOUND);
> +        return NULL;
> +    }
> +    status = wine_nt_to_unix_file_name(&nt_name, &fname_unix, FILE_OPEN_IF, FALSE);

You can move the RtlFreeUnicodeString(.) functions here to avoid code duplication.

> +    if (status && status != STATUS_NO_SUCH_FILE)
> +    {
> +        RtlFreeUnicodeString(&dospathW);
> +        RtlFreeUnicodeString(&nt_name);
> +        SetLastError(RtlNtStatusToDosError(status));
> +        return NULL;
> +    }
> +    RtlFreeUnicodeString(&nt_name);
> +    RtlFreeUnicodeString(&dospathW);
> +    dumper_data = pcap_dump_open(p, fname_unix.Buffer);
> +    RtlFreeAnsiString(&fname_unix);
> +    return dumper_data;
> +}
> +
> +void CDECL wine_pcap_dump(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
> +{
> +    return pcap_dump(user, h, sp);
> +}
> diff --git a/dlls/wpcap/wpcap.spec b/dlls/wpcap/wpcap.spec
> index 66303b4..541fc49 100644
> --- a/dlls/wpcap/wpcap.spec
> +++ b/dlls/wpcap/wpcap.spec
> @@ -16,12 +16,12 @@
>  @ cdecl pcap_datalink_val_to_description(long) wine_pcap_datalink_val_to_description
>  @ cdecl pcap_datalink_val_to_name(long) wine_pcap_datalink_val_to_name
>  @ cdecl pcap_dispatch(ptr long ptr ptr) wine_pcap_dispatch
> -@ stub pcap_dump
> +@ cdecl pcap_dump(ptr ptr ptr) wine_pcap_dump
>  @ stub pcap_dump_close
>  @ stub pcap_dump_file
>  @ stub pcap_dump_flush
>  @ stub pcap_dump_ftell
> -@ stub pcap_dump_open
> +@ cdecl pcap_dump_open(ptr str) wine_pcap_dump_open
>  @ stub pcap_file
>  @ stub pcap_fileno
>  @ cdecl pcap_findalldevs(ptr ptr) wine_pcap_findalldevs
> 
> 
> 
> 




More information about the wine-devel mailing list