"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "htpdate.c" between
htpdate-1.3.1.tar.gz and htpdate-1.3.2.tar.gz

About: HTPdate (HTTP Time Protocol) synchronizes a computer’s time with web servers as reference time source (working through proxy servers).

htpdate.c  (htpdate-1.3.1):htpdate.c  (htpdate-1.3.2)
/* /*
htpdate v1.3.1 htpdate v1.3.2
Eddy Vervest <eddy@vervest.org> Eddy Vervest <eddy@vervest.org>
http://www.vervest.org/htp http://www.vervest.org/htp
Synchronize local system with time offered by remote web servers Synchronize local system with time offered by remote web servers
This program works with the timestamps return by web servers, This program works with the timestamps return by web servers,
formatted as specified by HTTP/1.1 (RFC 2616, RFC 1123). formatted as specified by HTTP/1.1 (RFC 2616, RFC 1123).
Example usage: Example usage:
skipping to change at line 54 skipping to change at line 54
#include <netdb.h> #include <netdb.h>
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/timex.h> #include <sys/timex.h>
#include <syslog.h> #include <syslog.h>
#include <stdarg.h> #include <stdarg.h>
#include <limits.h> #include <limits.h>
#include <pwd.h> #include <pwd.h>
#include <grp.h> #include <grp.h>
#if defined __NetBSD__ || defined __FreeBSD__ #if defined __NetBSD__ || defined __FreeBSD__ || defined __APPLE__
#define adjtimex ntp_adjtime #define adjtimex ntp_adjtime
#endif #endif
#ifdef ENABLE_HTTPS #ifdef ENABLE_HTTPS
#include <openssl/ssl.h> #include <openssl/ssl.h>
#endif #endif
#define VERSION "1.3.1" #define VERSION "1.3.2"
#define MAX_HTTP_HOSTS 16 /* 16 web servers */ #define MAX_HTTP_HOSTS 16 /* 16 web servers */
#define DEFAULT_HTTP_PORT "80" #define DEFAULT_HTTP_PORT "80"
#define DEFAULT_PROXY_PORT "8080" #define DEFAULT_PROXY_PORT "8080"
#define DEFAULT_IP_VERSION PF_UNSPEC /* IPv6 and IPv4 */ #define DEFAULT_IP_VERSION PF_UNSPEC /* IPv6 and IPv4 */
#define DEFAULT_HTTP_VERSION "1" /* HTTP/1.1 */ #define DEFAULT_HTTP_VERSION "1" /* HTTP/1.1 */
#define DEFAULT_TIME_LIMIT 31536000 /* 1 year */ #define DEFAULT_TIME_LIMIT 31536000 /* 1 year */
#define NO_TIME_LIMIT -1 #define NO_TIME_LIMIT -1
#define ERR_TIMESTAMP LONG_MAX /* Err fetching date in getHT TPdate */ #define ERR_TIMESTAMP LONG_MAX /* Err fetching date in getHT TPdate */
#define DEFAULT_PRECISION 4 /* 4 request per host */ #define DEFAULT_PRECISION 4 /* 4 request per host */
#define DEFAULT_MIN_SLEEP 1800 /* 30 minutes */ #define DEFAULT_MIN_SLEEP 1800 /* 30 minutes */
skipping to change at line 373 skipping to change at line 373
} else { } else {
rc = SSL_connect(conn); rc = SSL_connect(conn);
if (rc != 1) { if (rc != 1) {
printlog(1, "SSL error2: %i", rc); printlog(1, "SSL error2: %i", rc);
rc = -1; rc = -1;
} }
} }
} }
#endif #endif
long offset; long offset = 0;
long first_offset = 0; long first_offset = 0;
long prev_offset = 0; long prev_offset = 0;
long nap = 1e9L; long nap = 1e9L;
long when = 0; long when = 0;
do { do {
if (debug > 1) if (debug > 1)
printlog(0, "bisect: %i, when: %09li", polls, when); printlog(0, "bisect: %i, when: %09li", polls, when);
/* Initialize timer */ /* Initialize timer */
clock_gettime(CLOCK_REALTIME, &now); clock_gettime(CLOCK_REALTIME, &now);
skipping to change at line 454 skipping to change at line 454
#ifdef ENABLE_HTTPS #ifdef ENABLE_HTTPS
if (scheme) SSL_shutdown(conn); if (scheme) SSL_shutdown(conn);
SSL_CTX_free(tls_ctx); SSL_CTX_free(tls_ctx);
SSL_free(conn); SSL_free(conn);
#endif #endif
/* Rounding */ /* Rounding */
if (debug) printlog(0, "when: %ld, nap: %ld", when, nap); if (debug) printlog(0, "when: %ld, nap: %ld", when, nap);
if (when + nap == 1e9L) return 0; if (when + nap == 1e9L) return 0;
if (offset < 0) when -= nap;
/* Return the time delta between web server time (timevalue) /* Return the time delta between web server time (timevalue)
and system time (now) and system time (now)
*/ */
if (first_offset < 0) { if (first_offset < 0) {
return(-first_offset + (1e9L-when)/(double)1e9L); return(-first_offset + (1e9L-when)/(double)1e9L);
} else { } else {
return(-first_offset + 1 - when/(double)1e9L); return(-first_offset + 1 - when/(double)1e9L);
} }
} }
skipping to change at line 522 skipping to change at line 523
FILE *fp; FILE *fp;
fp = fopen(driftfile, "r"); fp = fopen(driftfile, "r");
if (fp != NULL) { if (fp != NULL) {
if (fscanf(fp, "%li", &tmx.freq)) { if (fscanf(fp, "%li", &tmx.freq)) {
printlog(0, "Reading frequency from file %li", tmx.freq); printlog(0, "Reading frequency from file %li", tmx.freq);
} else { } else {
printlog(1, "Error reading frequency from %s", driftfile); printlog(1, "Error reading frequency from %s", driftfile);
} }
fclose(fp); fclose(fp);
return -1; return -1;
} else { } else {
printlog(1, "Error reading frequency from %s", driftfile); printlog(1, "Error reading frequency from %s", driftfile);
return -1; return -1;
} }
if ((tmx.freq < -MAX_DRIFT) || (tmx.freq > MAX_DRIFT)) if ((tmx.freq < -MAX_DRIFT) || (tmx.freq > MAX_DRIFT))
tmx.freq = sign(tmx.freq) * MAX_DRIFT; tmx.freq = sign(tmx.freq) * MAX_DRIFT;
printlog(0, "Set frequency: %li", tmx.freq); printlog(0, "Set frequency: %li", tmx.freq);
tmx.modes = MOD_FREQUENCY; tmx.modes = MOD_FREQUENCY;
/* Become root */ /* Become root */
swuid(0); swuid(0);
return(ntp_adjtime(&tmx)); return(adjtimex(&tmx));
} }
static int htpdate_adjtimex(double drift, char *driftfile) { static int htpdate_adjtimex(double drift, char *driftfile) {
struct timex tmx; struct timex tmx;
long freq; long freq;
FILE *fp; FILE *fp;
/* Read current clock frequency */ /* Read current clock frequency */
tmx.modes = 0; tmx.modes = 0;
adjtimex(&tmx); adjtimex(&tmx);
/* Calculate new frequency */ /* Calculate new frequency */
freq = (long)(65536e6 * drift); freq = (long)(65536e6 * drift);
/* Weighted average of current and new frequency */ /* Weighted average of current and new frequency */
tmx.freq = tmx.freq + (freq >> 3); tmx.freq = tmx.freq + (freq >> 3);
if ((tmx.freq < -MAX_DRIFT) || (tmx.freq > MAX_DRIFT)) if ((tmx.freq < -MAX_DRIFT) || (tmx.freq > MAX_DRIFT))
tmx.freq = sign(tmx.freq) * MAX_DRIFT; tmx.freq = sign(tmx.freq) * MAX_DRIFT;
printlog(0, "Adjusting to new frequency %li", tmx.freq); printlog(0, "Set frequency %li", tmx.freq);
tmx.modes = MOD_FREQUENCY; tmx.modes = MOD_FREQUENCY;
if (driftfile) { if (driftfile) {
fp = fopen(driftfile, "w"); fp = fopen(driftfile, "w");
if (fp != NULL) { if (fp != NULL) {
printlog(0, "Update %s", driftfile); printlog(0, "Update %s", driftfile);
fprintf(fp, "%li", tmx.freq); fprintf(fp, "%li", tmx.freq);
fclose(fp); fclose(fp);
} else { } else {
printlog(1, "Error writing frequency to %s", driftfile); printlog(1, "Error writing frequency to %s", driftfile);
skipping to change at line 587 skipping to change at line 588
Usage: htpdate [-046acdhlnqstvxD] [-f driftfile] [-i pidfile] [-m minpoll]\n\ Usage: htpdate [-046acdhlnqstvxD] [-f driftfile] [-i pidfile] [-m minpoll]\n\
[-M maxpoll] [-p precision] [-P <proxyserver>[:port]]\n\ [-M maxpoll] [-p precision] [-P <proxyserver>[:port]]\n\
[-u user[:group]] <URL> ...\n\n\ [-u user[:group]] <URL> ...\n\n\
-0 HTTP/1.0 request\n\ -0 HTTP/1.0 request\n\
-4 Force IPv4 name resolution only\n\ -4 Force IPv4 name resolution only\n\
-6 Force IPv6 name resolution only\n\ -6 Force IPv6 name resolution only\n\
-a adjust time smoothly\n\ -a adjust time smoothly\n\
-c verify server certificate\n\ -c verify server certificate\n\
-d debug mode\n\ -d debug mode\n\
-D daemon mode\n\ -D daemon mode\n\
-f drift/frequency file\n\
-F run daemon in foreground\n\ -F run daemon in foreground\n\
-h help\n\ -h help\n\
-i pid file\n\ -i pidfile\n\
-l use syslog for output\n\ -l use syslog for output\n\
-m minimum poll interval\n\ -m minimum poll interval\n\
-M maximum poll interval\n\ -M maximum poll interval\n\
-n no proxy (ignore http_proxy environment variable)\n\ -n no proxy (ignore http_proxy environment variable)\n\
-p precision (1..9, default 4)\n\ -p precision (1..9, default 4)\n\
-P proxy server\n\ -P proxy server\n\
-q query only, don't make time changes (default)\n\ -q query only, don't make time changes (default)\n\
-s set time\n\ -s set time\n\
-t turn off sanity time check\n\ -t turn off sanity time check\n\
-u run daemon as user\n\ -u run daemon as user\n\
 End of changes. 11 change blocks. 
9 lines changed or deleted 11 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)