/* Call ping to get the round trip time */ //#include "smrt.h" #include #include #include #include #include #include /***** FUNCTION PROTOTYPES *****/ FILE *OpenFile1(char *fname, char *access_mode); /***** PROGRAM's MAIN DRIVER *****/ void main() { FILE *OUTFILE; FILE *Ifile; FILE *RFile; char sitename[100]; char Ln[300]; char PingInstruction[200]; time_t now; float min=0,average=0,max=0; float bandwidth; // available bandwidth float times; // round trip time int sitenum=0; int i=0; strcpy(sitename,"ftp.cse.buffalo.edu"); while (i<25) { //printf("%s\n",sitename); strcpy(PingInstruction,""); strcat(PingInstruction,"ping -c 5 "); strcat(PingInstruction,sitename); strcat(PingInstruction," > pingCse.txt"); //printf("%s\n",PingInstruction); system(PingInstruction); now = time(NULL); RFile = OpenFile1("pingCse.txt", "r"); // read the ping result file while (fgets(Ln,255,RFile) != EOF) { if (strstr(Ln,"packet loss") != NULL) { fscanf(RFile,"%*s %*s = %f/%f/%f ", &min, &average, &max); break; } } // end of ping text file while fclose(RFile); OUTFILE = OpenFile1("cseTime.dat", "a"); fprintf(OUTFILE,"%s %s %f\n",ctime(&now)," | ", average); fclose(OUTFILE); system("sleep 3600"); i = i+1; } // end of siteList file while } /* 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 *OpenFile1( 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 */