Wireshark-dev: [Wireshark-dev] memory leak while using libwireshark, please help me
From: lipeng5555lipeng <lipeng5555@xxxxxxx>
Date: Thu, 28 Nov 2013 17:23:16 +0800

When I use libwires to dissect something,there may accur a memory leak

 

Cpp is my test program,is it right?please help me

Attachment: valgrind_memory_leak.rar
Description: Binary data

#pragma warning(disable : 4786)
#pragma warning(disable : 4805)

#include "Scan_Dissect_Pkt_Struct.h"
#include <signal.h>


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define  MAX_PACKGE_LENGTH  65536//1540
#define  MIN_PACKGE_LENGTH  18

/***********************glibµÄÍ·Îļþ*****************************/
#include <glib.h>
#include <glib/gprintf.h>
#include <time.h>
/***********************epanµÄÍ·Îļþ*****************************/
#include <epan/epan.h>
#include <epan/packet.h>
#include <epan/addr_resolv.h>
#include <epan/epan_dissect.h>
#include <epan/tap.h>
/////////////////////////////////add by ljm on 20130317
#ifdef XJ_DISSECT_PACKET_LINUX_DEF
#include <wsutil/privileges.h>
#endif
//////////////////////////////////
//#include "vld.h"


bool g_binitepan = false;
bool g_xj_process_policies_called = false;
int g_nlibpCapFileSize = -1;
int g_nlibcurpos = -1;
char* g_plibpCapFileContent = NULL;
PACKET_STRUCT g_Packet;
bool g_bExit;

typedef int                     BOOL;
typedef unsigned int                    UINT;
//#define DATA_LEN 193
#define DATA_LEN 73

/*
guchar data[DATA_LEN] = 
{
	0x00, 0xc3, 0x53, 0x1c, 0x00, 0x00, 0x1e, 0x06, 0x6c, 0x05, 0x0a, 0x64, 0x64, 0x4b, 0x0a, 0x64, 
	0x64, 0x01, 0x00, 0x66, 0xff, 0xc0, 0x00, 0x89, 0x9a, 0xf7, 0x8e, 0xfc, 0xf3, 0xd5, 0x50, 0x18, 
	0x20, 0x00, 0xda, 0x20, 0x00, 0x00, 0x03, 0x00, 0x00, 0x9b, 0x02, 0xf0, 0x80, 0x01, 0x00, 0x01, 
	0x00, 0x61, 0x81, 0x8d, 0x30, 0x81, 0x8a, 0x02, 0x01, 0x03, 0xa0, 0x81, 0x84, 0xa3, 0x81, 0x81, 
	0xa0, 0x7f, 0xa1, 0x05, 0x80, 0x03, 0x52, 0x50, 0x54, 0xa0, 0x76, 0x8a, 0x05, 0x41, 0x69, 0x6e, 
	0x33, 0x30, 0x84, 0x03, 0x06, 0x78, 0x00, 0x86, 0x02, 0x00, 0xee, 0x8c, 0x06, 0x01, 0x31, 0xd2, 
	0x4e, 0x2a, 0x9d, 0x8a, 0x16, 0x50, 0x4c, 0x31, 0x30, 0x30, 0x31, 0x36, 0x4d, 0x45, 0x41, 0x53, 
	0x2f, 0x4c, 0x4c, 0x4e, 0x30, 0x24, 0x64, 0x73, 0x41, 0x69, 0x6e, 0x84, 0x04, 0x01, 0x00, 0xc0, 
	0x00, 0xa2, 0x1a, 0xa2, 0x09, 0xa2, 0x07, 0x87, 0x05, 0x08, 0x39, 0xb8, 0xbd, 0x53, 0x84, 0x03, 
	0x03, 0x00, 0x40, 0x91, 0x08, 0x52, 0x83, 0x0f, 0x4a, 0x35, 0x87, 0x93, 0x0a, 0xa2, 0x1a, 0xa2, 
	0x09, 0xa2, 0x07, 0x87, 0x05, 0x08, 0x39, 0xdb, 0xd4, 0x47, 0x84, 0x03, 0x03, 0x00, 0x40, 0x91, 
	0x08, 0x52, 0x83, 0x0f, 0x4a, 0x42, 0x54, 0x60, 0x0a, 0x84, 0x02, 0x02, 0x40, 0x84, 0x02, 0x02, 
	0x40
};
*/
const guchar xjdata[DATA_LEN] = 
{
	0x7E, 0x6D, 0x20, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00, 
	0x00, 0x3B, 0x5F, 0x15, 0x00, 0x00, 0x40, 0x11, 0xF1, 0x51, 0x73, 0xAB, 0x4F, 0x08, 0xDB, 0x8D, 
	0x8C, 0x0A, 0x9B, 0x90, 0x00, 0x35, 0x00, 0x27, 0xEF, 0x4D, 0x43, 0x07, 0x01, 0x00, 0x00, 0x01, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x74, 0x04, 0x73, 0x69, 0x6E, 0x61, 0x03, 0x63, 0x6F, 
	0x6D, 0x02, 0x63, 0x6E, 0x00, 0x00, 0x01, 0x00, 0x01
};

void sig_handler(int nsig)
{
	switch(nsig)
	{
	case SIGINT:
	case SIGTERM:
		{
			printf("ÊÕµ½Í˳öÐźÅ:%d, ³ÌÐò×¼±¸×¼±¸Í˳ö...", nsig);
			g_bExit = true;//ÈÃÖ÷Ïß³ÌÍ˳ö£¬²¢ÊÍ·Å×ÊÔ´
		}
		return;
	default:
		break;
	}
}

