[Winpcap-users] Problems with Tutorial "Filtering the traffic"
Gianluca Varenni
gianluca.varenni at cacetech.com
Thu Mar 16 15:26:41 GMT 2006
----- Original Message -----
From: "Guy Harris" <guy at alum.mit.edu>
To: <winpcap-users at winpcap.org>
Sent: Wednesday, March 15, 2006 12:55 PM
Subject: Re: [Winpcap-users] Problems with Tutorial "Filtering the traffic"
> Gianluca Varenni wrote:
>> Uhm, the error tells me you are writing a managed c++ application (BTW, a
>> managed C++ MFC application, quite interesting).
>> I suggest you to read this FAQ
>> http://www.winpcap.org/misc/faq.htm#Q-29
>
> ...
>
>> The problem is due to the fact that the standard winpcap include file
>> "pcap.h" contains only a forward declaration of "struct pcap", but not
> > the actual definition of it. As a consequence, the Managed C++
> > compiler does not emit any metadata for that type, since there's no
> > definition for it.
>>
>> There are two solutions to the problem:
>>
> >
>> 1. Include "pcap-int.h" instead of "pcap.h". This include the
> > actual definition for the type "struct pcap"
> >
>> 2. Add a fake definition of "struct pcap". The simplest one is
> > "struct pcap{};".
>
> Managed C++ requires extra work for opaque structures? Sigh....
Well, managed C++ is not exactly "C++"... it has its own extensions to
supported the managed types of the CLR (and its limits).
>
> Is there some sort of #ifdef so that pcap.h could do "struct pcap{};" in
> Managed C++ and "struct pcap;" in C and "unmanaged" C++? (Does C++
> support opaque structures in that fashion? If so, why doesn't Managed C++
> do so? "We don't care, we don't have to - we're Microsoft"?)
Well, WinPcap/libpcap was not born to be used in Managed C++, I'm not too
much inclined at the moment in adding such an #ifdef to the main libpcap
include file (pcap.h) for this issue. Regarding "why didn't Microsoft do
that in MC++?" I don't know at all, but I'm pretty sure there is a reason
for this behavior. Just to give you one: if you *don't* have the "struct
pcap{}" declaration, you cannot declare a variable of that type (i.e.
"struct pcap foo;" is not allowed), you can only declare pointers to that
structure. If you add the fake declaration, you can declare a variable (i.e.
"struct pcap foo;" is compiled), *but* the structure is completely *wrong*
(since the size of foo is not the actual size of "struct pcap" as defined in
pcap_int.h). I'm not trying to defend Microsoft, just observing that maybe
that was a good (or not so good) reason for this.
Have a nice day
GV
>
> _______________________________________________
> Winpcap-users mailing list
> Winpcap-users at winpcap.org
> https://www.winpcap.org/mailman/listinfo/winpcap-users
>
More information about the Winpcap-users
mailing list