/* SMRT (Single Message Round trip Time Measurement) */ #include "smrt.h" #include #include #include #include #include #include /***** FUNCTION PROTOTYPES *****/ FILE *OpenFile(char *fname, char *access_mode); void HoldScreen(void); /***** PROGRAM's MAIN DRIVER *****/ main(argc,argv) int argc; char *argv[]; { FILE *OUTFILE; FILE *Ifile; FILE *RFile; char sitename[100]; char Ln[300]; char PingInstruction[200]; float min=0,average=0,max=0; float bandwidth; // available bandwidth float times; // round trip time int sitenum=0; int i=0; int FindOrNot=0; Ifile = OpenFile(argv[1], "r"); while (fscanf(Ifile,"%s %f %f\n",sitename,&bandwidth,×) != EOF) { if (strcmp(sitename,argv[2]) == 0) { strcpy(PingInstruction,""); strcat(PingInstruction,"ping -c 1 "); strcat(PingInstruction,sitename); strcat(PingInstruction," > SMRTping.txt"); //printf("%s\n",PingInstruction); system(PingInstruction); RFile = OpenFile("SMRTping.txt", "r"); // read the ping result file while (fgets(Ln,255,RFile) != EOF) { if (strstr(Ln,"packet loss") != NULL) { float band=0; fscanf(RFile,"%*s %*s = %f/%f/%f ", &min, &average, &max); if (average <= times) band = bandwidth; else band = (bandwidth*times)/average; printf("%s %f\n","Available Bandwidth is :",band); break; } }// end of ping text file while fclose(RFile); FindOrNot=1; break; } // end if } // end of siteList file while fclose(Ifile); if (!FindOrNot) printf("Did not find the history information of entried host name !!!\n"); return 1; } /* end main() */ /***** FUNCTION DEFINITIONS ******/ /* This funcction returns a pointer to the opened file named as a the 1st */ /* argument for the access mode of the second argument. */ FILE *OpenFile( char *fname, char *access_mode) { FILE *fp; if((fp=fopen(fname, access_mode)) == NULL) fprintf(stderr,"\nError openong file %s with access mode %s\n", fname, access_mode); return fp; } /* OpenFile */ /* Prompts the user to press Enter to continue program execution. */ void HoldScreen(void) { int dummy; printf("\nPress Enter to continue: "); fflush(stdin); dummy = getchar(); printf("%c\n",dummy); } /* HoldScreen */