/************************************************************************* Logs an event *************************************************************************/ void DefaultLogger::logEvent(LPCTSTR message, LoggingLevel level /* = Standard */) { time_t et; time(&et); tm* etm = localtime(&et); if (etm) { // clear sting stream CDuiStringT strbuf; strbuf.Format(_T("%04d/%02d/%02d %02d:%02d:%02d "),1900+etm->tm_year,etm->tm_mon+1,etm->tm_mday,etm->tm_hour,etm->tm_min,etm->tm_sec); // write event type code switch(level) { case Errors: strbuf+= _T("(Error)\t"); break; case Warnings: strbuf+= _T("(Warn)\t"); break; case Standard: strbuf+= _T("(Std) \t"); break; case Informative: strbuf+= _T("(Info) \t"); break; case Insane: strbuf+= _T("(Insan)\t"); break; default: strbuf+= _T("(Unkwn)\t"); break; } strbuf+= message; strbuf+=_T("\n"); if (d_caching) { d_cache.Add(LOGRECORD(strbuf, level)); } else if (d_level >= level) { if(d_pFile) { // write message fprintf(d_pFile,(LPCSTR)DUI_CT2A(strbuf)); fflush(d_pFile); } } } }
void AnalysePacket() { int fdin; int vlNum = GetiValue("vlannum"); char* file = GetcValue("readfile"); LOGRECORD(DEBUG, "Analyse Packet start..."); PktStrucInit(vlNum); memset(packet,0,sizeof(packet)); if((fdin = open(file, O_RDWR)) < 0) { LOGRECORD(ERROR, "open pcap file error"); } if(read(fdin, packet, PCAPHDRLEN) < 0) { LOGRECORD(ERROR, "read pcaphdr error"); } if(htonl(pcap_hdr->magic) != 0xd4c3b2a1) { LOGRECORD(ERROR, "file paratarn error"); } while(read(fdin, packet, PKTHDRLEN) > 1) { if(read(fdin, packet+PKTHDRLEN, pkt_hdr->len) < 0) { LOGRECORD(ERROR, "read packethdr error"); exit(0); } ParameterUpadte(); if(htons(mac_hdr->pro2) == VLAN) { RecordStatisticsInfo(EMPRO_VLAN); PktStrucInit(1); if(htons(vlan_hdr1->type) == VLAN) { RecordStatisticsInfo(EMPRO_QinQ); PktStrucInit(2); } } if(htons(mac_hdr->pro2) == ARP) { RecordStatisticsInfo(EMPRO_ARP); } else if(htons(mac_hdr->pro2) == IPv4 || htons(vlan_hdr1->type) == IPv4 \ || htons(vlan_hdr2->type) == IPv4) { // Layer 3 RecordStatisticsInfo(EMPRO_IPv4); if(ip4_hdr->protocol == UDP) { // Layer 4 RecordStatisticsInfo(EMPRO_UDP); } else if(ip4_hdr->protocol == TCP) { // Layer 4 RecordStatisticsInfo(EMPRO_TCP); } else if(ip4_hdr->protocol == ICMPv4) { // Layer 4 RecordStatisticsInfo(EMPRO_ICMPv4); } } /* else if(htons(mac_hdr->pro2) == IPv6) { // Layer 3 RecordStatisticsInfo(EMPRO_IPv6); if(ip6_hdr->protocol == TCP) { // Layer 4 RecordStatisticsInfo(EMPRO_TCP); } else if(ip6_hdr->protocol == UDP) { // Layer 4 RecordStatisticsInfo(EMPRO_UDP); } else if(ip6_hdr->protocol == ICMPv6) { // Layer 4 RecordStatisticsInfo(EMPRO_ICMPv6); } else { RecordStatisticsInfo(EMPRO_UNKNOWN); } } */ }// end of while close(fdin); DisplayStatisticsResults(); LOGRECORD(DEBUG, "Analyse Packet finished..."); }