Exemple #1
0
int Dijkstra(NodeStruct *Map,int MapSize,int Start,int Finish)
{
    //Start Dijkstra algorithm
    VisitNode(Map, MapSize, Start, Finish);

    //Trace found route of Dijkstra algorithm
    return TraceRoute(Map, Finish);
}
Exemple #2
0
void EvalTraceOpts(char * pOptions, int sockfd)
{
	int idx,idx1,iFileNameCounter=0;
	char fileName[200]; 
	int bInvalidInput=FALSE;
	int bFlag=FALSE;
	int rate;
	FILE *fp;
	char sLine[200]; 
	char cmd[200];
	char logText[BUFSIZE] = "";

	for (idx=0; idx <strlen(pOptions); idx++)
	{
		if (pOptions[idx] == ' ')
		{
			fileName[iFileNameCounter] = '\0';
			bFlag=TRUE;
			break;
		}
		else
			fileName[iFileNameCounter++] = pOptions[idx];
	}


	if (!bFlag)
		fileName[iFileNameCounter] = '\0';


	for (idx1=idx; idx1 < strlen(pOptions); idx1++)
	{
		if(pOptions[idx1] == ' ')
			continue;
		else
			bInvalidInput = TRUE;
	}


	if (bInvalidInput)
	{
		WriteToLog("Invalid traceroute options");
		char message[] = "\nSome Extra characters in Traceroute command\n"
							"Use 'HELP' to get assistance\n";
								  
		if (send(sockfd,message,strlen(message),0) != -1)
		{}

		//DisplayHelp(sockfd);

		return;
	}

	if (strcmp(fileName,"me") == 0) {

		for(idx=0;idx<active_sessions;idx++)
		{
			if(siUsers[idx].sockfd == sockfd)
			{
				rate = GetCmdRate(sockfd);
				if(rate >=1 && rate <= gRateRequest ) {
					TraceRoute(siUsers[idx].ip,siUsers[idx].sockfd);
				}
				else
				{
					snprintf(logText,BUFSIZE-1,
							"Traceroute exceeded limit of %d per %d",gRateRequest,gRateDuration);
					WriteToLog(logText);
					char message[] = "\nMaximum number of requests exceeded."
									  " Please Wait for some time and try again\n";
					if (send(sockfd,message,strlen(message),0) != -1)
					{/*...*/}
												
				}
				return;
			}
		}

	}
	else
	{
		if((fp =fopen(fileName,"r")) == NULL)
		{
			bFlag = FALSE;
			for (idx=0; idx<strlen(fileName); idx++) {
				if (!(fileName[idx] == '.' || fileName[idx] == '-'
					|| (fileName[idx] >= 48 && fileName[idx] <=57)
					|| (fileName[idx] >= 65 && fileName[idx] <=90)
					|| (fileName[idx] >= 97 && fileName[idx] <=122))) {
					bFlag = TRUE;
				}
			}

			if (bFlag)
			{

				char message[]="\nInvalid DNS/IP entered\n"
								"Use 'HELP' to get assistance\n";
											
				if (send(sockfd,message,strlen(message),0) != -1) {}
				return;
			}

			bFlag = 1;
			if (gStrictDest){
				for(idx=0;idx<active_sessions;idx++)
				{
					if(siUsers[idx].sockfd == sockfd)
					{
						if (strcmp(fileName,siUsers[idx].ip) != 0) {
							bFlag = 0;
							break;
						}
					}
				}		
			}
			
			if(bFlag) {
				rate = GetCmdRate(sockfd);
				if(rate >=1 && rate <= gRateRequest ) {
					TraceRoute(fileName, sockfd);
				}
				else
				{
					snprintf(logText,BUFSIZE-1,
										"Traceroute per minute exceeded limit of %d",gRateRequest);
					WriteToLog(logText);
					char message[] = "\nMaximum number of requests exceeded."
									  " Please Wait for some time and try again\n";
					if (send(sockfd,message,strlen(message),0) != -1)
					{}
												
				}
				
			} else {

				WriteToLog("STRICT_DEST Violation, alerting user");
				char message[]="\nSrict Destination enabled by Server\n"
						"Can traceroute to your ip only\n";
				if (send(sockfd,message,strlen(message),0) != -1) {}
			}
		}
		else
		{

			while (fscanf(fp,"%s %s",sLine,cmd) != EOF) {
				printf("%s: %s\n",sLine,cmd);
				
				
				rate = GetCmdRate(sockfd);
				if(rate >=1 && rate <= gRateRequest ) 
				{
					TraceRoute(cmd, sockfd);
									
				}
				else
				{
					snprintf(logText,BUFSIZE-1,
						"Traceroute per minute exceeded limit of %d",gRateRequest);
					WriteToLog(logText);
										
					char message[] = "\nMaximum number of requests exceeded."
				  				     " Please Wait for some time and try again\n";
					if (send(sockfd,message,strlen(message),0) != -1)
					{}
														
				}
			}
			return;
		}
	}
}