コード例 #1
0
ファイル: winsock2.cpp プロジェクト: CodeAsm/tedabyss
void ProcessPacket(unsigned char* Buffer, int Size)
{
	iphdr = (IPV4_HDR *)Buffer;
	++total;
	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;
			PrintUdpPacket(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);
}
コード例 #2
0
ファイル: main.c プロジェクト: desideri/proyectoRedes
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);
}