/********************¹¹½¨Ó¦ÓÃЭÒéÀàÐÍ,²¢±ê¼Ç¶ÔÓ¦µÄ½ÚµãÐòºÅ******************/
int get_ether_type(XJ_DISSECT_PKT* pxj_dissect_pkt)
{
	xj_pkt_ether_type_enum  pkt_eher_type = PKT_ETHER_TYPE_UNKOWN;
	XJ_PROTO_NODE* pxj_proto_node_bottom = NULL;
	int nLayerNO;//ÓÐЧ²ãµÄ²ãºÅ

	for(nLayerNO = pxj_dissect_pkt->prototreelist_size-1; nLayerNO >=0; nLayerNO--)//Öð²ãÑ°ÕÒ
	{
		pxj_proto_node_bottom = &pxj_dissect_pkt->pprototreelist[nLayerNO];
		pxj_dissect_pkt->prototreelist_app_seq = nLayerNO;
		if(pxj_proto_node_bottom->node_name == NULL)//MMS±¨ÎÄ
		{
			continue;
		}

		if(strcmp(pxj_proto_node_bottom->node_name, "MMS") == 0)
		{
			pkt_eher_type = PKT_ETHER_TYPE_IEC61850_MMS;
			break;
		}
		else if(strcmp(pxj_proto_node_bottom->node_name, "IEC61850 Sampled Values")== 0)
		{
			pkt_eher_type = PKT_ETHER_TYPE_IEC61850_SMV;
			break;
		}
		else if(strcmp(pxj_proto_node_bottom->node_name, "GOOSE")== 0)
		{
			pkt_eher_type = PKT_ETHER_TYPE_IEC61850_GOOSE;
			break;
		}
		else if(NULL != strstr(pxj_proto_node_bottom->node_name, "COTP"))//¼ÌÐø¿ª·Å
		{
			pkt_eher_type = PKT_ETHER_TYPE_COTP;
			break;
		}
		else if(NULL != strstr(pxj_proto_node_bottom->node_name, "TPKT"))//¼ÌÐø¿ª·Å  add by yinzhehong 20130321
		{
			pkt_eher_type = PKT_ETHER_TYPE_TPKT;
			break;
		}
		else if(strcmp(pxj_proto_node_bottom->node_name, "Address Resolution Protocol")== 0)
		{
			pkt_eher_type = PKT_ETHER_TYPE_ARP;
			break;
		}
		else if(strcmp(pxj_proto_node_bottom->node_name, "Transmission Control Protocol")== 0)
		{
			pkt_eher_type = PKT_ETHER_TYPE_TCP;
			break;
		}
		else if(strcmp(pxj_proto_node_bottom->node_name, "Precision Time Protocol (IEEE1588)")== 0)
		{
			pkt_eher_type = PKT_ETHER_TYPE_IEC61850_PTP_1588;
			break;
		}
		else if(NULL != strstr(pxj_proto_node_bottom->node_name, "User Datagram Protocol"))
		{
			pkt_eher_type = PKT_ETHER_TYPE_UDP;
		}
	}
	pxj_dissect_pkt->ether_type = pkt_eher_type;

	return nLayerNO;
}

//ÉêÇëÊý¾ÝÍ·¿Õ¼ä*/
wtap_pkthdr * pwtap_phdr_init()
{
	wtap_pkthdr * pwtap_phdr = (wtap_pkthdr *)g_malloc0(sizeof(wtap_pkthdr));
	pwtap_phdr->interface_id = 0;
	pwtap_phdr->caplen       = 0;
	pwtap_phdr->len          = 0;
	pwtap_phdr->pkt_encap    = 1;
	pwtap_phdr->pack_flags   = 0;
	pwtap_phdr->drop_count   = 0;
	pwtap_phdr->opt_comment  = NULL;
	return pwtap_phdr;
}

/*********»ñÈ¡wirshark½á¹¹ÖÐͬ¼¶×Ó½Úµã¸öÊý***************/
int get_proto_node_same_level_size(_proto_node *pnode)
{
	if(pnode == NULL)
	{
		return 0;
	}

	int listsize = 1;//ĬÈÏ1¸ö
	_proto_node *pnode_level = pnode->next;
	while(pnode_level != NULL)
	{
		listsize ++;
		pnode_level = pnode_level->next;
	}
	return listsize;
}

//²éѯÌØÕ÷×Ö·û³öÏÖµÄλÖÃ
int GetProtocolNum(const char *buf,int n_buffer_length,char c_char)
{
	int nposition = -1;

	for(int i = 0; i < n_buffer_length; i++)
	{
		if(*buf == c_char)
		{
			nposition = i;
			break;
		}
		buf++;
	}
	return nposition;
}

/***************Êä³ö¸÷¼¶×Ó½Úµã*************************/
void output_nodetree_field_info(_proto_node *pnode, XJ_PROTO_NODE* pxj_node, bool btoplevel)
{
	pxj_node->length =    pnode->finfo->length;//³¤¶È
	pxj_node->start_pos = pnode->finfo->start;//ÆðʼλÖÃ
	pxj_node->node_type = (xj_pkt_ether_type_enum) pnode->finfo->hfinfo->type;//ÀàÐÍ

	gchar label_str[ITEM_LABEL_LENGTH] = "";
	gchar *label_ptr = NULL;
	gint label_length = ITEM_LABEL_LENGTH;
	memset(label_str, 0, ITEM_LABEL_LENGTH);
	field_info* fi = pnode->finfo;

	if (fi->rep) 
	{
		label_ptr = fi->rep->representation;
	}
	else 
	{ /* no, make a generic label */
		label_ptr = label_str;
		proto_item_fill_label(fi, label_str);
	}
	label_length = strlen(label_ptr);
/*	if(label_length > 0)
	{
		pxj_node->node_desc = (char*) calloc((label_length+1),sizeof(char));
		memcpy(pxj_node->node_desc,label_ptr,label_length);
		pxj_node->node_name_detail = (char*) calloc((label_length+1),sizeof(char));
		memcpy(pxj_node->node_name_detail,label_ptr,label_length);
	}*/
	int nstart = 0;
	if(btoplevel)
	{
		nstart = GetProtocolNum(label_ptr, label_length, ',');
	}
	else
	{
		nstart = GetProtocolNum(label_ptr, label_length, ':');
	}

	if(nstart == -1)
	{
		nstart = 0;
	}
	else
	{
		nstart +=2;//È¥³ý£ººÍ¿Õ¸ñ
	}

	if(nstart != 0)//node_name_desc
	{
		pxj_node->node_name_detail = new char[nstart];//(char*) calloc(nstart,sizeof(char));
		memset(pxj_node->node_name_detail, 0, nstart);
		memcpy(pxj_node->node_name_detail, label_ptr, nstart-2);
	}

	label_length -= nstart;
	if(label_length < 0)
	{
		label_length += nstart;
	}

	pxj_node->node_desc = new char[label_length+1];//(char*) calloc((label_length+1),sizeof(char));
	memset(pxj_node->node_desc, 0, label_length+1);
	memcpy(pxj_node->node_desc, &label_ptr[nstart], label_length);//¿½±´ÃèÊö

	if(fi->hfinfo->name)//¿½±´Ãû³Æ
	{
		label_length = strlen(fi->hfinfo->name) + 1;
		if(label_length > 0)
		{
			pxj_node->node_name = new char[label_length + 1];//(char*) calloc(label_length+1,sizeof(char));
			memset(pxj_node->node_name, 0, (label_length + 1));
			memcpy(pxj_node->node_name, fi->hfinfo->name, label_length);
		}
	}

	proto_node *pchildnode = pnode->first_child;//¿½±´×Ó½Úµã
	int nchildnodelistsize = get_proto_node_same_level_size(pchildnode);
	if(nchildnodelistsize == 0)//ÎÞ×ӽڵ㣬ֱ½Ó·µ»Ø
	{
		return;
	}

	pxj_node->pchildlist = new XJ_PROTO_NODE[nchildnodelistsize];//(XJ_PROTO_NODE*) calloc(nchildnodelistsize,sizeof(XJ_PROTO_NODE));//
	memset(pxj_node->pchildlist, 0, nchildnodelistsize*sizeof(XJ_PROTO_NODE));
	pxj_node->childlist_size = nchildnodelistsize;
	for(int j = 0; j < nchildnodelistsize; j++)
	{
		if(pchildnode == NULL)
		{
			break;
		}

		pxj_node->pchildlist[j].parent_node = pxj_node;
		output_nodetree_field_info(pchildnode, &pxj_node->pchildlist[j], false);
		pchildnode = pchildnode->next;
	}
}

