[Winpcap-users] Various fixups

Gianluca Varenni gianluca.varenni at cacetech.com
Mon Jan 16 03:55:49 GMT 2006


Hi.

I played a bit with the patch you sent, with the following outcome:
- the modified files seem to compile smoothly both with GCC and Visual C 6 
(used normally to compile the WinPcap DLLs)
- due to licensing issues (or better, lack of), I cannot use the 
gai_strerror.c file you sent, which is probably taken out of the Microsoft 
include file WS2tcpip.h. I took an implementation of that function from the 
freeBSD source code (we do the same for other functions in 
wpcap\libpcap\Win32\Src) and modified some bits to make it compile.
- regarding the weird patch for struct bpf_stat, it's a problem related to a 
duplicated definition of that structure in multiple include files, for which 
a quite ugly #ifdef was added years ago in packet32.h (i.e. it's not a 
problem with MingW per se). In any case, an easy and safe patch to the 
problem is to add a forward declaration of struct bpf_stat inside packet32.h 
(since the function declarations in this file only use a pointer to this 
struct). Any other patch for this issue involved adding some #ifdef's here 
and there in various include files (and this could cause side effects that 
I'd prefer to avoid).
- in the GNU makefile for packet.dll, it's not necessary to define 
HAVE_REMOTE (since the remote stuff is implemented in wpcap.dll)

All these things have been tested with Cygwin, which should be quite similar 
to MingW. In any case, attached you can find an updated patch file against 
WinPcap 3.2a1. The new gai_strerror.c file is included in the patch file. 
Can you please test it with MingW and tell me if it works?

To apply the patch, go into the "winpcap" folder, then type "patch -p1 < 
[path_to_the_diff_file]".

Have a nice day
GV

PS: thanks for the hard work!!


----- Original Message ----- 
From: "deadchicken" <deadchicken at gmail.com>
To: <winpcap-users at winpcap.org>
Sent: Thursday, January 12, 2006 2:03 PM
Subject: Re: [Winpcap-users] Various fixups


> Attached is the unified diff and the missing file which should end up as:
> winpcap\wpcap\libpcap\Win32\Src\gai_strerror.c
>
> Gianluca Varenni wrote:
>> Hi
>>
>> I'll try to apply the patches during the weekend.
>>
>> Next time, I suggest you to use "diff -U"  (unified diff), which gives a
>> bit of context in the diff and helps patching the files when they have
>> been slightly modified, perform a single diff for all the modifications
>> (diff -Ur), and send it as an attachment...
>> Basically I'll need to copy and paste every single diff you sent into a
>> text file, and apply it to the proper destination file.
>>
>> In any case, don't worry, we all learn how to use these (nasty?) tools
>> day by day :-))
>>
>> Have a nice day
>> GV
>>
>> ----- Original Message ----- From: "deadchicken" <deadchicken at gmail.com>
>> To: <winpcap-users at winpcap.org>
>> Sent: Tuesday, January 10, 2006 8:32 PM
>> Subject: Re: [Winpcap-users] Various fixups
>>
>>
>>> Hopefully this will work better than the last time...
>>>
>>> -----
>>>
>>> The following is an update of my attempts to get WinPcap and it's
>>> examples to
>>> compile under MingW. These changes were applied to a fresh copy of
>>> wpcapsrc_3_2_alpha1 and then diff'd against the original. Testing
>>> involved
>>> simply compiling the library, then compiling the packet utility I've 
>>> been
>>> working on, then running it to see if it worked. I have little 
>>> experience
>>> with submitting changes to community edited source code so please bear
>>> with me.
>>>
>>> The first diff adjusts one of the makefiles by adding HAVE_REMOTE and
>>> changing
>>> the winsock library:
>>>
>>> diff -r -d
>>> wpcapsrc_3_2_alpha1/winpcap/packetNtx/Dll/Project/GNUmakefile
>>> wpcapsrc_3_2_alpha1_mingw/winpcap/packetNtx/Dll/Project/GNUmakefile
>>> 5c5
>>> < OPTFLAGS = -O -D_WINNT4
>>> ---
>>>> OPTFLAGS = -O -D_WINNT4 -DHAVE_REMOTE
>>> 11c11
>>> < LIBS = -lwsock32 -lversion
>>> ---
>>>> LIBS = -lws2_32 -lversion
>>>
>>>
>>> Then I copied the bpf_stat structure. It originates in Packet32.h.
>>> BPF_MAJOR_VERSION is defined which then prevents bpf_stat from being
>>> defined.
>>> It appears that this sort of behavior has been run into before since
>>> bpf_insn
>>> appears in two places. So I've copied bpf_stat in a similiar manner.
>>> Probably
>>> not a good fix, but it works.
>>>
>>> diff -r -d wpcapsrc_3_2_alpha1/winpcap/wpcap/libpcap/pcap-bpf.h
>>> wpcapsrc_3_2_alpha1_mingw/winpcap/wpcap/libpcap/pcap-bpf.h
>>> 673a674,683
>>>> #ifdef __MINGW32__
>>>> struct bpf_stat
>>>> {
>>>>  UINT bs_recv;
>>>>  UINT bs_drop;
>>>>  UINT ps_ifdrop;
>>>>  UINT bs_capt;
>>>> };
>>>> #endif
>>>>
>>>
>>>
>>> The next diff adds some things to work around a bug in the MinW32 
>>> headers
>>> regarding getnameinfo():
>>>
>>> diff -r -d wpcapsrc_3_2_alpha1/winpcap/wpcap/libpcap/sockutils.h
>>> wpcapsrc_3_2_alpha1_mingw/winpcap/wpcap/libpcap/sockutils.h
>>> 48a49,52
>>>> /* Need windef.h for defines used in winsock2.h under MingW32 */
>>>> #ifdef __MINGW32__
>>>> #include <windef.h>
>>>> #endif
>>> 64a69,77
>>>> /* MingW headers include this definition, but only for Windows XP and
>>>> above.
>>>>    MSDN states that this function is available for most versions on
>>>> Windows.
>>>> */
>>>> #if ((defined(__MINGW32__)) && (_WIN32_WINNT < 0x0501))
>>>> int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD,
>>>>          char*,DWORD,int);
>>>> #endif
>>>>
>>>>
>>>
>>>
>>> Next is a change to fix a warning regarding the IN_MULTICAST define:
>>>
>>> diff -r -d
>>> wpcapsrc_3_2_alpha1/winpcap/wpcap/libpcap/Win32/Include/ip6_misc.h
>>> wpcapsrc_3_2_alpha1_mingw/winpcap/wpcap/libpcap/Win32/Include/ip6_misc.h
>>> 33a34
>>>> #ifndef __MINGW32__
>>> 34a36
>>>> #endif
>>>
>>>
>>> The next diff is the same as the previous GNUmakefile diff with some
>>> syntax
>>> changes added:
>>>
>>> diff -r -d wpcapsrc_3_2_alpha1/winpcap/wpcap/PRJ/GNUmakefile
>>> wpcapsrc_3_2_alpha1_mingw/winpcap/wpcap/PRJ/GNUmakefile
>>> 17,18c17,18
>>> < LEX = flex -Ppcap_
>>> < YACC = bison -y -p pcap_
>>> ---
>>>> LFLAGS = -Ppcap_
>>>> YFLAGS = -y -p pcap_
>>> 30a31
>>>>  -DHAVE_REMOTE \
>>> 33c34
>>> < LIBS = -L ../../${PACKET_DIR}/DLL/Project -lPacket -lwsock32
>>> ---
>>>> LIBS = -L ../../${PACKET_DIR}/DLL/Project -lPacket -lws2_32
>>> 55a57,60
>>>>  ../libpcap/pcap-new.o \
>>>>  ../libpcap/pcap-remote.o \
>>>>  ../libpcap/sockutils.o \
>>>>  ../libpcap/Win32/Src/gai_strerror.o \
>>> 59c64
>>> <  ${CC} ${CFLAGS} ${LDFLAGS} -o wpcap.dll wpcap_no_extensions.def
>>> ${OBJS} ${LIBS}
>>> ---
>>>>  ${CC} ${CFLAGS} ${LDFLAGS} -o wpcap.dll wpcap.def ${OBJS} ${LIBS}
>>> 65c70
>>> <  rm -f ${OBJS} ../libpcap/scanner.c ../libpcap/grammar.c wpcap.a
>>> wpcap.dll
>>> ---
>>>>  ${RM} ${OBJS} ../libpcap/scanner.c ../libpcap/grammar.c wpcap.a
>>>> wpcap.dll
>>> 71,72c76,77
>>> <  @rm -f ../libpcap/grammar.c ../libpcap/tokdefs.h
>>> <  $(YACC) -d $<
>>> ---
>>>>  @${RM} ../libpcap/grammar.c ../libpcap/tokdefs.h
>>>>  ${YACC} ${YFLAGS} -d $<
>>> 76,77c81,82
>>> <  @rm -f $@<  $(LEX) -t $< >$*.c
>>> ---
>>>>  @${RM} $@>  ${LEX} ${LFLAGS} -t $< >$*.c
>>>
>>>
>>> These seem to be all the changes necessary to get it working on my
>>> computer.
>>> Some further private changes not included in the above involved
>>> dealing with mv
>>> and cp since I use the XP CLI rather than MSYS or cygwin's shell.
>>> Additionally,
>>> I had to remember to set CC, RM, YACC, LEX, and BISON_SIMPLE in my
>>> environment
>>> variables, something that those familiar with makefiles probably
>>> already know to
>>> do. I got flex and bison for Windows from:
>>>
>>> http://www.monmouth.com/~wstreett/lex-yacc/lex-yacc.html
>>>
>>> I got diff for Windows from:
>>>
>>> http://gnuwin32.sourceforge.net/packages/diffutils.htm
>>>
>>> My environment variables were:
>>>
>>> CC=gcc
>>> RM=del
>>> YACC=bison
>>> LEX=flex
>>> BISON_SIMPLE=J:\lex-yacc\bison.simple
>>>
>>>
>>> ----- Original Message -----
>>> From: Gianluca Varenni
>>> To: ouroborus at softhome.net
>>> Sent: Thursday, January 05, 2006 9:02 AM
>>> Subject: Re: [Winpcap-users] Various fixups
>>>
>>>
>>> Hi.
>>>
>>> Sorry for the late reply...
>>>
>>> Do you have any update to these patches? I can probably find some time
>>> in the
>>> next week or so to try applying these patches to main source tree, it
>>> we can
>>> succeed in making it compile under Cygwin/MingW without breaking any
>>> license.
>>>
>>> Happy new year
>>> GV
>>>
>>> _______________________________________________
>>> Winpcap-users mailing list
>>> Winpcap-users at winpcap.org
>>> https://www.winpcap.org/mailman/listinfo/winpcap-users
>>>
>>
>> _______________________________________________
>> Winpcap-users mailing list
>> Winpcap-users at winpcap.org
>> https://www.winpcap.org/mailman/listinfo/winpcap-users
>>
>


