[Winpcap-users] WinPCap in a winService
Alessandro Baldisserri
bujia at libero.it
Sun Oct 2 09:31:46 GMT 2005
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
More information about the Winpcap-users
mailing list