/********½«wirshark½âÎö³öÀ´µÄ½á¹¹×ª³ÉÊä³ö½á¹¹*******/
void wirsharkpkt2xjpkt(epan_dissect_t* edt, XJ_DISSECT_PKT* pxj_dissect_pkt)
{
	_proto_node *pnode = NULL;
	pnode = edt->tree->first_child;//Ö¡ÃèÊöÄÚÈݲ㣬²»Êä³ö
	if(pnode == NULL)
	{
		return;
	}

	pnode = pnode->next;            //Õýʽ½âÎöµÄ±¨ÎIJã
	int nlistsize = get_proto_node_same_level_size(pnode);
	if(nlistsize <= 0)//ÎÞЧ
	{
		return;
	}

	pxj_dissect_pkt->pprototreelist = new XJ_PROTO_NODE[nlistsize];//(XJ_PROTO_NODE*) calloc(nlistsize, sizeof(XJ_PROTO_NODE));//
	memset(pxj_dissect_pkt->pprototreelist, 0, nlistsize*sizeof(XJ_PROTO_NODE));
	pxj_dissect_pkt->prototreelist_size = nlistsize;
	for(int i = 0; i < nlistsize; i++)
	{
		if(pnode == NULL)
		{
			break;
		}

		output_nodetree_field_info(pnode, &pxj_dissect_pkt->pprototreelist[i], true);//Ñ­»·Êä³ö¸÷²ã½âÎö½á¹û
		pnode = pnode->next;
	}
	get_ether_type(pxj_dissect_pkt);//»ñÈ¡±¨ÎÄÀàÐÍ
	pxj_dissect_pkt->port_src = edt->pi.srcport; //Ô´¶Ë¿Ú
	pxj_dissect_pkt->port_dst = edt->pi.destport;//Ä¿±ê¶Ë¿Ú
}

/********½«wirshark½âÎö³öÀ´µÄMMS±¨ÎĽṹת³ÉÊä³ö½á¹¹*******/
void wirsharkpkt2xjpkt_mms(epan_dissect_t* edt,XJ_DISSECT_PKT* pxj_dissect_pkt)
{
	_proto_node *pnode,*pnde_copystart;
	pnode = edt->tree->first_child;//Ö¡ÃèÊöÄÚÈݲ㣬²»Êä³ö
	pnde_copystart = NULL;
	int listsize = 0;//ĬÈÏ1¸ö
	while(pnode != NULL)
	{
		listsize ++;
		pnode = pnode->next;
		if(listsize == 4)//Ìø¹ýTCP²ã
		{
			pnde_copystart  = pnode;
		}
	}
	if(pnde_copystart == NULL)
		return;
	pxj_dissect_pkt->pprototreelist = new XJ_PROTO_NODE[listsize-4];//(XJ_PROTO_NODE*) calloc(listsize-4, sizeof(XJ_PROTO_NODE));//
	memset(pxj_dissect_pkt->pprototreelist,0,(listsize-4)* sizeof(XJ_PROTO_NODE));
	pxj_dissect_pkt->prototreelist_size = listsize-4;
	for(int i = 0; i < pxj_dissect_pkt->prototreelist_size; i++)
	{
		if(pnde_copystart == NULL)
			break;
		output_nodetree_field_info(pnde_copystart,&pxj_dissect_pkt->pprototreelist[i],true);//Ñ­»·Êä³ö¸÷²ã½âÎö½á¹û
		pnde_copystart = pnde_copystart->next;
	}
	get_ether_type(pxj_dissect_pkt);//»ñÈ¡±¨ÎÄÀàÐÍ
	//MACµØÖ·
	unsigned char* pdata;
	if(edt->pi.dl_src.len == 6)
	{
		pdata = (unsigned char*)edt->pi.dl_src.data;
		g_sprintf(pxj_dissect_pkt->mac_src,"%02x-%02x-%02x-%02x-%02x-%02x", 
			*pdata,*(pdata+1), *(pdata+2), *(pdata+3), *(pdata+4), *(pdata+5));
	}

	if(edt->pi.dl_dst.len == 6)
	{
		pdata = (unsigned char*)edt->pi.dl_dst.data;
		g_sprintf(pxj_dissect_pkt->mac_dst,"%02x-%02x-%02x-%02x-%02x-%02x", 
			*pdata, *(pdata+1), *(pdata+2), *(pdata+3), *(pdata+4), *(pdata+5));
	}

	if(edt->pi.net_src.len == 4)
	{
		pdata = (unsigned char*)edt->pi.net_src.data;
		g_sprintf(pxj_dissect_pkt->ip_src,"%d.%d.%d.%d", 
			*pdata, *(pdata+1), *(pdata+2), *(pdata+3));
	}

	if(edt->pi.net_dst.len == 4)
	{
		pdata = (unsigned char*)edt->pi.net_dst.data;
		g_sprintf(pxj_dissect_pkt->ip_dst,"%d.%d.%d.%d", 
			*pdata, *(pdata+1), *(pdata+2), *(pdata+3));
	}

	pxj_dissect_pkt->port_src = edt->pi.srcport; //Ô´¶Ë¿Ú
	pxj_dissect_pkt->port_dst = edt->pi.destport;//Ä¿±ê¶Ë¿Ú
}

