All pastes #780648 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-11-18 17:12 UTC
rendered paste body
#include "analyzer.h"
#define N 1000
#define M 100

/*==============================================================================
                                MyList
==============================================================================*/
struct bufList {
        struct Packet   pckt;
        struct bufList *next;
        struct bufList *prev;
};
class MyList{
        private :
                struct bufList *all;
                struct bufList *npoint;
                struct bufList *rmpoint;
                int    lsize;
                bool    newlist;
        public :
//-------------------------------- Constructor ---------------------------------
                MyList(){
                        all=new bufList;
                        all->pckt.buf=new char[10];
                        all->pckt.hbuf=new char[10];
                        all->prev=NULL;
                        all->next=NULL;
                        npoint=all;
                        newlist=true;
                }
//-------------------------------- Add new Item --------------------------------
        void Add(Packet *packet){
                 if(!newlist){
                                npoint->prev=npoint;
                                npoint->next=new bufList;
                                npoint->next->next=NULL;
                                npoint->next->pckt.buf=new char[packet->len];
                                npoint->next->pckt.len=packet->len;
                                memcpy(npoint->next->pckt.buf,packet->buf,npoint->next->pckt.len);
                                int len=packet->hlen;
                                npoint->next->pckt.hlen=len;
                                npoint->next->pckt.hbuf=new char[len];
                                memcpy(npoint->next->pckt.hbuf,packet->hbuf,len);
                                memcpy(&npoint->next->pckt.eth,&packet->eth,sizeof(packet->eth));

                                npoint->next->prev=npoint;
                                npoint=npoint->next;
                                lsize++;
                                delete packet->buf;
                                delete packet->hbuf;
                 }else{
                                delete npoint->pckt.buf;
                                all->pckt.buf=new char[packet->len];
                                all->pckt.len=packet->len;
                                all->pckt.hlen=packet->hlen;
                                memcpy(all->pckt.buf,packet->buf,packet->len);
                                memcpy(&all->pckt.eth,&packet->eth,sizeof(packet->eth));
                                int len=all->pckt.hlen;
                                all->pckt.hbuf=new char[len];
                                strncpy(all->pckt.hbuf,packet->hbuf,all->pckt.hlen);
                                lsize=1;
                                newlist=false;
                                delete packet->buf;
                                delete packet->hbuf;
                 }

}

//-------------------------------- Remove First Item ---------------------------
                void RemoveFirst(){
                        rmpoint=all;
                        all=all->next;
                        if(rmpoint->pckt.buf!=NULL){
                                delete rmpoint->pckt.buf;
                        }
                        if(rmpoint->pckt.hbuf!=NULL){
                                delete rmpoint->pckt.hbuf;
                        }
                        delete rmpoint;
                        rmpoint=all;
                        lsize--;
                }
                bufList *getList(){
                        return all;
                }
//-------------------------------- Get Pointer to packet -----------------------
                bufList *GetPack(int num){
                        bufList *p=all;
                        for(int i=0;i<num && p->next!=NULL;i++){
                                p=p->next;
                        }
                        return p;
                }

//-------------------------------- GetSize -------------------------------------
                int GetSize(){
                        return lsize;
                }

//-------------------------------- Clear ---------------------------------------
                void Clear(){
                        rmpoint=all;
                        while(rmpoint!=NULL){
                                delete rmpoint->pckt.buf;
                                delete rmpoint->pckt.hbuf;
                                rmpoint=rmpoint->next;
                        }
                        delete all;
                }
};