// Initialise the page when displayed
BOOL PageCOM::OnSetActive()
{
	// Build the list of COM ports
	comboCOMPort.ResetContent();
	for (POSITION port = listPorts.GetHeadPosition(); port;)
	{
		comboCOMPort.AddString(listPorts.GetNext(port));
	}

	// Modify the current selection if appropriate
	valueCOMPort = FindUnique(listPorts, valueCOMPort, !GetSheet()->automatic);

	// Pretent that the currently selected baud rate is available
	comboBaud.ResetContent();
	comboBaud.AddString(valueBaud);

	// Ensure that the controls reflect the current selection
	UpdateData(false);

	// Enable the appropriate controls
	OnPortChanged();
	
	// Perform any other initialisation required
	return DFUPage::OnSetActive();
}
void packet_handler(u_char *dumpfile, const struct pcap_pkthdr *header, const u_char *pkt_data)
{
	const struct sniff_ethernet *ethernet;  /* The ethernet header [1] */
	struct sniff_ethernet *ethaddr;

	const struct sniff_ip *ip;              /* The IP header */
	const struct sniff_tcp *tcp;            /* The TCP header */
	int size_ip;
	int size_tcp;
	int size_udp;

	printf("\nepoch time is %ld:%ld (%ld)\n",header->ts.tv_sec, header->ts.tv_usec, header->len);
	size[count]=header->len;
	//strcpy(ethaddr->ether_shost, ether_ntoa(ethernet->ether_shost));
	//strcpy(ethaddr->ether_dhost, ether_ntoa(ethernet->ether_dhost));
	//printf("source: %s \n",ethaddr->ether_shost );
    	//printf("dest: %s \n",ethaddr->ether_dhost);

	ip = (struct sniff_ip*)(pkt_data + 14);
	size_ip = IP_HL(ip)*4;
	printf("size of ip %d   ", size_ip);
	tcp = (struct sniff_tcp*)(pkt_data + 14 + size_ip);
	size_tcp = TH_OFF(tcp)*4;
	printf("size of tcp %d", size_tcp);
	struct udphdr *udph = (struct udphdr*)(pkt_data + 14 + size_ip);
	if (size_ip < 20)
	{

		ip = (struct sniff_ip*)(pkt_data + 12+14);
		//printf("   * Invalid IP header length: %u bytes\n", size_ip);
		fprintf(stdout," prot %u \n ",ip->ip_p);
		printf("       To: %s\n", inet_ntoa(ip->ip_src));
		ip = (struct sniff_ip*)(pkt_data + 12);
		printf("        From: %s\n", inet_ntoa(ip->ip_dst));

		FindUnique(ip->ip_src);
		FindUnique(ip->ip_dst);

		count++;
		printf("packet number is %d\n",count);
		printf("Start time and date of the capture is: %s",ctime(&header->ts.tv_sec) );
		return;
	}

	/* print source and destination IP addresses */
	else
	{
		if(ip->ip_p==6)
		{
		printf("   Src port: %d\n", ntohs(tcp->th_sport));
		printf("   Dst port: %d\n", ntohs(tcp->th_dport));
			/*if((tcp->th_flags==TH_ACK))
			{
			//printf("flag %X\n",tcp->th_flags);
			ack++;
			}
			if((tcp->th_flags== TH_RST))
			{
			//printf("flag %X\n",tcp->th_flags);
			rst++;
			}
			if((tcp->th_flags==TH_SYN))
			{
			//printf("flag %X\n",tcp->th_flags);
			syn++;
			}
			if((tcp->th_flags==TH_PUSH))
			{
			//printf("flag %X\n",tcp->th_flags);
			psh++;
			}*/
		//printf("   Flag: RST\n");
		}

		if(ip->ip_p==17)
		{
		printf("   Src port: %d\n", ntohs(udph->uh_sport));
		printf("   Dst port: %d\n", ntohs(udph->uh_dport));
		printf("   checksum %X\n", ntohs(udph->uh_sum));
		printf("   length %d\n",udph->uh_ulen);
		}
	fprintf(stdout," prot %u \n ",ip->ip_p);
	printf("       To: %s\n", inet_ntoa(ip->ip_src));
	printf("       From: %s\n", inet_ntoa(ip->ip_dst));
	count++;
	printf("packet number is %d\n",count);
	printf("Start time and date of the capture is: %s",ctime(&header->ts.tv_sec) );
	}
}