/*****ÊͷŸ÷¸öËùÓÐ×Ó½Úµã******/
int  xj_cleanup_packet_node(XJ_PROTO_NODE* pxj_node)
{
	if(NULL == pxj_node)
	{
		return 0;
	}

	//ɾ³ý½Úµã×ÔÉí¸÷¸öÊôÐÔ
	if(NULL != pxj_node->node_name)
	{
		delete[] pxj_node->node_name;
		pxj_node->node_name = NULL;
	}
	
	if(NULL != pxj_node->node_name_detail)
	{
		delete[] pxj_node->node_name_detail;
		pxj_node->node_name_detail = NULL;
	}
	
	if(NULL != pxj_node->node_desc)
	{
		delete[] pxj_node->node_desc;
		pxj_node->node_desc = NULL;
	}
	
	/*
	if(pxj_node->childlist_size == 0 || pxj_node->pchildlist== NULL)
		return 0;
	*/

	//Ñ­»·É¾³ý×Ó½Úµã
	for(int k = 0; k < pxj_node->childlist_size; k++)
	{
		xj_cleanup_packet_node(&pxj_node->pchildlist[k]);//µÝ¹éµ÷ÓÃ
	}

	if (NULL != pxj_node->pchildlist)
	{
		delete[] pxj_node->pchildlist;
		pxj_node->pchildlist = NULL;
	}

	pxj_node->childlist_size = 0;
	
	return 0;
}

/*****ÊͷŽâÎöºóµÄЭÒéÊ÷******/
int  xj_cleanup_packet(XJ_DISSECT_PKT* pxj_dissect_pkt)
{
	if(NULL == pxj_dissect_pkt)
	{
		printf("[xj_cleanup_packet]pxj_dissect_pkt is null point£¡\n");
		return -1;
	}

	if(NULL == pxj_dissect_pkt->pprototreelist)
	{
		if (pxj_dissect_pkt != NULL)
		{
			delete pxj_dissect_pkt;
			pxj_dissect_pkt = NULL;
		}
		return -1;
	}

	//printf("[xj_cleanup_packet]pprototreelist size is %d", pxj_dissect_pkt->prototreelist_size);

	for(int i = 0; i < pxj_dissect_pkt->prototreelist_size; i++)
	{
		xj_cleanup_packet_node(&pxj_dissect_pkt->pprototreelist[i]);
	}

	if (NULL != pxj_dissect_pkt->pprototreelist)
	{
		delete[] pxj_dissect_pkt->pprototreelist;
		pxj_dissect_pkt->pprototreelist = NULL;
	}

	if (NULL != pxj_dissect_pkt)
	{
		delete pxj_dissect_pkt;
		pxj_dissect_pkt = NULL;
		//printf("[xj_cleanup_packet]release pxj_dissect_pkt memory success£¡\n");
	}
	
	return 0;
}

XJ_DISSECT_PKT*  xj_dissect_packet()
{
#ifdef XJ_DISSECT_PACKET_LINUX_DEF
	if (!g_xj_process_policies_called)
	{
		init_process_policies();//³õʼ»¯±¾µØȨÏÞ
		g_xj_process_policies_called = true;
	}
#endif

	if(!g_binitepan)//È«¾Ö±äÁ¿£¬Èçδע²á³õʼ»¯£¬ÏÈ×¢²á³õʼ»¯£¬¶à´Îµ÷Óã¬Ö»Ðè³õʼ»¯Ò»´Î
	{
		epan_init(register_all_protocols, register_all_protocol_handoffs, 
			NULL, NULL, NULL, NULL, NULL, NULL);//×¢²á½âÎöÆ÷
		
		cleanup_dissection();//clean up environment
		init_dissection();//init dissect environment
		
		g_binitepan = true;
		//tap_queue_init(&edt);//¶ÓÁÐ
	}

	frame_data  *fdata;
	epan_dissect_t  *edt;
	wtap_pkthdr  pseudo_header;
	pseudo_header.interface_id = 0;
	pseudo_header.caplen       = 0;
	pseudo_header.len          = -1;
	pseudo_header.pkt_encap    = 1;
	pseudo_header.pack_flags   = 0;
	pseudo_header.drop_count   = 0;
	pseudo_header.opt_comment  = NULL;
	
	fdata = (frame_data*)g_new(frame_data, 1);
	
	memset(fdata, 0, sizeof(frame_data));
	fdata->pfd  = NULL;
	fdata->num = 1;
	fdata->interface_id = 0;
	fdata->pkt_len  = DATA_LEN;
	fdata->cap_len  = DATA_LEN;
	fdata->cum_bytes = 0;
	fdata->file_off = 0;
	fdata->subnum = 0;
	fdata->lnk_t = WTAP_ENCAP_ETHERNET;
	fdata->flags.encoding = PACKET_CHAR_ENC_CHAR_ASCII;
	fdata->flags.visited = 0;
	fdata->flags.marked = 0;
	fdata->flags.ref_time = 0;
	fdata->color_filter = NULL;
	fdata->abs_ts.secs = 0;
	fdata->abs_ts.nsecs = 0;
	fdata->opt_comment = NULL;

	nstime_t       elapsed_time;    /* Elapsed time */
	nstime_t       first_ts;
	nstime_t       prev_dis_ts;
	nstime_t       prev_cap_ts;
	guint32 cum_bytes = 0;

	nstime_set_zero(&elapsed_time);
	nstime_set_zero(&first_ts);
	nstime_set_zero(&prev_dis_ts);
	nstime_set_zero(&prev_cap_ts);
	
	edt = epan_dissect_new(TRUE, TRUE);
	//frame_data_set_before_dissect(fdata, &elapsed_time, &first_ts, &prev_dis_ts, &prev_cap_ts);//½âÎöÇ°µÄÉèÖã¬ÉèÖÃʱ¼ä´Á
	epan_dissect_run(edt, &pseudo_header, xjdata, fdata, NULL);

	epan_dissect_free(edt);
	//frame_data_cleanup(fdata);
	frame_data_destroy(fdata);
	g_free(fdata);
	//cleanup_dissection();

	printf("successful call xj_dissect_packet...\n");

	return NULL;
}

void MySleep(UINT nmilliseconds)
{
#ifdef OS_WINDOWS
	//Sleep(nmilliseconds);
#endif
	
#ifdef OS_LINUX
	timeval tm;
	tm.tv_sec =  nmilliseconds / 1000;
	tm.tv_usec = (nmilliseconds % 1000) * 1000;
	int nret=select(0, 0, 0, 0, &tm);
#endif
}

int main(int argc, char *argv[])
{
	XJ_DISSECT_PKT* pXjstruct = NULL;

	while (!g_bExit)
	{
		pXjstruct = xj_dissect_packet();
		xj_cleanup_packet(pXjstruct);//ÊÍ·Å×ÊÔ´

		MySleep(50);
	}

	if (g_binitepan)
	{
		cleanup_dissection();
		epan_cleanup();
	}

	return 0;
}

