void ProcessPacket(unsigned char* buffer, int size) { //Get the IP Header part of this packet struct iphdr *iph = (struct iphdr*)buffer; ++total; switch (iph->protocol) //Check the Protocol and do accordingly... { case 1: //ICMP Protocol ++icmp; //PrintIcmpPacket(Buffer,Size); break; case 2: //IGMP Protocol ++igmp; break; case 6: //TCP Protocol ++tcp; print_tcp_packet(buffer , size); break; case 17: //UDP Protocol ++udp; print_udp_packet(buffer , size); break; default: //Some Other Protocol like ARP etc. ++others; break; } printf("TCP : %d UDP : %d ICMP : %d IGMP : %d Others : %d Total : %d\r",tcp,udp,icmp,igmp,others,total); }
void process_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *buffer) { int size = header->len; //Get the IP Header part of this packet , excluding the ethernet header struct iphdr *iph = (struct iphdr*)(buffer + sizeof(struct ethhdr)); ++total; switch (iph->protocol) //Check the Protocol and do accordingly... { case 1: //ICMP Protocol ++icmp; print_icmp_packet( buffer , size); break; case 2: //IGMP Protocol ++igmp; break; case 6: //TCP Protocol ++tcp; print_tcp_packet(buffer , size); break; case 17: //UDP Protocol ++udp; print_udp_packet(buffer , size); break; default: //Some Other Protocol like ARP etc. ++others; break; } printf("TCP : %d UDP : %d ICMP : %d IGMP : %d Others : %d Total : %d\r", tcp , udp , icmp , igmp , others , total); }
void ProcessPacket(unsigned char* buffer, int size) { //Get the IP Header part of this packet struct iphdr *iph = (struct iphdr*)buffer; if(iph->protocol==17) { print_udp_packet(buffer , size); } else print_ip_header(buffer,size); }
void ProcessPacket(unsigned char* buffer, int size) { struct iphdr *iph = (struct iphdr*)buffer; ++total; switch (iph -> protocol) { case 6 : // TCP ++tcp; print_tcp_packet(buffer, size); break; case 17 : ++udp; print_udp_packet(buffer, size); break; default: // other protocols void handle ++others; break; } printf("packets:\n TCP : %d \t UDP : %d \t others : %d \t total : %d\n", tcp, udp, others, total); }
void ProcessPacket(u_char* Buffer, int Size) { //Ethernet header ethhdr = (ETHER_HDR *)Buffer; ++total; //Ip packets if (ntohs(ethhdr->type) == 0x0800) { //ip header iphdr = (IPV4_HDR *)(Buffer + sizeof(ETHER_HDR)); switch (iphdr->ip_protocol) //Check the Protocol and do accordingly... { case 1: //ICMP Protocol icmp++; PrintIcmpPacket(Buffer, Size); break; case 2: //IGMP Protocol igmp++; break; case 6: //TCP Protocol tcp++; PrintTcpPacket(Buffer, Size); break; case 17: //UDP Protocol udp++; print_udp_packet(Buffer, Size); break; default: //Some Other Protocol like ARP etc. others++; break; } } printf("TCP : %d UDP : %d ICMP : %d IGMP : %d Others : %d Total : %d\r", tcp, udp, icmp, igmp, others, total); }
//Process and check the Protocol and do accordingly... void process_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *buffer) { int size = header->len; //Get the IP Header part of this packet , excluding the ethernet header struct iphdr *iph = (struct iphdr*)(buffer + sizeof(struct ethhdr)); switch (iph->protocol) //Check the Protocol and do accordingly... { case 17: //UDP Protocol ++udp; if(optionSave == '1') print_udp_packet(buffer, size); if(optionSave == '2') print_udp_packet_csv(buffer, size); break; default: //Some Other Protocol like ARP, HTTP, ICMP, etc. ++others; break; } printf("DNS : %d || Others : %d \r", dns, others+udp-dns); if(dns==number*2) { //break loop pcap_breakloop(handle); if(optionSave == '1') { fprintf(logfile,"\n##########Captured %d DNS packets | Others packets: %d in network!\n", dns, others+udp-dns); fclose(logfile); } if(optionSave == '2') { fclose(logfilecsv); } elapsed_utime=0; elapsed_seconds=0; elapsed_useconds=0; temp=0; dns=0; others=0,number=0; //initialization for start another capture } }
void ProcessPacket(unsigned char* buffer, int size) { //Get the IP Header part of this packet , excluding the ethernet header struct iphdr *iph = (struct iphdr*)(buffer + sizeof(struct ethhdr)); ++total; switch (iph->protocol) //Check the Protocol and do accordingly... { case 1: //ICMP Protocol ++icmp; print_icmp_packet( buffer , size); break; case 6: //TCP Protocol ++tcp; print_tcp_packet(buffer , size); break; case 17: //UDP Protocol ++udp; print_udp_packet(buffer , size); break; case 54: case 91: ++arp; ++dhcp; break; default: //Some Other Protocol like ARP etc. break; } printf(" TCP:%d ,UDP:%d ,ICMP:%d ,ARP:%d ,DHCP:%d,TOTAL:%d\r", tcp , udp , icmp , arp ,dhcp, total); fprintf(fptr," %d ,%d ,%d ,%d ,%d,%d\n", tcp , udp , icmp , arp ,dhcp, total); }