コード例 #1
0
int gotFreshRoute(char *address, int staleness)
{
	int i;
	struct sockaddr *sa;
	char interface_addr[16];
	time_t curr_time = time(NULL);
	i = findInTable(address);
	
	//if there is a route that is not stale, return it
	if(i >= 0)
	{
		if(routing_table[i].timestamp == 0)
		{	
			printf("No route\n");
			return -1;
		}
		if(difftime(routing_table[i].timestamp, curr_time) < staleness)
		{
			printf("Got fresh route\n");
			return i;
		}
		else
		{
			deleteRoute(i);
			printf("Got stale route, deleting\n");
			return -1;
		}
	}
	
	printf("No route for %s\n", address);
	return -1;
}
コード例 #2
0
// ƒобавление константы в таблицу констант
int insertToTable(ConstsTable* table, int number, struct ConstInfo const_info)
{
	int retVal = findInTable(*table, const_info);

	if(retVal == -1)
	{
		table->insert(ConstPair(number, const_info));
		retVal = table->size();
	}
	
	return retVal;
}
コード例 #3
0
int updateTable(char* address, char* haddr, int index, int hops,int routediscovery)
{
	int i;
	
	i = findInTable(address);
	
	if(i == -1) //If it's not in the table, it's new. Find a new slot
	{
		i = findSlot();
		if(i != -1)
		{
			routing_table[i] = newRoute(address, haddr, index, hops);
			return 0;
		}
		return -1;
	}
		
	if(i != -1) //if it's in the table, update it
	{
		if(routediscovery == 1)
		{
			printf("Force update\n");
			memcpy((void*)routing_table[i].nexthop, (void*)haddr, 6);
			routing_table[i].index = index;
			routing_table[i].hops = hops;
			routing_table[i].timestamp = time(NULL);
		}
		else if(routing_table[i].hops > hops)
		{
			memcpy((void*)routing_table[i].nexthop, (void*)haddr, 6);
			routing_table[i].index = index;
			routing_table[i].hops = hops;
			routing_table[i].timestamp = time(NULL);
		}
		else
			printf("This route is inferior - %d hops < %d hops\n", routing_table[i].hops, hops);		
	}

}
コード例 #4
0
ファイル: hash.c プロジェクト: marceloprates/compiladores
linkedList_t* findSymbol(symbol_t symbol)
{

	return findInTable(symbol, symbolTable, SYMBOL_TABLE_SIZE);
}