/*
//¸ù¾ÝÊý¾Ý°üÀàÐÍ£¬½âÎöÊý¾Ý°ü
int main(int argc, char *argv[])
{
	char chErrorMsg[1024] = "";
	char* pkt_data = NULL;//º¬±¨ÎÄÍ·
	TS_PCAP_PKTHDR pktheader;
	TS_PCAP_HEADER ts_cap_header;
	g_bExit = false;

#ifdef OS_LINUX
	//Ôö¼ÓÊÕµ½¶ÔÍâ½çÐźŵĴ¦Àí
	//¶ÔSIGTERM´¦Àí 
	signal(SIGTERM, sig_handler);
	//¶ÔSIGINT´¦Àí
	signal(SIGINT, sig_handler);
#else
	signal(SIGINT, sig_handler);
#endif

	if(argc < 2)
	{
		printf("please input test filename... \n");
		return -1;
	}
	else
	{
		FILE* pCapfile;
		pCapfile = fopen(argv[1], "rw");
		if (NULL == pCapfile)
		{
			memset(chErrorMsg, '\0', 1024);
			sprintf(chErrorMsg, "open %s failed,reason:%s(errno:%d)", 
				argv[1], strerror(errno), errno);
			printf("%s\n", chErrorMsg);
			return -2;
		}

		printf("open file %s succeed.\n", argv[1]);
		
		fseek(pCapfile, 0, SEEK_END);
		g_nlibpCapFileSize = ftell(pCapfile);
		//fclose(pCapfile);

		//pCapfile = fopen(argv[1], "rb");

		printf("file size is %d \n", g_nlibpCapFileSize);
		
		fseek(pCapfile, 0, SEEK_SET);
		g_plibpCapFileContent = new char[g_nlibpCapFileSize+1];
		memset(g_plibpCapFileContent, '\0', g_nlibpCapFileSize+1);
		
		
		int nReadSize = fread(g_plibpCapFileContent, sizeof(char), g_nlibpCapFileSize, pCapfile);
		fclose(pCapfile);//¹Ø±ÕÎļþ
		g_plibpCapFileContent[g_nlibpCapFileSize] = '\0';

		printf("read file %s succeed,last char is %c.\n", 
			argv[1], g_plibpCapFileContent[g_nlibpCapFileSize+1]);
		
		g_nlibcurpos = sizeof(TS_PCAP_HEADER);
		memcpy(&ts_cap_header, g_plibpCapFileContent, g_nlibcurpos);
		
		unsigned int npktoffset = 0;
		CAPMSGGININFO  * pCapPackage = NULL;
		double   fFirstPackageT = 0.0f; //µÚһ֡ʱ¼ä
		double   fPrePackageT = 0.0f;   //ÉÏһ֡ʱ¼ä
		double   fPackageT = 0.0f;
		int nseq = 1;
		unsigned int nmmscount = 0;//MMS±¨Îļ¶Êý
		
		while (!g_bExit)
		{
			while((pkt_data = Libpcap_next_cap(&pktheader, npktoffset))!= NULL)
			{
				printf("cap %d seq from pcap msg...\n", npktoffset);

				pCapPackage = LoadePacketMsg(nseq, &pktheader, pkt_data);//ÖÆ×÷±¨ÎÄ£¬TCP±¨ÎÄÁ´Â··ÖÎö¡¢¹ý³Ì²ãµÄ±¨ÎÄ(SMV,GOOSE,1588)ÖÆ×÷
				pCapPackage->npkt_offset_incapfile = npktoffset;
				
				fPackageT = pktheader.ts.GmtTime + pktheader.ts.us/1000000.0;
				if(nseq == 1)//µÚÒ»Ö¡
				{
					fFirstPackageT = fPackageT;
					fPrePackageT   = fPackageT;//0.0f;
				}
				
				pCapPackage->ftime_delta = fPackageT - fPrePackageT;     //ÓëÉÏÒ»Ö¡µÄʱ¼ä²î
				pCapPackage->ftime_relative = fPackageT - fFirstPackageT;//ÓëµÚÒ»Ö¡±¨ÎĵÄʱ¼ä²î
				//ÖÆ×÷½çÃæÏÔʾÓõĽṹ-£¬Ö»½âÎö102¶Ë¿Ú±¨ÎÄ,ÇÒÐÄÌø±¨ÎIJ»½âÎö
				if(pCapPackage->napptype == ETHER_TYPE_TCP  && (pCapPackage->ndst_port == 102 || pCapPackage->nsrc_port == 102) 
					&& (pCapPackage->ncap_len > 90))//66½öÐÄÌø +7 COPT+TPKTµÄÍ·
				{
					nmmscount++;
					printf("call xj_dissect_packet now.. \n");
					xj_dissect_packet(pCapPackage->csourceinfo+16, pCapPackage->nsourceinfo_length-16, nmmscount, 0, 0, 0, 0);
					xj_cleanup_packet(pCapPackage->pxj_dissect_pkt);//ÊÍ·Å×ÊÔ´
					pCapPackage->pxj_dissect_pkt = NULL;
				}
				nseq++;//ÐòºÅ+1
				fPrePackageT = fPackageT;//¼Ç¼ÉÏһ֡ʱ¼ä
				
				if (pCapPackage != NULL)
				{
					delete pCapPackage;
					pCapPackage = NULL;
				}
			}
			
			MySleep(100);

			npktoffset = 0;
			nmmscount = 0;
			nseq = 0;
		}
		
		if (g_plibpCapFileContent != NULL)
		{
			delete[] g_plibpCapFileContent;
			g_plibpCapFileContent = NULL;
		}

		if (g_binitepan)
		{
			epan_cleanup();
		}
	}

	return 0;
}
*/


Attachment: Makefile_debug
Description: Binary data

#if !defined(_SCAN_DISSECT_STRUCT_H)
#define _SCAN_DISSECT_STRUCT_H

#include <map>
#include <string.h>
#include <errno.h>

#define	PCAP_MAGIC			0xa1b2c3d4

/**
 * @brief       Êý¾Ý°ü½âÎö½Ó¿Ú
 * @use			wirsharkÊý¾Ý°ü½âÎö·â×°½Ó¿Ú½á¹¹¶¨Òå
 * @author      ÒüÕãºé
 * @version     ver1.0
 * @date        2012/10/17
 */
