////////////////////////////////////////////////////////////
	/* get client time and parse (only for printout purposes) */
	////////////////////////////////////////////////////////////
	gettimeofday(&clienttime,0);

	clientdayportion = clienttime.tv_sec%86400 + timezonediff + dst; 
	if (clientdayportion < 0)
		clientdayportion = clientdayportion + 86400;	/* accout for early morning GMT */

	clienttimehours = clientdayportion/3600;
	clienttimeminutes = (clientdayportion%3600)/60;
	clienttimeseconds = clientdayportion%60;
	clienttimemilliseconds = clienttime.tv_usec/1000;

These lines get the client time in seconds and microseconds since the Epoch in Greenwich Mean Time, and then calculate the seconds since the start of today in U.S. Eastern Time, also accounting for Daylight Savings. These seconds are then converted into hours, minutes, and seconds. The microseconds are converted to milliseconds. In this Unix client, the client time is only need for comparative purposes.

	///////////////////////////////////////
	/* send message loop for prop delays */
	///////////////////////////////////////

	for (i=0; i < propdelaycount; i++) {

		going = gethrtime();

		/* send junk message to the server PORT on machine HOST */
		if (send(sd, "123", 4, 0) == -1) {
			perror("send");
			exit(1);
		}

  	        /* wait for a message to come back from the server */
        	if (recv(sd, messagereply, (sizeof(long)*8+3)*2+3, 0) == -1) {
                	perror("recv");
                	exit(1);
        	}

		coming = gethrtime();

		propdelays[i] = (double)(coming - going)/2.0;

	} //end prop delay loop

This loop marks a time in nanoseconds, sends a junk message to the server, then marks the time again in nanoseconds after receiving a response. The difference of these times represents 2-way propagation delay between the client and the server. This delay is then halved and stored in an array. The loop is currently set to perform 50 times.

While it is true that the forward propagation delay is not necessarily equal to the reverse propagation delay, and hence halving isn't perfectly precise, I felt this system was a good approximation due to the relatively low latencies involved.

	/////////////////////////////
	/* find prop delay average */
	/////////////////////////////

	sum = 0.0;
	maxpropdelay = 0.0;
	minpropdelay = 99999999999.0;

	for (i=0; i < propdelaycount; i++ ) {
		sum = sum + propdelays[i];
		if (propdelays[i] > maxpropdelay) 
			maxpropdelay = propdelays[i];
		else if (propdelays[i] < minpropdelay)
			minpropdelay = propdelays[i];
	}
	
	avgpropdelay = (sum-maxpropdelay-minpropdelay)/double(propdelaycount-2);  /* throw out highest and lowest */

This section adds up all the recorded propagation delays, throwing out the highest and lowest, and then finds the average delay.

	/////////////////////////////
	/* parse server time reply */
	/////////////////////////////
	j = 0;
	while (messagereply[j] != ' ') {

	serversecstring[j]=messagereply[j];
	j++;
	} // end while

	serversecstring[j]='\0';
	
	j = j+3;
	k = 0;
	while (messagereply[j] !='\0') {
	
	serverusecstring[k]=messagereply[j];
	k++; j++;
	} // end while
	
	serverusecstring[k]='\0';

After having received the server's time string already, these lines parse the string into seconds and microseconds, both still strings.

	//////////////////////////////////////////////////////////
	/* change server time strings to long ints and break up */
	//////////////////////////////////////////////////////////
	serverseclong = atol(serversecstring);
	serveruseclong = atol(serverusecstring);

	serverdayportion = serverseclong%86400 + timezonediff + dst; 
	if (serverdayportion < 0)
		serverdayportion = serverdayportion + 86400;	/* accout for early morning GMT */

	settimetohours = serverdayportion/3600;
	settimetominutes = (serverdayportion%3600)/60;
	settimetoseconds = serverdayportion%60;
	settimetomilliseconds = serveruseclong/1000.0 + avgpropdelay/1000000.0;

Finally, these commands convert the time strings to long integers, and adjusts them for U.S. Eastern Time as was done to the client time.