[Winpcap-users] WinPCap in a winService

Alex Narinsky alex_narinsky at guardium.com
Sun Oct 2 20:22:01 GMT 2005


One will receive the error message exiting Windows service program if the program does not exit cleanly.  The program should release all threads. 

 

I use pcap_open_live in my Windows service program without a problem.  If you translate the message from Italian I think I can identify the problem easier.

 

Regards,

 

Alex


Alessandro Baldisserri <bujia at libero.it> wrote:Hi!

I'm developing an application based on winPCap that analyze web traffic. I thought to run this application like a winService. I use Visual C++ .NET. My application run very well like console application. Now I try to realize service. I put code that previously I had in "main" in the method "OnStart" of a class ServiceBase.
My code in OnStart is this:
---------------------------------------------------------------------------
if (pcap_findalldevs(&dev,errbuf) == -1) 
{
exit(1);
}
a=dev->addresses;
// Apertura del device per la cattura dei pacchetti
pcap_handler_p = pcap_open_live(dev->name,65536,0,1000,errbuf);
if (pcap_handler_p==NULL) 
{ 
//printf("Unable to open device ETH0!! \n");
exit(1);
}
sprintf(f,"not ((src net 192.168.1) and (dst net 192.168.1))");
// Compilazione filtro da applicare alla cattura dei pacchetti
cap_compile(pcap_handler_p,&filter,f,1,((struct sockaddr_in*)a->netmask)->sin_addr.S_un.S_addr); 
....
....
....


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

It seems that pcap_findalldevs returns a positive value,so all ok, but if flow of program run pcap_open_live when I activate service this is message:

IL SERVIZIO SU COMPUTER LOCALE SI è AVVIATO, QUINDI SI è INTERROTTO. ALCUNI SERVIZI SI INTERROMPONO AUTOMATICAMENTE SE NON VI SONO OPERAZIONI DA ESEGUIRE......

My question is: is a problem to put winPcap functions in a OnStart method of a Service? In this method I want to initialize my variables, open live capture session and so my service run...

Any help will be very useful...
Thanks in advance!
Alessandro





_______________________________________________
Winpcap-users mailing list
Winpcap-users at winpcap.org
https://www.winpcap.org/mailman/listinfo/winpcap-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winpcap.org/pipermail/winpcap-users/attachments/20051002/e99c4ff5/attachment-0001.htm


More information about the Winpcap-users mailing list