/* field types ¸÷¸ö½ÚµãÀàÐÍ*/
enum xj_pkt_field_type_enum {
	PKT_FT_NONE,	/* used for text labels with no value */
	PKT_FT_PROTOCOL,
	PKT_FT_BOOLEAN,	/* TRUE and FALSE come from <glib.h> */
	PKT_FT_UINT8,
	PKT_FT_UINT16,
	PKT_FT_UINT24,	/* really a UINT32, but displayed as 3 hex-digits if FD_HEX*/
	PKT_FT_UINT32,
	PKT_FT_UINT64,
	PKT_FT_INT8,
	PKT_FT_INT16,
	PKT_FT_INT24,	/* same as for UINT24 */
	PKT_FT_INT32,
	PKT_FT_INT64,
	PKT_FT_FLOAT,
	PKT_FT_DOUBLE,
	PKT_FT_ABSOLUTE_TIME,
	PKT_FT_RELATIVE_TIME,
	PKT_FT_STRING,
	PKT_FT_STRINGZ,	/* for use with proto_tree_add_item() */
	PKT_FT_UINT_STRING,	/* for use with proto_tree_add_item() */
	/*FT_UCS2_LE, */    /* Unicode, 2 byte, Little Endian     */
	PKT_FT_ETHER,
	PKT_FT_BYTES,
	PKT_FT_UINT_BYTES,
	PKT_FT_IPv4,
	PKT_FT_IPv6,
	PKT_FT_IPXNET,
	PKT_FT_FRAMENUM,	/* a UINT32, but if selected lets you go to frame with that number */
	PKT_FT_PCRE,	/* a compiled Perl-Compatible Regular Expression object */
	PKT_FT_GUID,	/* GUID, UUID */
	PKT_FT_OID,		/* OBJECT IDENTIFIER */
	PKT_FT_EUI64,
	PKT_FT_NUM_TYPES /* last item number plus one */
};
/* ETHER_TYPE ¸÷¸ö½ÚµãÀàÐÍ*/
enum xj_pkt_ether_type_enum
{
    PKT_ETHER_TYPE_UNKOWN           =0,
	PKT_ETHER_TYPE_IEC61850_MMS     =1,
	PKT_ETHER_TYPE_IEC61850_GOOSE   =2,
	PKT_ETHER_TYPE_IEC61850_SMV     =3,
	PKT_ETHER_TYPE_IEC61850_SMV_91  =4,
	PKT_ETHER_TYPE_IEC61850_PTP_1588=5,
	PKT_ETHER_TYPE_ARP              =6,
	PKT_ETHER_TYPE_IP               =7,
	PKT_ETHER_TYPE_TCP              =8,
	PKT_ETHER_TYPE_UDP              =9,
	PKT_ETHER_TYPE_COTP             =13,
	PKT_ETHER_TYPE_TCP_FIN			    =14,//ÊÍ·ÅTCPÁ´½Ó 
	PKT_ETHER_TYPE_TCP_SYN_REQ		    =15,//ÇëÇó
	PKT_ETHER_TYPE_TCP_SYN_RESP	        =16,//½ÓÊÜÁ´½Ó
	PKT_ETHER_TYPE_TCP_RST			    =17,//ÖØÖÃÁ´½Ó
	PKT_PKT_ETHER_TYPE_TCP_PSH			=18,//ÓÐÓ¦ÓÃÊý¾Ý£¬½ÓÊÕ·½ÐèÒª¾¡¿ì´¦Àí
	PKT_ETHER_TYPE_TCP_ACK			    =19,//±£³ÖÁ¬½Ó
	PKT_ETHER_TYPE_TCP_URG			    =20,//½ô¼±Êý¾Ý
	PKT_ETHER_TYPE_TPKT                 =21,//add by yinzhehong 20130321
};
typedef struct _xj_proto_node
{
	struct _xj_proto_node  *parent_node;       //¸¸½Úµã
	struct _xj_proto_node  *pchildlist;        //×Ó½Úµã¸ùÖ¸Õë
	int                    childlist_size;     //×Ó½Úµã¸öÊý
	int				       start_pos;         //ÔÚÔ´Êý¾ÝÖеÄÆðʼλÖÃ
	int				       length;			  //< Êý¾ÝÕ¼Óó¤¶È
	void*				   pkt_usrview;       //¹©ÍⲿӦÓÃʹÓÃ
	char		           *node_name;        //½ÚµãÃû³Æ
	char                   *node_name_detail; //½ÚµãÃû³ÆÏêϸÃèÊö
	char                   *node_desc;        //½ÚµãÃèÊö
	int                     errortype;        //½Úµã´íÎóÀàÐÍ 
	xj_pkt_ether_type_enum node_type;         //½ÚµãÀàÐÍ 0:Õý³£½Úµã 1:±äλ½Úµã 2:Òì³£½Úµã        
} XJ_PROTO_NODE;
/**************ת»¯ºóµÄÊý¾Ý°ü*******************/
typedef struct _xj_dissect_pkt
{
	xj_pkt_ether_type_enum ether_type;   //±¨ÎÄÀàÐÍ
	int          pkt_length;             //±¨Îij¤¶È
	void*        pkt_data;               //ԭʼÊý¾ÝÖ¡¶ÔÓ¦Ö¸Õë
	int          utc_s;                  //utcÃë
	int          utc_ms;                 //utcºÁÃë
	XJ_PROTO_NODE * pprototreelist;      //ЭÒéÊ÷
	int           prototreelist_size;    //ЭÒéÊ÷²ã´Î
	int           prototreelist_app_seq; //ÓÐЧӦÓòãµÄ²ãºÅ
	char         mac_src[18];            //·¢ËͶËMACµØÖ·
	char         mac_dst[18];            //½ÓÊÕ¶ËMACµØÖ·
	char         ip_src[18];             //·¢ËͶËIPµØÖ·
	char         ip_dst[18];             //½ÓÊÕ¶ËIPµØÖ·
	int          port_src;               //·¢ËͶ˶˿Ú
	int          port_dst;               //½ÓÊն˶˿Ú
	
}XJ_DISSECT_PKT;

typedef struct _TS_PCAP_HEADER {
	unsigned int    Magic;
	unsigned short	MajorVersion;	/* Ö÷°æ±¾ºÅ */
	unsigned short	MinorVersion;	/* ¸±°æ±¾ºÅ */
	unsigned int	ThisZone;	    /* ÇøÓòʱ¼ä£¬32λ£¬Î´Óã¬Ä¬ÈÏΪ0 */
	unsigned int	Sigfigs;	    /*¾«È·Ê±¼ä´Á£¬32λ £¬Î´Óã¬Ä¬ÈÏΪ0Öµ*/
	unsigned int	SnapLen;	    /* Ëù×¥»ñµÄÊý¾Ý°ü×î´ó³¤¶È*/
	unsigned int	Network;	    /* Á´Â·²ãÀàÐÍ */
	_TS_PCAP_HEADER()
	{
		Magic = PCAP_MAGIC;
		MajorVersion = 2;
		MinorVersion = 4;
		ThisZone = 0;
		Sigfigs = 0;
		SnapLen = 0x00010000;
		Network = 1;
	}
}TS_PCAP_HEADER;

/**********ʱ¼ä´Á***********/
typedef struct _TS_TIMEVAL
{
	unsigned int GmtTime;//Ãë¼Æʱ 1970ÄêºóµÄÃë
	unsigned int us;     //΢Ãë¼Æʱ ¿ÉÊÜÍ·½á¹¹ÖеÄSigfigsÏÞÖÆ£¬¾«¶ÈΪ΢Ãë»òÕßÄÉÃë
	_TS_TIMEVAL()
	{
		GmtTime = 0;
		us      = 0;
	}
	
}TS_TIMEVAL;

