コード例 #1
0
ファイル: PortsManager.cpp プロジェクト: fara-ramin/firewall
PortSet PortsManager::GetNowPorts()
{
	PortSet newPorts;

	PMIB_TCPTABLE pTcpTable;
	DWORD dwSize = 0;
	DWORD dwRetVal = 0;
	unsigned short *port_ptr;
	DWORD i;

	/* Get size required by GetTcpTable() */
	if (GetTcpTable(NULL, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
		pTcpTable = (MIB_TCPTABLE *) malloc (dwSize);
	}

	/* Get actual data using GetTcpTable() */
	if ((dwRetVal = GetTcpTable(pTcpTable, &dwSize, 0)) == NO_ERROR) {
		if (pTcpTable->dwNumEntries > 0) {
			for (i=0; i<pTcpTable->dwNumEntries; i++) {
				//addr_ptr = (char *)&pTcpTable->table[i].dwLocalAddr;
				//port_ptr = (unsigned short *)&pTcpTable->table[i].dwLocalPort;
				//addr_ptr = (char *)&pTcpTable->table[i].dwRemoteAddr;
				port_ptr = (unsigned short *)&pTcpTable->table[i].dwRemotePort;
				DWORD state = pTcpTable->table[i].dwState;
				newPorts.insert(Port(*port_ptr, state));
			}
		}
	}
	free(pTcpTable);
	return newPorts;
}
コード例 #2
0
ファイル: cell.cpp プロジェクト: xenia-cjen/atpg
//{{{ PortSet Cell::getNetPorts()
PortSet Cell::getNetPorts(const size_t &i) const {
    PortSet ports;
    if (i >= nets_.size())
        return ports;
    NetSet eqv = getEqvNets(i);
    for (NetSet::iterator it = eqv.begin(); it != eqv.end(); ++it)
        for (size_t i = 0; i < (*it)->getNPort(); ++i)
            ports.insert((*it)->getPort(i));
    return ports;
}
コード例 #3
0
Handle<Value> HoneydProfileBinding::AddPort(const Arguments& args)
{
	if( args.Length() != 7 )
	{
		return ThrowException(Exception::TypeError(String::New("Must be invoked with seven parameters")));
	}

	HandleScope scope;
	HoneydProfileBinding* obj = ObjectWrap::Unwrap<HoneydProfileBinding>(args.This());



	int portSetIndex = cvv8::CastFromJS<int>( args[0] );
	string portBehavior = cvv8::CastFromJS<string>( args[1] );
	string portProtcol = cvv8::CastFromJS<string>( args[2] );
	uint portNumber = cvv8::CastFromJS<uint>( args[3] );
	string portScriptName = cvv8::CastFromJS<string>( args[4] );
	vector<string> scriptConfigurationKeys = cvv8::CastFromJS<vector<string>>( args[5] );
	vector<string> scriptConfigurationValues = cvv8::CastFromJS<vector<string>>( args[6] );

	PortSet *portSet = obj->m_profile->GetPortSet(portSetIndex);
	if(portSet == NULL)
	{
		cout << "ERROR: Unable to get portset " << portSetIndex << endl;
		return scope.Close(Boolean::New(false));
	}

	Port port;
	port.m_behavior = Port::StringToPortBehavior(portBehavior);
	port.m_protocol = Port::StringToPortProtocol(portProtcol);
	port.m_portNumber = portNumber;

	if (scriptConfigurationKeys.size() != scriptConfigurationValues.size())
	{
		cout << "ERROR: Size of key array is not equal to size of value array in scriptConfiguration" << endl;
		return scope.Close(Boolean::New(false));
	}

	for (uint i = 0; i < scriptConfigurationKeys.size(); i++)
	{
		port.m_scriptConfiguration[scriptConfigurationKeys[i]] = scriptConfigurationValues[i];
	}

	if(port.m_behavior == PORT_SCRIPT || port.m_behavior == PORT_TARPIT_SCRIPT)
	{
		port.m_scriptName = portScriptName;
	}

	portSet->AddPort(port);

	return scope.Close(Boolean::New(true));
}
コード例 #4
0
ファイル: PortsManager.cpp プロジェクト: fara-ramin/firewall
void PortsManager::Update()
{
	PortSet newPorts = GetNowPorts();
	Ports tmp(m_ports.size()+newPorts.size());
	PortsIterator end=std::set_difference (m_ports.begin(), m_ports.end(), newPorts.begin(), newPorts.end(), tmp.begin());
	for(PortsIterator it = tmp.begin();it!=end;it++)
	{
		USHORT port = it->GetPort();
		//USHORT netPort = htons(port);
		m_helper->WriteIo(DEL_PORT, &port, sizeof(port));
		m_traces.erase(m_traces.find(UsageTrace(port)));
	}
	end=std::set_difference (newPorts.begin(), newPorts.end(), m_ports.begin(), m_ports.end(), tmp.begin());
	m_ports = newPorts;
	for(PortSet::iterator iter = m_ports.begin(); iter!=m_ports.end(); iter++){
		UpdatePort(iter);
	}
	for(int i = 0; i<m_list->GetItemCount(); i++)
	{
		TCHAR szBuffer[1024];
		int port = GetPortFromList(i);
		PortSet::iterator iter = m_ports.find(Port(port, 0));
		if(iter!=m_ports.end())
		{
			wsprintf(szBuffer, _T("%ld"), iter->GetUsage());
			m_list->SetItem(i, 1, LVIF_TEXT, szBuffer, 0, 0, 0, 0);
			switch (iter->GetState()) {
            case MIB_TCP_STATE_CLOSED:
				wsprintf(szBuffer, _T("CLOSED"));
                break;
            case MIB_TCP_STATE_LISTEN:
				wsprintf(szBuffer, _T("LISTEN"));
                break;
            case MIB_TCP_STATE_SYN_SENT:
				wsprintf(szBuffer, _T("SYN-SENT"));
                break;
            case MIB_TCP_STATE_SYN_RCVD:
				wsprintf(szBuffer, _T("SYN-RECEIVED"));
                break;
            case MIB_TCP_STATE_ESTAB:
				wsprintf(szBuffer, _T("ESTABLISHED"));
                break;
            case MIB_TCP_STATE_FIN_WAIT1:
				wsprintf(szBuffer, _T("FIN-WAIT-1"));
                break;
            case MIB_TCP_STATE_FIN_WAIT2:
				wsprintf(szBuffer, _T("FIN-WAIT-2"));
                break;
            case MIB_TCP_STATE_CLOSE_WAIT:
				wsprintf(szBuffer, _T("CLOSE-WAIT"));
                break;
            case MIB_TCP_STATE_CLOSING:
				wsprintf(szBuffer, _T("CLOSING"));
                break;
            case MIB_TCP_STATE_LAST_ACK:
				wsprintf(szBuffer, _T("LAST-ACK"));
                break;
            case MIB_TCP_STATE_TIME_WAIT:
				wsprintf(szBuffer, _T("TIME-WAIT"));
                break;
            case MIB_TCP_STATE_DELETE_TCB:
				wsprintf(szBuffer, _T("DELETE-TCB"));
                break;
            default:
				wsprintf(szBuffer, _T("UNKNOWN"));
                break;
            }
		m_list->SetItem(i, 2, LVIF_TEXT, szBuffer, 0, 0, 0, 0);
		}
		else
		{
			m_list->DeleteItem(i);
			i--;
		}
	}
	for(PortsIterator it = tmp.begin();it!=end;it++)
	{
		int i = m_list->GetItemCount();
		TCHAR szBuffer[1024];
		unsigned short port = ntohs(it->GetPort());
		wsprintf(szBuffer, _T("%u"), port);
		m_list->InsertItem(i, szBuffer);
		wsprintf(szBuffer, _T("%ld"), it->GetUsage());
		m_list->SetItem(i, 1, LVIF_TEXT, szBuffer, 0, 0, 0, 0);
		
		switch (it->GetState()) {
            case MIB_TCP_STATE_CLOSED:
				wsprintf(szBuffer, _T("CLOSED"));
                break;
            case MIB_TCP_STATE_LISTEN:
				wsprintf(szBuffer, _T("LISTEN"));
                break;
            case MIB_TCP_STATE_SYN_SENT:
				wsprintf(szBuffer, _T("SYN-SENT"));
                break;
            case MIB_TCP_STATE_SYN_RCVD:
				wsprintf(szBuffer, _T("SYN-RECEIVED"));
                break;
            case MIB_TCP_STATE_ESTAB:
				wsprintf(szBuffer, _T("ESTABLISHED"));
                break;
            case MIB_TCP_STATE_FIN_WAIT1:
				wsprintf(szBuffer, _T("FIN-WAIT-1"));
                break;
            case MIB_TCP_STATE_FIN_WAIT2:
				wsprintf(szBuffer, _T("FIN-WAIT-2"));
                break;
            case MIB_TCP_STATE_CLOSE_WAIT:
				wsprintf(szBuffer, _T("CLOSE-WAIT"));
                break;
            case MIB_TCP_STATE_CLOSING:
				wsprintf(szBuffer, _T("CLOSING"));
                break;
            case MIB_TCP_STATE_LAST_ACK:
				wsprintf(szBuffer, _T("LAST-ACK"));
                break;
            case MIB_TCP_STATE_TIME_WAIT:
				wsprintf(szBuffer, _T("TIME-WAIT"));
                break;
            case MIB_TCP_STATE_DELETE_TCB:
				wsprintf(szBuffer, _T("DELETE-TCB"));
                break;
            default:
				wsprintf(szBuffer, _T("UNKNOWN"));
                break;
            }
		m_list->SetItem(i, 2, LVIF_TEXT, szBuffer, 0, 0, 0, 0);
	}
	UpdateChart();
	m_helper->ReadIo(GET_TOTAL, &m_totalPacket, sizeof(ULONG));
}