Hi.
 
I'm not completely sure, because I don't know how the C_Paquet constructor works, but I think that the problem is that you are storing the pointer returned in pkt_data into your C_Paquet class. Unfortunately, this pointer is valid only up to the next call to pcap_next_ex (or pcap_close). In practice, in order, to store the packets returned by pcap_next_ex, you must copy them into some buffer of your program.
 
Have a nice day
GV
 
----- Original Message -----
Sent: Monday, April 19, 2004 5:27 AM
Subject: [WinPcap-users] Problem to list packet with pcap_next_ex

Hello all,
First time I used this mailing list so hello all :)
I program a c++ software to capture network traffic and analyze it so Winpcap is very useful :)
But i got an issue with the pcap_next_ex function. I explain:
In my code i analyze the paket as soon as they arrived and it works fine. (i analyze pkt_data and prints the packet).
After that, i need to "construct" a Paquet Class with its packet_data and the number of the packet.
After having my packet, i add it into a list of packet and here is the issue. When i print my list after for example, 5 packets received, my list seems bugged, as if pkt_data was not correct.
Here is the code in C++:
//Code located into a thread to sniff while executing other commands in the main program
while((res = pcap_next_ex( adhandle, &header, &pkt_data)) >= 0){
 
        if(res == 0)
          {  /* Timeout elapsed */
          //continue;
         }
          else
          {
          if (res == -1)
                {
                }
                else
                {
               paquet = pkt_data;
               Paquet_courant = new C_Paquet (paquet, cpto);
              cpto ++;
Liste_Paque->Add((void*)Paquet_courant);
Synchronize (AfficherListe);
   
}
 
type of Liste_Paque is:  TList *Liste_Paque;
AfficherListe is a function to print list of packets.
 
When i print mypackets, it works fine for generally 3 or 4 packets and after, it prints unattended data....
 
So can u explain me how to store each packet into a list ?
I need this storage list because i use it in other capabilities of my program.
Any help will be appreciated.
Thanks a lot.
 

Reply via email to