Пример #1
0
void UpdateStats (int PacketSlot) {
	static int	PacketSec=0;
	static int	TCPSec=0;
	static int	UDPSec=0;
	static int	LastTime=0;
	void*		data;

	pthread_mutex_lock (&StatsMutex);

	PacketSec++;

	if (GetDataByID(PacketSlot, TCPDecoderID, &data))
		TCPSec++;
	else if (GetDataByID(PacketSlot, UDPDecoderID, &data))
		UDPSec++;

	if (Globals.Packets[PacketSlot].tv.tv_sec != LastTime){
		Globals.PacketsPerSec = PacketSec;
		Globals.TCPPerSec = TCPSec;
		Globals.UDPPerSec = UDPSec;

		PacketSec = 0;
		TCPSec = 0;
		UDPSec = 0;

		LastTime = Globals.Packets[PacketSlot].tv.tv_sec;
	}

	pthread_mutex_unlock (&StatsMutex);
}
Пример #2
0
/******************************************
* Reroute this IP
******************************************/
int BNSAction(int RuleNum, int PacketSlot, void* Data){
	ActionBNSRec*		data;
	PacketRec*			p;
	IPData*				IP;
	char				Message[512];
	
	DEBUGPATH;

	if (!Data){
#ifdef DEBUG
		printf("I must have somewhere to route to\n");
#endif	
		return FALSE;
	}
		
	if (!GetDataByID(PacketSlot, IPDecoderID, (void**)&IP)){
		printf("This packet has no IP header\n");
		return FALSE;
	}
	
	p=&Globals.Packets[PacketSlot];
	data=(ActionBNSRec*)Data;

	if (IsInList(data->GreenList, ntohl(IP->Header->saddr))){
#ifdef DEBUG
		printf("This is in the green list\n");
#endif	
		return FALSE;
	}
						
	snprintf(Message, 512,"Rerouting %s to Honeypot for %i seconds",inet_ntoa(*(struct in_addr*)&IP->Header->saddr),data->TimeOut);
	LogMessageAllActions(Message);
				
	return AddRangeTime(BNSRerouteList, ntohl(IP->Header->saddr), ntohl(IP->Header->saddr), p->tv.tv_sec+data->TimeOut);
}
Пример #3
0
/******************************************
* Reroute this IP
******************************************/
int RouteSIPAction(int RuleNum, int PacketSlot, void* Data){
	ActionRouteSIPRec*	data;
	PacketRec*			p;
	IPData*				IP;
	
	DEBUGPATH;

	if (!Data){
#ifdef DEBUG
		printf("I must have somewhere to route to\n");
#endif	
		return FALSE;
	}
		
	if (!GetDataByID(PacketSlot, IPDecoderID, (void**)&IP)){
		printf("This packet has no IP header\n");
		return FALSE;
	}
	
	p=&Globals.Packets[PacketSlot];
	data=(ActionRouteSIPRec*)Data;

	if (IsInList(data->LocalList, ntohl(IP->Header->saddr))){
#ifdef DEBUG
		printf("This is in the local list\n");
#endif	
		return FALSE;
	}
			
	/*check to see if we're too fast*/
			
			
	return RouteSIPAdd(IP->Header->saddr, data->Interface, Globals.Packets[PacketSlot].tv.tv_sec+data->Timeout);
}
Пример #4
0
HSDouble CHSFinanceData::CAPITAL(CodeInfo* pCode)
{
	if( pCode == NULL )
		return hx_DefMaxValues;

	HSDouble dRet = hx_DefMaxValues;

	if( pCode->IsType(KIND_STOCKB) )
		dRet = GetDataByID(COLUMN_CAPITALIZATION_B);
	else if( MakeIndexMarket( pCode->m_cCodeType ) )
		dRet = 0;
	else //if( pCode->IsType(KIND_STOCKA) ) 
		dRet = GetDataByID(COLUMN_CAPITALIZATION_PASS_A);	

	if((long)dRet != hx_DefMaxValues )
		dRet *= 100;

	return dRet;
}
Пример #5
0
/******************************************
* Apply the Test with collapsed rules
******************************************/
int TestTCPFlags(int PacketSlot, TestNode* Nodes){
	unsigned short 		TCPFlags;
	TCPFlagsData*			t;
	TCPData*			TData;
	int					i;
	PacketRec*			p;

	DEBUGPATH;
	
	if (!Nodes) return FALSE;
	
	p=&Globals.Packets[PacketSlot];
	
	/*get the flags out of the tcp header*/
	if (!GetDataByID(PacketSlot, TCPDecoderID, (void**)&TData)){
		printf("Failed to get TCP header data\n");
		return FALSE;
	}

	TCPFlags=ntohs(TData->Header->dest);
	
	if (i==-1){
#ifdef DEBUG	
		printf("Couldn't find the tcp header\n");
#endif		
		return FALSE;
	}

#ifdef DEBUGMATCH
	printf("**************************************\n");
	printf("Before applying tcp flags tests\n");
	for (i=0;i<Globals.NumRules;i++)
	if (RuleIsActive(PacketSlot,i))
		printf("Rule %i is active\n",i);
	else
		printf("Rule %i is inactive\n",i);
	printf("**************************************\n");
#endif	
	
	t=TCPFlagsHead;
	while (t){
		if ( (t->Fin==0) || (t->Fin==1 && TData->Header->fin) || (t->Fin==-1 && !TData->Header->fin))
		if ( (t->Syn==0) || (t->Syn==1 && TData->Header->syn) || (t->Syn==-1 && !TData->Header->syn))
		if ( (t->Rst==0) || (t->Rst==1 && TData->Header->rst) || (t->Rst==-1 && !TData->Header->rst))
		if ( (t->Psh==0) || (t->Psh==1 && TData->Header->psh) || (t->Psh==-1 && !TData->Header->psh))
		if ( (t->Ack==0) || (t->Ack==1 && TData->Header->ack) || (t->Ack==-1 && !TData->Header->ack))
		if ( (t->Urg==0) || (t->Urg==1 && TData->Header->urg) || (t->Urg==-1 && !TData->Header->urg))
		if ( (t->Ece==0) || (t->Ece==1 && TData->Header->ece) || (t->Ece==-1 && !TData->Header->ece))
		if ( (t->Cwr==0) || (t->Cwr==1 && TData->Header->cwr) || (t->Cwr==-1 && !TData->Header->cwr)){
			/*mark these rules as inactive*/
			NotAndBitFields(p->RuleBits, t->RuleBits, p->RuleBits, Globals.NumRules);
		}
		t=t->Next;
	}
		
#ifdef DEBUGMATCH
	printf("**************************************\n");
	for (i=0;i<Globals.NumRules;i++)
	if (RuleIsActive(PacketSlot,i))
		printf("Rule %i is active\n",i);
	else
		printf("Rule %i is inactive\n",i);
	printf("**************************************\n");
#endif	
		
	return TRUE;
}
Пример #6
0
void  CHSCalculate::GetTextByID(int nID,  CurrentFinanceData* pFinanceData, char strText[64])
{
	if (pFinanceData == NULL)
	{
		memset(strText, 0, STR_LENTH);
		return;
	}

	float fValue = 0.0;
	double dValue = 0.0;
	CString str = "";
	fValue = GetDataByID(nID, pFinanceData);

	if (nID == COLUMN_FINANCE_REPORT_DATE)
	{
		fValue = GetDataByID(0, pFinanceData);
		if (abs(fValue - 1) < 0.0001)
			str = _T("一季度");
		else if (abs(fValue - 2) < 0.0001)
			str = _T("二季度");
		else if (abs(fValue - 3) < 0.0001)
			str = _T("三季度");
		else
			str = _T("四季度");
	}
	else
	{
		int	nUnit	= 10000;	
		CString	strUnit;
		AutoAdjustUnit(nID, fValue, strUnit, &nUnit);

		if ( !fValue )
		{
			str.Empty();
		}
		else
		{
			dValue = fValue / nUnit;
			str.Format(_T("%16.5f"), dValue);

			//////////////////////////////////////////////////////////////////////////
			//这里根据实际情况动态格式化文本
			TCHAR	ch;
			/*	首先去除字符串中后面可能存在的一连串的0字符*/
			str.TrimLeft();
			int	n	= str.GetLength() - 1;
			while(1)
			{
				ch	= str[n];
				if ( ch == '0' )
				{
					//	用空格代替
					str.SetAt(n,' ');
					n --;
				}
				else
				{
					//	去掉右边的一连串空格
					str.TrimRight();
					break;
				}
			}
			//	如果文本变成了“0.”这样的格式,直接用空格代替
			if ( str == _T("0."))
			{
				str.Empty() ;
			}
			//	如果文本串中小数点后面的数据全部是空格,则去调
			//	多余的小数点
			else if ( str[str.GetLength() - 1] == _T('.'))
			{
				str	= str.Left(str.GetLength() - 1);
			}
			//	如果小数点后面的长度太长,那就取到小数点后面第二位为止即可。
			if ( dValue * 100 > 1 || dValue * 100 < -1 )
			{
				int	nDot	= str.Find(_T('.'));
				if ( nDot != -1 )
				{
					//每股收益等每股数据时,保留4位小数--------------------
					if ((COLUMN_FINANCE_PER_INCOME == nID) || (COLUMN_FINANCE_PER_UNPAID == nID) ||
						(COLUMN_FINANCE_PER_ASSETS == nID) || (COLUMN_FINANCE_ADJUST_PER_ASSETS == nID) )
						str	= str.Left(nDot + 5);
					else
						str	= str.Left(nDot + 3);
				}
				//	如果新得到的文本为XXX.00格式则去处后面的.00
				if ( str.Right(3) == _T(".00"))
				{
					str	= str.Left(str.GetLength() - 3);
				}
			}
		}
		if (dValue && !str.IsEmpty() )
		{
			str	+= strUnit;
		}
	}
	strncpy(strText, str.GetBuffer(), min(str.GetLength()+1, STR_LENTH));
}