[Winpcap-users] How can I get Packet statistic using winpcap

Gianluca Varenni gianluca.varenni at cacetech.com
Sun Mar 12 17:34:23 GMT 2006


----- Original Message ----- 
From: "Isara Anantavrasilp" <isara.a at gmail.com>
To: <winpcap-users at winpcap.org>
Sent: Monday, March 06, 2006 5:24 AM
Subject: Re: [Winpcap-users] How can I get Packet statistic using winpcap


I also had problem with dispatcher function.

I dont really understand your question but I think you have the
problem of linking the objects.

If you write your program in OOP style (i.e. C++ style), you cannot
use dispatcher function.
Somehow VC++ does have problem with callback function and gives LINK
ERROR when you compile the program.

--GV--
There are two "issues" with callback functions from within a C++ 
application:
1. the callback cannot be an instance method of a class. This is because in 
practice an instance method is nothing more that a normal C function 
receiving "this" as the first parameter (this is not exactly true for 
virtual methods).
2. usually C and C++ use different naming decoration schemes. The result is 
the usual (well, usual for me...) linking errors like "unresolved external 
_somefunction bla bla bla" but the same function should be there.
--GV--

The solution that I found (which might not be optimal) is that to
declare dispatcher_handler to global function.
That is, it should not belong to any class. Then you can compile the 
program.
(pcap_loop, however, can be called within a class member.)

--GV--
The solution I usually adopt is to use a static method of my class that 
invokes a normal instance method of the class. Something like

class foo
{
    .....
    static int DispatcherStatic(LPVOID pParam);
    int Dispatcher();
    ....
}

int foo:DispatcherStatic(LPVOID pParam)
{
    foo* lpThis = (foo*)pParam;
    return lpThis->Dispatcher();
}

int foo:Dispatcher()
{
    // this does the real job
}

Hope it helps
GV



-- BiGGA

On 2/7/06, Gianluca Varenni <gianluca.varenni at cacetech.com> wrote:
> Uhm, I don't understand precisely your question.
>
> Basically you need to define a callback (the dispatcher handler) that gets
> called with new statistics by pcap_loop. Alternatively, if you want to 
> avoid
> the use of a callback, you can also use pcap_next_ex to retrieve the
> statistics directly.
>
> If you send a *small* snippet of your code on the ML, maybe we can help 
> you
> better.
>
> Have a nice day
> GV
>
> ----- Original Message -----
> From: "jack chotikapakorn" <de_untouchable at hotmail.com>
> To: <winpcap-users at winpcap.org>
> Sent: Saturday, February 04, 2006 6:37 AM
> Subject: [Winpcap-users] How can I get Packet statistic using winpcap
>
>
> >I had read "Gathering Statistics on the network traffic" and I want to 
> >use
> >this code to my program (VC++.NET)that write by using OOP, and pcap_loop
> >function not know about "dispatcher_handler" is not pcap_handler Please
> >Help me !!!  also you can Example coding for me please . I'm not good in
> >c++ programming.
> >
> > thanks a lot
> >
> > _________________________________________________________________
> > Express yourself instantly with MSN Messenger! Download today - it's 
> > FREE!
> > http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
> >
> > _______________________________________________
> > 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
>

_______________________________________________
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