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 process_packet(unsigned char* buffer, int size) { struct iphdr *ip_header = (struct iphdr*)(buffer + sizeof(struct ethhdr)); if (ip_header->protocol == 6) { ++total; print_tcp_packet(buffer, size); } printf("Total Packets: %d\r", total); }
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(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); }