--------------------------------------------------------------------------------


> diff -ru wpcapsrc_3_2_alpha1/winpcap/packetNtx/Dll/Project/GNUmakefile 
> wpcapsrc_3_2_alpha1_mingw/winpcap/packetNtx/Dll/Project/GNUmakefile
> --- wpcapsrc_3_2_alpha1/winpcap/packetNtx/Dll/Project/GNUmakefile 
> 2004-01-13 01:15:24.000000000 -0800
> +++ wpcapsrc_3_2_alpha1_mingw/winpcap/packetNtx/Dll/Project/GNUmakefile 
> 2006-01-12 13:27:29.334250000 -0800
> @@ -2,13 +2,13 @@
> # Nate Lawson <nate at rootlabs.com>
>
> # OPTFLAGS = -g -DDBG
> -OPTFLAGS = -O -D_WINNT4
> +OPTFLAGS = -O -D_WINNT4 -DHAVE_REMOTE
> # I am suspicious of -O2 since it hosed wpcap.dll. To be safe, use -O only
>
> CFLAGS = -I ../../../common -shared -mno-cygwin ${OPTFLAGS}
> LDFLAGS = -Wl,--out-implib,libpacket.a
> OBJS = ../Packet32.o ../AdInfo.o
> -LIBS = -lwsock32 -lversion
> +LIBS = -lws2_32 -lversion
>
> Packet.dll: ${OBJS}
>  ${CC} ${CFLAGS} ${LDFLAGS} -o Packet.dll ../Packet.def ${OBJS} ${LIBS}
> @@ -17,7 +17,7 @@
>  ${CC} ${CFLAGS} -o $*.o -c $<
>
> clean:
> - rm -f ${OBJS} libpacket.a Packet.dll
> + ${RM} ${OBJS} libpacket.a Packet.dll
>
> install: Packet.dll
>  cp Packet.dll c:/winnt/system32
> diff -ru wpcapsrc_3_2_alpha1/winpcap/wpcap/libpcap/pcap-bpf.h 
> wpcapsrc_3_2_alpha1_mingw/winpcap/wpcap/libpcap/pcap-bpf.h
> --- wpcapsrc_3_2_alpha1/winpcap/wpcap/libpcap/pcap-bpf.h 2005-08-13 
> 15:29:48.000000000 -0700
> +++ wpcapsrc_3_2_alpha1_mingw/winpcap/wpcap/libpcap/pcap-bpf.h 2006-01-10 
> 14:50:30.070000000 -0800
> @@ -671,6 +671,16 @@
>  bpf_int32 k;
> };
>
> +#ifdef __MINGW32__
> +struct bpf_stat
> +{
> + UINT bs_recv;
> + UINT bs_drop;
> + UINT ps_ifdrop;
> + UINT bs_capt;
> +};
> +#endif
> +
> /*
>  * Macros for insn array initializers.
>  */
> diff -ru wpcapsrc_3_2_alpha1/winpcap/wpcap/libpcap/sockutils.h 
> wpcapsrc_3_2_alpha1_mingw/winpcap/wpcap/libpcap/sockutils.h
> --- wpcapsrc_3_2_alpha1/winpcap/wpcap/libpcap/sockutils.h 2003-12-05 
> 00:00:16.000000000 -0800
> +++ wpcapsrc_3_2_alpha1_mingw/winpcap/wpcap/libpcap/sockutils.h 2006-01-10 
> 13:20:24.982750000 -0800
> @@ -46,6 +46,10 @@
> #ifdef _WINSOCKAPI_
> #undef _WINSOCKAPI_
> #endif
> +/* Need windef.h for defines used in winsock2.h under MingW32 */
> +#ifdef __MINGW32__
> +#include <windef.h>
> +#endif
> #include <winsock2.h>
> #include <ws2tcpip.h>
> #else
> @@ -62,6 +66,15 @@
> #endif
>
>
> +/* MingW headers include this definition, but only for Windows XP and 
> above.
> +   MSDN states that this function is available for most versions on 
> Windows.
> +*/
> +#if ((defined(__MINGW32__)) && (_WIN32_WINNT < 0x0501))
> +int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD,
> +        char*,DWORD,int);
> +#endif
> +
> +
> /*!
>  \defgroup SockUtils Cross-platform socket utilities (IPv4-IPv6)
> */
> diff -ru 
> wpcapsrc_3_2_alpha1/winpcap/wpcap/libpcap/Win32/Include/ip6_misc.h 
> wpcapsrc_3_2_alpha1_mingw/winpcap/wpcap/libpcap/Win32/Include/ip6_misc.h
> --- wpcapsrc_3_2_alpha1/winpcap/wpcap/libpcap/Win32/Include/ip6_misc.h 
> 2004-07-06 16:45:30.000000000 -0700
> +++ 
> wpcapsrc_3_2_alpha1_mingw/winpcap/wpcap/libpcap/Win32/Include/ip6_misc.h 
> 2006-01-10 13:31:06.310875000 -0800
> @@ -31,7 +31,9 @@
> #include <ws2tcpip.h>
> #endif /* __MINGW32__ */
>
> +#ifndef __MINGW32__
> #define IN_MULTICAST(a) IN_CLASSD(a)
> +#endif
>
> #define IN_EXPERIMENTAL(a) ((((u_int32_t) (a)) & 0xf0000000) == 
> 0xf0000000)
>
> diff -ru wpcapsrc_3_2_alpha1/winpcap/wpcap/PRJ/GNUmakefile 
> wpcapsrc_3_2_alpha1_mingw/winpcap/wpcap/PRJ/GNUmakefile
> --- wpcapsrc_3_2_alpha1/winpcap/wpcap/PRJ/GNUmakefile 2005-07-12 
> 21:38:38.000000000 -0700
> +++ wpcapsrc_3_2_alpha1_mingw/winpcap/wpcap/PRJ/GNUmakefile 2006-01-10 
> 13:32:49.467125000 -0800
> @@ -14,8 +14,8 @@
> # used by the generated parser.  This allows programs to use lex/yacc
> # and link against libpcap.  If you don't have flex or bison, get them.
> #
> -LEX = flex -Ppcap_
> -YACC = bison -y -p pcap_
> +LFLAGS = -Ppcap_
> +YFLAGS = -y -p pcap_
>
> PACKET_DIR = packetNTx
> INSTALL_DIR = ${SYSTEMROOT}\system32
> @@ -28,9 +28,10 @@
>  -DSIZEOF_CHAR=1 -DSIZEOF_SHORT=2 -DSIZEOF_INT=4 -DSIZEOF_LONG_LONG=8 -DWPCAP 
>  -D'_U_=' \
>  -DHAVE_SNPRINTF -DHAVE_VSNPRINTF \
>  -DSIZEOF_LONG_LONG=8 \
> + -DHAVE_REMOTE \
>  -mno-cygwin -shared ${OPTFLAGS}
> LDFLAGS = -Wl,--out-implib,../lib/libwpcap.a
> -LIBS = -L ../../${PACKET_DIR}/DLL/Project -lPacket -lwsock32
> +LIBS = -L ../../${PACKET_DIR}/DLL/Project -lPacket -lws2_32
> OBJS = ../libpcap/bpf/net/bpf_filter.o \
>  ../libpcap/bpf_dump.o \
>  ../libpcap/bpf_image.o \
> @@ -53,27 +54,31 @@
>  ../libpcap/pcap.o \
>  ../libpcap/savefile.o \
>  ../libpcap/scanner.o \
> + ../libpcap/pcap-new.o \
> + ../libpcap/pcap-remote.o \
> + ../libpcap/sockutils.o \
> + ../libpcap/Win32/Src/gai_strerror.o \
>  ../Win32-Extensions/Win32-Extensions.o
>
> main: ${OBJS}
> - ${CC} ${CFLAGS} ${LDFLAGS} -o wpcap.dll wpcap_no_extensions.def ${OBJS} 
> ${LIBS}
> + ${CC} ${CFLAGS} ${LDFLAGS} -o wpcap.dll wpcap.def ${OBJS} ${LIBS}
>
> install:
>  cp wpcap.dll ${INSTALL_DIR}
>
> clean:
> - rm -f ${OBJS} ../libpcap/scanner.c ../libpcap/grammar.c wpcap.a 
> wpcap.dll
> + ${RM} ${OBJS} ../libpcap/scanner.c ../libpcap/grammar.c wpcap.a 
> wpcap.dll
>
> # Keeps intermediate .c files from being deleted
> .SECONDARY: ../libpcap/scanner.c ../libpcap/grammar.c
>
> .y.c:
> - @rm -f ../libpcap/grammar.c ../libpcap/tokdefs.h
> - $(YACC) -d $<
> + @${RM} ../libpcap/grammar.c ../libpcap/tokdefs.h
> + ${YACC} ${YFLAGS} -d $<
>  mv y.tab.c ../libpcap/grammar.c
>  mv y.tab.h ../libpcap/tokdefs.h
> .l.c:
> - @rm -f $@
> - $(LEX) -t $< >$*.c
> + @${RM} $@
> + ${LEX} ${LFLAGS} -t $< >$*.c
> .c.o:
>  ${CC} ${CFLAGS} -o $*.o -c $<
>


--------------------------------------------------------------------------------


> _______________________________________________
> Winpcap-users mailing list
> Winpcap-users at winpcap.org
> https://www.winpcap.org/mailman/listinfo/winpcap-users
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wpcapsrc_3_2_newpatch.diff
Type: application/octet-stream
Size: 8093 bytes
Desc: not available
Url : http://www.winpcap.org/pipermail/winpcap-users/attachments/20060115/9d80db78/wpcapsrc_3_2_newpatch-0001.obj


More information about the Winpcap-users mailing list