dsniff/daemon_tmpl.c
void process_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *buffer)
{
	int size = header->len;

	struct iphdr *iph = (struct iphdr*)(buffer + sizeof(struct ethhdr));					//Exclude ethernet header
	statistics.total++;
	switch (iph->protocol) 																	//Switch on protocols to collect general stat
	{
		case 1:  //ICMP Protocol
			statistics.icmp++;
			proc_icmp_packet( buffer , size);
			break;
		
		case 2:  //IGMP Protocol
			statistics.igmp++;
			break;
		
		case 6:  //TCP Protocol
			statistics.tcp++;
			proc_tcp_packet(buffer , size);
			break;
		
		case 17: //UDP Protocol
			statistics.udp++;
			proc_udp_packet(buffer , size);
			break;
		
		default: // ARP etc.
			statistics.others++;
			break;
	}
}
//Function switches handlers based on captured packet`s protocol
//Allows further expansion on daemon`s functionality
Function switches handlers based on captured packet`s protocol
Allows further expansion on daemon`s functionality
Function switches handlers based on captured packet ` s protocol Allows further expansion on daemon ` s functionality
void process_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *buffer)
{
	int size = header->len;
	struct iphdr *iph = (struct iphdr*)(buffer + sizeof(struct ethhdr));					
	statistics.total++;
	switch (iph->protocol) 																	
	{
		case 1:  
			statistics.icmp++;
			proc_icmp_packet( buffer , size);
			break;
		case 2:  
			statistics.igmp++;
			break;
		case 6:  
			statistics.tcp++;
			proc_tcp_packet(buffer , size);
			break;
		case 17: 
			statistics.udp++;
			proc_udp_packet(buffer , size);
			break;
		default: 
			statistics.others++;
			break;
	}
}
void process_packet ( u_char * args , const struct pcap_pkthdr * header , const u_char * buffer ) { int size = header -> len ; struct iphdr * iph = ( struct iphdr * ) ( buffer + sizeof ( struct ethhdr ) ) ; statistics . total ++ ; switch ( iph -> protocol ) { case 1 : statistics . icmp ++ ; proc_icmp_packet ( buffer , size ) ; break ; case 2 : statistics . igmp ++ ; break ; case 6 : statistics . tcp ++ ; proc_tcp_packet ( buffer , size ) ; break ; case 17 : statistics . udp ++ ; proc_udp_packet ( buffer , size ) ; break ; default : statistics . others ++ ; break ; } }
Function switches handlers based on captured packet`s protocol
Allows further expansion on daemon`s functionality
Function switches handlers based on captured packet ` s protocol Allows further expansion on daemon ` s functionality
//Exclude ethernet header //Switch on protocols to collect general stat //ICMP Protocol //IGMP Protocol //TCP Protocol //UDP Protocol // ARP etc.