[Winpcap-users] Re: linked list problem urgent help needed!

David Chang dchang at fsautomation.com
Mon Apr 24 22:29:30 GMT 2006


Steve,

If your struct declaration is

> typedef struct packet{
>                int packet_number;
>                struct pcap_pkthdr *pkt_header; //points to the header of a 
> packet
>                const u_char *pkt_data; //packet data
>                struct packet *next; //pointer to next node in list
> } packet;

Then, you've only allocated space for a 4 byte pointer.

The declaration should read:

typedef struct packet{
               int packet_number;
               struct pcap_pkthdr pkt_header; //points to the header of a 
packet
               const u_char *pkt_data; //packet data
               struct packet *next; //pointer to next node in list
} packet;

That is, without the pointer (*) in front of pkt_header.  Then a full 16 
bytes for the struct pcap_pkthdr will be allocated.
If you then assign to the pkt_header struct element, the entire 16 bytes of 
the struct gets copied.

OR, the better approach is to keep your current struct declaration and use a 
malloc() and memcpy().

For example:

tmp_ptr = malloc(sizeof(struct pcap_pkthdr)); /* Or use the C++ 'new' 
construct */
if (tmp_ptr != NULL)
{
        memcpy(tmp_ptr, this->SniffEther->pkt_header, sizeof(struct 
pcap_pkthdr));
        tail->packet_ptr = tmp_ptr;
}

DC


----- Original Message ----- 
From: "Steve Mc Donnell" <s-mc-d at hotmail.com>
To: <winpcap-users at winpcap.org>
Sent: Monday, April 24, 2006 3:07 PM
Subject: Re: [Winpcap-users] Re: linked list problem urgent help needed!


> >You *are* allocating new "pcap_pkthdr" structures for each new packet, 
> >right?  (I presume, from
>
> I think so, if pcap_pkthdr is one of the fields in the packet struct:
> typedef struct packet{
> int packet_number;
>                struct pcap_pkthdr *pkt_header; //points to the header of a 
> packet
>                const u_char *pkt_data; //packet data
> struct packet *next; //pointer to next node in list
> } packet;
>
> and if I'm creating a new one of these nodes for each packet that should 
> cover it right?
>
>>I'm a C programmer rather than a C++ programmer, but it sounds like you're 
>>copying the pointer to the header record rather than the entire struct.
>>
>>Specifically, does
>>
>>tail->pkt_header = this->SniffEther->pkt_header;
>>
>>copy just the pointer to the header or the entire struct?
>>
>>DC
>
> I'll admit, getting my head around pointers is definitly not one of my 
> strong points. Since I can pass this->SniffEther->pkt_header directly to 
> the function to update the gui I just assumed I could assign it to 
> tail->pkt_header the same way.
>
> _________________________________________________________________
> FREE pop-up blocking with the new MSN Toolbar - get it now! 
> http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
>
> _______________________________________________
> 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