void main() { int a[10] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}; int i; struct List L; initList(&L, 5); for(i = 0; i < 10; i++){ insertLastList(&L, a[i]); } insertPosList(&L, 11, 48); insertPosList(&L, 1, 64); printf("%d ", getElem(&L, 1)); traverseList(&L); printf("%d ", findList(&L, 10)); updatePosList(&L, 3, 20); printf("%d ", getElem(&L, 3)); traverseList(&L); deleteFirstList(&L); deleteFirstList(&L); deleteLastList(&L); deleteLastList(&L); deletePosList(&L, 5); ;deletePosList(&L, 7); printf("%d ", sizeList(&L)); printf("%d ", emptyList(&L)); traverseList(&L); clearList(&L); return 0; }
void printPcap(void * data,size_t size,pcap_header *ph){ unsigned short iPos = 0; if (data==NULL) { return; } if (ph==NULL) { return; } Flow myflow; FramHeader_t *ether; IPHeader_t *iph; TCPHeader_t *tcph; ether=(struct FramHeader_t*)data; //不是ipv4,返回 if (ether->FrameType != 0x0008) return; iph=(struct IPHeader_t*)(data+14); //不是TCP、UDP,返回 if (iph->Protocol != 6 && iph->Protocol != 17) return; tcph=(struct TCPHeader_t*)(data+14+(((iph->Ver_HLen) & 0x0F) << 2)); printf("smac %02x:%02x:%02x:%02x:%02x:%02x\r\n",*(ether->SrcMAC),*(ether->SrcMAC+1), *(ether->SrcMAC+2),*(ether->SrcMAC+3),*(ether->SrcMAC+4),*(ether->SrcMAC+5)); printf("dmac %02x:%02x:%02x:%02x:%02x:%02x\r\n",*(ether->DstMAC),*(ether->DstMAC+1), *(ether->DstMAC+2),*(ether->DstMAC+3),*(ether->DstMAC+4),*(ether->DstMAC+5)); printf("以太网类型:%04x\n",ntohs(ether->FrameType)); struct in_addr ip; ip.s_addr = iph->SrcIP; printf("原IP:%s",inet_ntoa(ip)); ip.s_addr = iph->DstIP; printf("目的ip:%s",inet_ntoa(ip)); myflow.DstIP=iph->DstIP; myflow.SrcIP=iph->SrcIP; myflow.Protocol=iph->Protocol; myflow.DstPort=tcph->DstPort; myflow.SrcPort=tcph->SrcPort; overtime_flow_handler (pList, ph->ts); if(findflow(pList,myflow,ph)==0)//新的流 { // myflow.cs.time_len.ts=ph->ts; //myflow.cs.time_len.len=ph->len; insertLastList(&pList,myflow,ph); } /* if(findflow(pList,myflow,ph)==1)//CS流 { // insertLastList(&pList,myflow); } if(findflow(pList,myflow,ph)==2)//SC流 { //insertLastList(&pList,myflow); }*/ /* for (iPos=0; iPos < size/sizeof(unsigned short); iPos++) { unsigned short a = ntohs( *((unsigned short *)data + iPos ) ); if (iPos%8==0) printf("\n"); if (iPos%4==0) printf(" "); printf("%04x~",a); }*/ //printList(pList); printf("\n============\n"); }