//main.cpp
//descrip :	measures the round trip time of a packet

#include < unistd.h >
#include < time.h >
#include < stdio.h >
#include < stdlib.h >

#define __babbage_csee_usf_edu__ //( a unix environment )
//#define __europa_tzo_com__		//( a linux environment )

int main()
{
	struct tm *local ;
	time_t t ;
	time_t start ;
	time_t end ;
	
	int sleeptime ;
	int nexthour ;




	t = time( 0 ) ;
	local = localtime( &t ) ;
	nexthour = local->tm_hour ;

	printf( "testing sleep for 20 seconds\n" ) ;
	sleep( 20 ) ;
	printf( "waking up now... continuing with program\n" ) ;
	
		
	//sleep( 1800 ) ;//wait 30 minutes, report on every hour


	//loop forever or until ^C
	do
	{
		start = time( 0 ) ;
		local = localtime( &start ) ;
		printf( "the hour is %d\n", local->tm_hour ) ;
	
	
		#ifdef __babbage_csee_usf_edu__
			system( "ping -s -n www.uquebec.ca	64 20	>>canada.dat" ) ;
			system( "ping -s -n www.maine.edu	64 20 >>maine.dat " ) ;
			system( "ping -s -n www.mit.edu		64 20	>>mit.dat" ) ;
			system( "ping -s -n www.suny.edu		64 20	>>newyork.dat" ) ;
			system( "ping -s -n www.psu.edu		64 20	>>pennsylvania.dat" ) ;
			system( "ping -s -n www.gwu.edu		64 20	>>washingtondc.dat" ) ;
			system( "ping -s -n www.unc.edu		64 20	>>northcarolina.dat" ) ;
			system( "ping -s -n www.gatech.edu	64 20 >>georgia.dat" ) ;
			system( "ping -s -n www.usf.edu		64 20	>>florida.dat" ) ;
			system( "ping -s -n www.upr.edu		64 20	>>puertorico.dat" ) ;
	
			system( "ping -s -n www.uquebec.ca	500 15 >>bigcanada.dat" ) ;
			system( "ping -s -n www.maine.edu	500 15 >>bigmaine.dat " ) ;
			system( "ping -s -n www.mit.edu		500 15 >>bigmit.dat" ) ;
			system( "ping -s -n www.suny.edu		500 15 >>bignewyork.dat" ) ;
			system( "ping -s -n www.psu.edu		500 15 >>bigpennsylvania.dat" ) ;
			system( "ping -s -n www.gwu.edu		500 15 >>bigwashingtondc.dat" ) ;
			system( "ping -s -n www.unc.edu		500 15 >>bignorthcarolina.dat" ) ;
			system( "ping -s -n www.gatech.edu	500 15 >>biggeorgia.dat" ) ;
			system( "ping -s -n www.usf.edu		500 15 >>bigflorida.dat" ) ;
			system( "ping -s -n www.upr.edu		500 15 >>bigpuertorico.dat" ) ;
		#endif



		#ifdef __europa_tzo_com__
			system( "ping -c 10 -s 64 www.uquebec.ca >>canada.dat" ) ;
			system( "ping -c 10 -s 64 www.maine.edu  >>maine.dat " ) ;
			system( "ping -c 10 -s 64 www.mit.edu	  >>mit.dat" ) ;
			system( "ping -c 10 -s 64 www.suny.edu	  >>newyork.dat" ) ;
			system( "ping -c 10 -s 64 www.psu.edu	  >>pennsylvania.dat" ) ;
			system( "ping -c 10 -s 64 www.gwu.edu	  >>washingtondc.dat" ) ;
			system( "ping -c 10 -s 64 www.unc.edu	  >>northcarolina.dat" ) ;
			system( "ping -c 10 -s 64 www.gatech.edu >>georgia.dat" ) ;
			system( "ping -c 10 -s 64 www.usf.edu	  >>florida.dat" ) ;
			system( "ping -c 10 -s 64 www.upr.edu	  >>puertorico.dat" ) ;
	
			system( "ping -c 10 -s 1000 www.uquebec.ca >>bigcanada.dat" ) ;
			system( "ping -c 10 -s 1000 www.maine.edu  >>bigmaine.dat " ) ;
			system( "ping -c 10 -s 1000 www.mit.edu	 >>bigmit.dat" ) ;
			system( "ping -c 10 -s 1000 www.suny.edu	 >> bignewyork.dat" ) ;
			system( "ping -c 10 -s 1000 www.psu.edu	 >>bigpennsylvania.dat" ) ;
			system( "ping -c 10 -s 1000 www.gwu.edu	 >>bigwashingtondc.dat" ) ;
			system( "ping -c 10 -s 1000 www.unc.edu	 >>bignorthcarolina.dat" ) ;
			system( "ping -c 10 -s 1000 www.gatech.edu >>biggeorgia.dat" ) ;
			system( "ping -c 10 -s 1000 www.usf.edu	 >>bigflorida.dat" ) ;
			system( "ping -c 10 -s 1000 www.upr.edu	 >>bigpuertorico.dat" ) ;
		#endif

		end = time( 0 ) ;
			
		printf( "it took %d seconds for ping to finish\n", (int)difftime( end, start ) ) ; 
		printf( "finished pinging at hour %d\n sleeping for 1 hour now...\n", local->tm_hour ) ;
		nexthour =( local->tm_hour + 1 )% 24;
	
		sleeptime = 3600 - (int)difftime( end, start ) ;
		sleep( sleeptime ) ;//wait 1 hour total

		printf( "\nawake now\n" ) ;

	} while( 1 ) ;
	
	
	return 0 ;
}