/**********°üÍ·****************/
typedef struct _TS_PCAP_PKTHDR{
	TS_TIMEVAL ts;	/* time stamp */
	unsigned int caplen;	/* length of portion present */
	unsigned int len;	    /* length this packet (off wire) */
	_TS_PCAP_PKTHDR()
	{
		caplen = 0;
		len    = 0;
	}
}TS_PCAP_PKTHDR;

//½á¹¹¶¨Òå ½âÎöÍê³ÉºóµÄÎļþ¸ÅÒª£¬Ò»°ãΪͳ¼ÆÐÅÏ¢
typedef struct CAPPARSERINFO
{
	char cparserfilename[256];    //capÎļþÃû³Æ
	char crecoriedname[64];        //¼Ç¼װÖÃ
	char crecorportname[64];       //¼Ç¼¶Ë¿ÚÃû³Æ
	int  crecordframetype;         //¼Ç¼Êý¾ÝÀàÐÍ£ºÊ¹ÓÃͬӦÓñ¨ÎÄÀàÐÍ
	int  napppackages;             //¼Ç¼×Ü°üÊý
	int  nappmmspackages;          //mms°üÊý
	int  nappgoosepackages;        //goose°üÊý
	int  napp92packages;           //9-2°üÊý
	int  napp91packages;           //9-1°üÊý
	int  napparppackages;          //arp°üÊý
    int  nappbroadcastpackages;    //¹ã²¥°üÊýÄ¿
	int  nappotherpackages;        //ÆäËüÓ¦Óðü
	int  nconnects;                 //ÓÐЧÁ¬½ÓÊý£ºÖ¸Á½¸öiedÖ®¼ä´æÔÚ61850±¨ÎĽ»»¥£¬º¬¹ã²¥
	char cstarttimestamp[64];       //¼¿ªÊ¼Ê±¼ä   1970ÄêÒÔºóµÄÃë º¬ºÁÃë
	char cendtimestamp[64];         //¼Ç¼½áÊøʱ¼ä   1970ÄêÒÔºóµÄÃë º¬ºÁÃë
	unsigned long   lTotalCapLenth; //±¾Îļþ×Ö½ÚÊý
	double ftime_lastpk_2_first;      //×îºóÒ»Ö¡±¨ÎÄÓë²ÉÑùÎļþÖеÚÒ»Ö¡µÄʱ¼ä²î
	int ntime1588packages;           //1588
	int  napptcppackages;          //TCP
	int  nappudppackages;          //UDP
	//³õʼ»¯
	CAPPARSERINFO()
	{
		memset(cparserfilename,'\0',sizeof(cparserfilename));
		memset(crecoriedname,'\0',sizeof(crecoriedname));
		memset(crecorportname,'\0',sizeof(crecorportname));
		crecordframetype      = 10;//»ìºÏ
		napppackages          = 0;
		nappmmspackages       = 0;
		nappgoosepackages     = 0;
		napp92packages        = 0;
		napp91packages        = 0;
		napparppackages       = 0;
		nappbroadcastpackages = 0;
		nappotherpackages     = 0;
		ntime1588packages     = 0;
		napptcppackages       = 0;
		nappudppackages       = 0;
		nconnects             = 0;
		memset(cstarttimestamp,'\0',sizeof(cstarttimestamp));
		memset(cendtimestamp,'\0',sizeof(cendtimestamp));
		lTotalCapLenth = 0;
		ftime_lastpk_2_first = 0.0;
	}
}_CAPPARSERINFO;

struct CAPMSGGININFO;

//ÁÐ±í¶¨Òå
typedef std::map <int, CAPMSGGININFO*>	MAP_CAPMSGINFO;//ÐÅÏ¢°ü°üÍ·

