[Winpcap-users] WinPCap in a winService

Alex Narinsky alex_narinsky at guardium.com
Mon Oct 3 19:31:45 GMT 2005


I have never seen this message while working on my Windows service that
uses winpcap, sorry.  Just in case, I am using the Windows SDK example
for creating the service

Regards,
Alex

-----Original Message-----
From: winpcap-users-bounces at winpcap.org
[mailto:winpcap-users-bounces at winpcap.org] On Behalf Of Alessandro
Baldisserri
Sent: Monday, October 03, 2005 2:45 AM
To: winpcap-users
Subject: Re: [Winpcap-users] WinPCap in a winService

Sorry for Italian message....
Me too want to use pcap_open_live in WinService, and obvoiusly I want it
in OnStart method.
The message:

SERVICE ON LOCAL COMPUTER IS STARTED, THEN IS STOPPED. SOME SERVICES
STOP ITSELF AUTOMATICALLY IF THEY AREN'T TASK TO EXECUTE...

Obviously next in my OnStart code I attach pcap_handler to a function
callback called any time a packet was captured, but it seems that flow
of my program doesn't arrive in tha point...
I put also a definition of a Timer before code that I post below, but
nothing.
If I put a "return;" on method OnStart between pcap_findalldevs e
pcap_open_live service run correctly and start, but obviously nothing is
ok....my service in this way is no useful....

Sorry for my very bad English.... I hope you understand where is the
problem....

Thanks!
Alessandro




---------- Initial Header -----------

>From      : winpcap-users-bounces at winpcap.org
To          : winpcap-users at winpcap.org
Cc          : 
Date      : Sun, 2 Oct 2005 13:22:01 -0700 (PDT)
Subject : Re: [Winpcap-users] WinPCap in a winService







> 
> 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
> 
> 


_______________________________________________
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