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

Steve Mc Donnell s-mc-d at hotmail.com
Mon Apr 24 23:00:51 GMT 2006


David do you by anychance believe in karma? You've just gained a huge amount 
of the positive kind!!! I switched the struct declaration to 'struct 
pcap_pkthdr pkt_header;' and now add the header to the list with 
'tail->pkt_header = *(this->SniffEther->pkt_header);' and it seems to work 
perfectly :) Thanks a lot! I can take this noose of my head now...


>From: "David Chang" <dchang at fsautomation.com>
>Reply-To: winpcap-users at winpcap.org
>To: <winpcap-users at winpcap.org>
>Subject: Re: [Winpcap-users] Re: linked list problem urgent help needed!
>Date: Mon, 24 Apr 2006 15:29:30 -0700
>
>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
>>
>
>
>_______________________________________________
>Winpcap-users mailing list
>Winpcap-users at winpcap.org
>https://www.winpcap.org/mailman/listinfo/winpcap-users

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



More information about the Winpcap-users mailing list