typedef struct CAPMSGGININFO
{
	CAPMSGGININFO*               pPreCapMsg; //ͬһÁ´Â·ÖеÄÉÏÒ»Ö¡
	void*                        pcapconnect; //±¨ÎÄËùÊôÁ´Â·£¬ÒòΪ±¨ÎĽṹûÓÐÉùÃ÷£¬´æÒ»¸övoid*Ö¸Õë
	
	int nseq;                           //±àºÅ£¬½çÃæ×ÔÓÃ
	int nnum;                           //ÔÚÎļþÖеļǼÐòºÅ
	int  nlen;					        //±¨Îij¤¶È
	int  ncap_len;				        //±¨ÎļǼ³¤¶È
	char*           csourceinfo;        //ԭʼÊý¾Ý
	int             nsourceinfo_length; //ԭʼÊý¾Ý³¤¶È
	unsigned int    nseconds_utc_tmstamp;//±¨ÎÄʱ±ê´Á£¬1970ÄêºóµÄÃë
	unsigned int    nus_tmstamp;         //±¨ÎÄʱ±ê´Á  nseconds_utc_tmstamp.΢Ãë  
	double ftime_delta;            //ÓëÉÏÒ»Ö¡±¨ÎĵÄʱ¼ä²î 1970ÄêÒÔºóµÄÃë º¬ºÁÃë
	double ftime_delta_capconnect; //±¾Á´Â·ÖÐÓëÉÏÒ»Ö¡µÄʱ¼ä²î 1970ÄêÒÔºóµÄÃë º¬ºÁÃë
	double ftime_relative;          //Óë¼Ç¼ÎļþÖеĵÚÒ»Ö¡±¨ÎÄ»òÕß»ù׼ʱ¼äµÄʱ¼ä²î,µ¥Î»ºÁÃë
	double ftime_relative_capconnect;//Óë±¾Á´Â·ÖеĵÚÒ»Ö¡±¨ÎÄ»òÕß»ù׼ʱ¼äµÄʱ¼ä²î,µ¥Î»ºÁÃë
	char csrc_mac[32];         //±¨ÎÄ·¢ËͶËmacµØÖ··û 00:1f:16:24:f2:0c
	char cdst_mac[32];            //±¨ÎĽÓÊÕ¶ËmacµØÖ·
	int nsrc_port;               //±¨ÎÄ·¢ËͶ˿ںÅ
	int ndst_port;               //±¨ÎĽÓÊն˿ںÅ
	int  napptype;				  //Ó¦Óò㱨ÎÄÀàÐÍ mms=1,goose=2,9-2=3,9-1=4,ÆäËü=0£¬ÔÚ³£Á¿ÖÐÔ¤¶¨Òå
	int napptpye_type;           //Ó¦Óò㱨ÎÄϸ·ÖµÄÀàÐÍ£¬±ÈÈçMMSµÄ·þÎñÀàÐ͵È
	//Èç¹ûֵΪ0x88ba ÔñΪ²ÉÑù
	int napp_id;			      //smv¡¢gooseµÄÓ¦ÓñàºÅ
	char csrc_ip[18];             //±¨ÎÄ·¢ËͶËipµØÖ··û  100.100.150.103
	char cdst_ip[18];             //±¨ÎĽÓÊÕ¶ËipµØÖ·
	char ccontent[128];			  //±¨ÎĸÅÒªÄÚÈÝ£º´ý¶¨
	int nHeadChkgood;			  //±¨ÎÄͷУÑéÊÇ·ñÕýÈ·£¬1£ºÕýÈ· 0£ºÒì³£
	int  nAppConetentGood;        //Ó¦Óò㱨ÎÄÊÇ·ñÕýÈ· 1£º±êʶÕýÈ· 0£ºÒì³£
	//	char ciedname[64];            //±¨ÎĶÔÓ¦µÄiedµÄÃû×Ö
	void*          pparserdstruct;          //Ó¦ÓÃÊý¾Ýèå½âÎöºóµÄÏêϸ֡
	void*           pap_analyzed_info;       //±¨ÎÄ·ÖÎö½á¹û
	void*           pap_anlyzed_info_connect;//±¨ÎÄ·ÖÎöÉÏÏÂÎÄ
	bool            berroranalyzedgoose;     //GOOSE´íÎó
	bool            beventanalyzedgoose;     //GOOSEʼþ¡¢MMSÖеı¨¸æ
	bool            berroranalyzedsmv;       //SMV´íÎó
	bool            berroranalyzedmms;       //MMS´íÎó
	int             n1588seqid;			     //1588ÖеÄÐòºÅ
	int             n1588portid;		      //1588ÖеĶ˿ںÅ
	XJ_DISSECT_PKT* pxj_dissect_pkt;          //½âÎöºóµÄÊý¾Ý°ü
	bool            blastcotpunit;            //¶àÖ¡´«ÊäµÄ×îºóÒ»Ö¡  add by yinzhehong 20130315
	bool            btcppsh;                 //TCPÊÇ·ñÓÐÓ¦Óñ¨ÎÄ´«Êä
	MAP_CAPMSGINFO  map_cotplist;            //¶àÖ¡´«Êäʱ¶ÓÁÐ
	char*           csourceinfo_cotp;        //¶àÖ¡±¨ÎÄ´«Êäʱ´ó³¤Ö¡
	int             nsourceinfo_cotp_length; //¶àÖ¡±¨ÎÄ´«Êäʱ´ó³¤Ö¡³¤¶È
	unsigned int    npkt_offset_incapfile;   //±¨ÎÄÔÚÎļþÖеÄλÖÃ
	//³õʼ»¯
	CAPMSGGININFO()
	{
		pPreCapMsg    = NULL;
		n1588portid   = 0;
		n1588seqid    = 0;
		pcapconnect   = NULL;
		nseq          = 0;
		nnum          = -1;
		nlen          = 0;
		ncap_len      = 0;
		napp_id       = -1;
		ftime_relative = 0.0;
		ftime_relative_capconnect = 0.0;
		ftime_delta    = 0.0;
		ftime_delta_capconnect = 0.0;
		memset(csrc_mac,'\0',sizeof(csrc_mac));
		memset(cdst_mac,'\0',sizeof(cdst_mac));
		
		nsrc_port     = 0;
		ndst_port     = 0;
		napptype      = 0;
		napptpye_type = 0;
		memset(csrc_ip,'\0',sizeof(csrc_ip));
		memset(cdst_ip,'\0',sizeof(cdst_ip));
		
		memset(ccontent,'\0',sizeof(ccontent));
		nHeadChkgood         = 1;
		nAppConetentGood     = 1;
		//		memset(ciedname,'\0',sizeof(ciedname));
		pparserdstruct  = NULL;
		pap_analyzed_info     = NULL;
		pap_anlyzed_info_connect = NULL;
		berroranalyzedgoose = false;
		berroranalyzedsmv	= false;
		berroranalyzedmms	= false;
		csourceinfo         = NULL;
		nsourceinfo_length  = 0;
		pxj_dissect_pkt     = NULL;
		blastcotpunit       = false;
		btcppsh             = false;
		csourceinfo_cotp    = NULL;
		nsourceinfo_cotp_length = 0;
		beventanalyzedgoose = false;
		nseconds_utc_tmstamp = 0;
		nus_tmstamp          = 0;
		npkt_offset_incapfile= 0;
	}
}_CAPMSGGININFO;

enum ETHER_TYPE
{
	IEC61850_ETHER_TYPE_UNKOWN  =0,
		IEC61850_ETHER_TYPE_MMS     =1,
		IEC61850_ETHER_TYPE_GOOSE   =2,
		IEC61850_ETHER_TYPE_SMV     =3,
		IEC61850_ETHER_TYPE_SMV_91  =4,
		IEC61850_ETHER_TYPE_PTP_1588=5,
		ETHER_TYPE_ARP              =6,
		ETHER_TYPE_IP               =7,
		ETHER_TYPE_TCP              =8,
		ETHER_TYPE_UDP              =9,
		ETHER_TYPE_COTP             =13,
		ETHER_TYPE_TCP_FIN			=14,//ÊÍ·ÅTCPÁ´½Ó 
		ETHER_TYPE_TCP_SYN_REQ		=15,//ÇëÇó
		ETHER_TYPE_TCP_SYN_RESP  	=16,//½ÓÊÜÁ´½Ó
		ETHER_TYPE_TCP_RST			=17,//ÖØÖÃÁ´½Ó
		ETHER_TYPE_TCP_PSH			=18,//ÓÐÓ¦ÓÃÊý¾Ý£¬½ÓÊÕ·½ÐèÒª¾¡¿ì´¦Àí
		ETHER_TYPE_TCP_ACK			=19,//±£³ÖÁ¬½Ó
		ETHER_TYPE_TCP_URG			=20,//½ô¼±Êý¾Ý
		ETHER_TYPE_TPKT             =21,//add by yinzhehong 20130321
};

typedef struct PACKET_STRUCT{
	
	//µ¥Ö¡±¨ÎÄÄÚÈÝÆðʼµØÖ·
	void *pPacket;
	//µ¥Ö¡±¨Îij¤¶È
	int nLen;
	
	unsigned int nAppid;
	
	ETHER_TYPE nEthType;
	
	PACKET_STRUCT()
	{
		pPacket = 0;
		nLen = 0;
		nAppid = 0;
		nEthType = IEC61850_ETHER_TYPE_UNKOWN;
	}
	
}PACKET_STRUCT;

#endif