2011-03-10 18:48:02 +08:00
|
|
|
/***************************************************************************
|
2006-02-05 02:08:54 +08:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2022-04-05 19:32:26 +08:00
|
|
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2006-02-05 02:08:54 +08:00
|
|
|
*
|
2011-03-10 18:48:02 +08:00
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2011-03-10 18:48:02 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
2006-02-05 02:08:54 +08:00
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2011-03-10 18:48:02 +08:00
|
|
|
***************************************************************************/
|
2016-01-04 22:34:05 +08:00
|
|
|
/* <DESC>
|
|
|
|
* Set your system time from a remote HTTP server's Date: header.
|
|
|
|
* </DESC>
|
|
|
|
*/
|
2011-03-10 18:48:02 +08:00
|
|
|
/* This example code only builds as-is on Windows.
|
2006-02-05 02:08:54 +08:00
|
|
|
*
|
2006-11-20 05:55:34 +08:00
|
|
|
* While Unix/Linux user, you do not need this software.
|
|
|
|
* You can achieve the same result as synctime using curl, awk and date.
|
|
|
|
* Set proxy as according to your network, but beware of proxy Cache-Control.
|
|
|
|
*
|
|
|
|
* To set your system clock, root access is required.
|
2018-09-23 05:44:36 +08:00
|
|
|
* # date -s "`curl -sI https://nist.time.gov/timezone.cgi?UTC/s/0 \
|
2006-11-20 05:55:34 +08:00
|
|
|
* | awk -F': ' '/Date: / {print $2}'`"
|
|
|
|
*
|
|
|
|
* To view remote webserver date and time.
|
2018-09-23 05:44:36 +08:00
|
|
|
* $ curl -sI https://nist.time.gov/timezone.cgi?UTC/s/0 \
|
2006-11-20 05:55:34 +08:00
|
|
|
* | awk -F': ' '/Date: / {print $2}'
|
|
|
|
*
|
2006-02-05 02:08:54 +08:00
|
|
|
* Synchronising your computer clock via Internet time server usually relies
|
|
|
|
* on DAYTIME, TIME, or NTP protocols. These protocols provide good accurate
|
2022-04-05 19:32:26 +08:00
|
|
|
* time synchronization but it does not work very well through a
|
2006-02-05 02:08:54 +08:00
|
|
|
* firewall/proxy. Some adjustment has to be made to the firewall/proxy for
|
|
|
|
* these protocols to work properly.
|
|
|
|
*
|
|
|
|
* There is an indirect method. Since most webserver provide server time in
|
|
|
|
* their HTTP header, therefore you could synchronise your computer clock
|
|
|
|
* using HTTP protocol which has no problem with firewall/proxy.
|
|
|
|
*
|
|
|
|
* For this software to work, you should take note of these items.
|
|
|
|
* 1. Your firewall/proxy must allow your computer to surf internet.
|
|
|
|
* 2. Webserver system time must in sync with the NTP time server,
|
|
|
|
* or at least provide an accurate time keeping.
|
|
|
|
* 3. Webserver HTTP header does not provide the milliseconds units,
|
|
|
|
* so there is no way to get very accurate time.
|
|
|
|
* 4. This software could only provide an accuracy of +- a few seconds,
|
|
|
|
* as Round-Trip delay time is not taken into consideration.
|
|
|
|
* Compensation of network, firewall/proxy delay cannot be simply divide
|
|
|
|
* the Round-Trip delay time by half.
|
|
|
|
* 5. Win32 SetSystemTime() API will set your computer clock according to
|
|
|
|
* GMT/UTC time. Therefore your computer timezone must be properly set.
|
|
|
|
* 6. Webserver data should not be cached by the proxy server. Some
|
|
|
|
* webserver provide Cache-Control to prevent caching.
|
|
|
|
*
|
|
|
|
* References:
|
2018-09-23 17:20:26 +08:00
|
|
|
* https://web.archive.org/web/20100228012139/ \
|
|
|
|
* tf.nist.gov/timefreq/service/its.htm
|
|
|
|
* https://web.archive.org/web/20100409024302/ \
|
|
|
|
* tf.nist.gov/timefreq/service/firewall.htm
|
2006-02-05 02:08:54 +08:00
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* This software will synchronise your computer clock only when you issue
|
|
|
|
* it with --synctime. By default, it only display the webserver's clock.
|
|
|
|
*
|
|
|
|
* Written by: Frank (contributed to libcurl)
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
|
|
|
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR OF THIS SOFTWARE BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
|
|
|
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
|
|
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
|
|
* OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
2006-07-06 07:10:37 +08:00
|
|
|
#ifndef __CYGWIN__
|
2018-09-23 05:44:36 +08:00
|
|
|
#include <winsock2.h>
|
2006-02-05 02:08:54 +08:00
|
|
|
#include <windows.h>
|
2006-07-06 07:10:37 +08:00
|
|
|
#endif
|
2006-02-05 02:08:54 +08:00
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define MAX_STRING 256
|
2017-09-10 05:55:08 +08:00
|
|
|
#define MAX_STRING1 MAX_STRING + 1
|
2006-02-05 02:08:54 +08:00
|
|
|
|
2014-12-13 22:02:30 +08:00
|
|
|
#define SYNCTIME_UA "synctime/1.0"
|
2014-12-10 01:18:40 +08:00
|
|
|
|
2006-02-05 02:08:54 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char http_proxy[MAX_STRING1];
|
|
|
|
char proxy_user[MAX_STRING1];
|
|
|
|
char timeserver[MAX_STRING1];
|
|
|
|
} conf_t;
|
|
|
|
|
2014-12-13 20:43:19 +08:00
|
|
|
const char DefaultTimeServer[3][MAX_STRING1] =
|
2006-02-05 02:08:54 +08:00
|
|
|
{
|
2018-09-23 05:44:36 +08:00
|
|
|
"https://nist.time.gov/",
|
|
|
|
"https://www.google.com/"
|
2006-02-05 02:08:54 +08:00
|
|
|
};
|
|
|
|
|
2007-07-13 05:11:10 +08:00
|
|
|
const char *DayStr[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
|
|
|
const char *MthStr[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
2006-02-05 02:08:54 +08:00
|
|
|
|
|
|
|
int ShowAllHeader;
|
|
|
|
int AutoSyncTime;
|
|
|
|
SYSTEMTIME SYSTime;
|
|
|
|
SYSTEMTIME LOCALTime;
|
|
|
|
|
|
|
|
#define HTTP_COMMAND_HEAD 0
|
|
|
|
#define HTTP_COMMAND_GET 1
|
|
|
|
|
|
|
|
|
|
|
|
size_t SyncTime_CURL_WriteOutput(void *ptr, size_t size, size_t nmemb,
|
|
|
|
void *stream)
|
|
|
|
{
|
|
|
|
fwrite(ptr, size, nmemb, stream);
|
2016-02-11 16:42:38 +08:00
|
|
|
return (nmemb*size);
|
2006-02-05 02:08:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb,
|
|
|
|
void *stream)
|
|
|
|
{
|
|
|
|
char TmpStr1[26], TmpStr2[26];
|
|
|
|
|
2018-09-23 05:44:36 +08:00
|
|
|
(void)stream;
|
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if(ShowAllHeader == 1)
|
2006-02-05 02:08:54 +08:00
|
|
|
fprintf(stderr, "%s", (char *)(ptr));
|
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if(strncmp((char *)(ptr), "Date:", 5) == 0) {
|
|
|
|
if(ShowAllHeader == 0)
|
2006-02-05 02:08:54 +08:00
|
|
|
fprintf(stderr, "HTTP Server. %s", (char *)(ptr));
|
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if(AutoSyncTime == 1) {
|
2006-02-05 02:08:54 +08:00
|
|
|
*TmpStr1 = 0;
|
|
|
|
*TmpStr2 = 0;
|
2016-02-11 16:42:38 +08:00
|
|
|
if(strlen((char *)(ptr)) > 50) /* Can prevent buffer overflow to
|
2006-02-05 02:08:54 +08:00
|
|
|
TmpStr1 & 2? */
|
|
|
|
AutoSyncTime = 0;
|
|
|
|
else {
|
2021-06-24 15:24:37 +08:00
|
|
|
int RetVal = sscanf((char *)(ptr), "Date: %25s %hu %s %hu %hu:%hu:%hu",
|
2019-05-25 16:06:08 +08:00
|
|
|
TmpStr1, &SYSTime.wDay, TmpStr2, &SYSTime.wYear,
|
|
|
|
&SYSTime.wHour, &SYSTime.wMinute,
|
|
|
|
&SYSTime.wSecond);
|
2006-02-05 02:08:54 +08:00
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if(RetVal == 7) {
|
2019-05-25 16:06:08 +08:00
|
|
|
int i;
|
2006-02-05 02:08:54 +08:00
|
|
|
SYSTime.wMilliseconds = 500; /* adjust to midpoint, 0.5 sec */
|
2017-09-10 05:09:06 +08:00
|
|
|
for(i = 0; i<12; i++) {
|
2016-02-11 16:42:38 +08:00
|
|
|
if(strcmp(MthStr[i], TmpStr2) == 0) {
|
2017-09-10 05:55:08 +08:00
|
|
|
SYSTime.wMonth = i + 1;
|
2006-02-05 02:08:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AutoSyncTime = 3; /* Computer clock will be adjusted */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
AutoSyncTime = 0; /* Error in sscanf() fields conversion */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if(strncmp((char *)(ptr), "X-Cache: HIT", 12) == 0) {
|
2006-02-05 02:08:54 +08:00
|
|
|
fprintf(stderr, "ERROR: HTTP Server data is cached."
|
|
|
|
" Server Date is no longer valid.\n");
|
|
|
|
AutoSyncTime = 0;
|
|
|
|
}
|
2016-02-11 16:42:38 +08:00
|
|
|
return (nmemb*size);
|
2006-02-05 02:08:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SyncTime_CURL_Init(CURL *curl, char *proxy_port,
|
|
|
|
char *proxy_user_password)
|
|
|
|
{
|
2016-02-11 16:42:38 +08:00
|
|
|
if(strlen(proxy_port) > 0)
|
2006-02-05 02:08:54 +08:00
|
|
|
curl_easy_setopt(curl, CURLOPT_PROXY, proxy_port);
|
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if(strlen(proxy_user_password) > 0)
|
2006-02-05 02:08:54 +08:00
|
|
|
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, proxy_user_password);
|
|
|
|
|
2014-12-13 22:02:30 +08:00
|
|
|
#ifdef SYNCTIME_UA
|
|
|
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, SYNCTIME_UA);
|
2014-12-10 01:18:40 +08:00
|
|
|
#endif
|
2020-12-16 16:24:16 +08:00
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, SyncTime_CURL_WriteOutput);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, SyncTime_CURL_WriteHeader);
|
2006-02-05 02:08:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int SyncTime_CURL_Fetch(CURL *curl, char *URL_Str, char *OutFileName,
|
|
|
|
int HttpGetBody)
|
|
|
|
{
|
|
|
|
FILE *outfile;
|
|
|
|
CURLcode res;
|
|
|
|
|
|
|
|
outfile = NULL;
|
2016-02-11 16:42:38 +08:00
|
|
|
if(HttpGetBody == HTTP_COMMAND_HEAD)
|
2008-05-23 05:20:07 +08:00
|
|
|
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
|
2006-02-05 02:08:54 +08:00
|
|
|
else {
|
|
|
|
outfile = fopen(OutFileName, "wb");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, URL_Str);
|
|
|
|
res = curl_easy_perform(curl);
|
2021-12-26 04:41:14 +08:00
|
|
|
if(outfile)
|
2006-02-05 02:08:54 +08:00
|
|
|
fclose(outfile);
|
|
|
|
return res; /* (CURLE_OK) */
|
|
|
|
}
|
|
|
|
|
|
|
|
void showUsage(void)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "SYNCTIME: Synchronising computer clock with time server"
|
|
|
|
" using HTTP protocol.\n");
|
|
|
|
fprintf(stderr, "Usage : SYNCTIME [Option]\n");
|
|
|
|
fprintf(stderr, "Options :\n");
|
|
|
|
fprintf(stderr, " --server=WEBSERVER Use this time server instead"
|
|
|
|
" of default.\n");
|
|
|
|
fprintf(stderr, " --showall Show all HTTP header.\n");
|
|
|
|
fprintf(stderr, " --synctime Synchronising computer clock"
|
|
|
|
" with time server.\n");
|
|
|
|
fprintf(stderr, " --proxy-user=USER[:PASS] Set proxy username and"
|
|
|
|
" password.\n");
|
|
|
|
fprintf(stderr, " --proxy=HOST[:PORT] Use HTTP proxy on given"
|
|
|
|
" port.\n");
|
|
|
|
fprintf(stderr, " --help Print this help.\n");
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int conf_init(conf_t *conf)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
*conf->http_proxy = 0;
|
2017-09-10 05:09:06 +08:00
|
|
|
for(i = 0; i<MAX_STRING1; i++)
|
2006-02-05 02:08:54 +08:00
|
|
|
conf->proxy_user[i] = 0; /* Clean up password from memory */
|
|
|
|
*conf->timeserver = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
CURL *curl;
|
|
|
|
conf_t conf[1];
|
|
|
|
int RetValue;
|
|
|
|
|
|
|
|
ShowAllHeader = 0; /* Do not show HTTP Header */
|
|
|
|
AutoSyncTime = 0; /* Do not synchronise computer clock */
|
|
|
|
RetValue = 0; /* Successful Exit */
|
|
|
|
conf_init(conf);
|
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if(argc > 1) {
|
2019-05-21 16:44:16 +08:00
|
|
|
int OptionIndex = 0;
|
2016-02-11 16:42:38 +08:00
|
|
|
while(OptionIndex < argc) {
|
|
|
|
if(strncmp(argv[OptionIndex], "--server=", 9) == 0)
|
2006-02-05 02:08:54 +08:00
|
|
|
snprintf(conf->timeserver, MAX_STRING, "%s", &argv[OptionIndex][9]);
|
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if(strcmp(argv[OptionIndex], "--showall") == 0)
|
2006-02-05 02:08:54 +08:00
|
|
|
ShowAllHeader = 1;
|
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if(strcmp(argv[OptionIndex], "--synctime") == 0)
|
2006-02-05 02:08:54 +08:00
|
|
|
AutoSyncTime = 1;
|
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if(strncmp(argv[OptionIndex], "--proxy-user=", 13) == 0)
|
2006-02-05 02:08:54 +08:00
|
|
|
snprintf(conf->proxy_user, MAX_STRING, "%s", &argv[OptionIndex][13]);
|
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if(strncmp(argv[OptionIndex], "--proxy=", 8) == 0)
|
2006-02-05 02:08:54 +08:00
|
|
|
snprintf(conf->http_proxy, MAX_STRING, "%s", &argv[OptionIndex][8]);
|
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if((strcmp(argv[OptionIndex], "--help") == 0) ||
|
2006-02-05 02:08:54 +08:00
|
|
|
(strcmp(argv[OptionIndex], "/?") == 0)) {
|
|
|
|
showUsage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
OptionIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if(*conf->timeserver == 0) /* Use default server for time information */
|
2006-02-05 02:08:54 +08:00
|
|
|
snprintf(conf->timeserver, MAX_STRING, "%s", DefaultTimeServer[0]);
|
|
|
|
|
|
|
|
/* Init CURL before usage */
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
curl = curl_easy_init();
|
2016-02-11 16:42:38 +08:00
|
|
|
if(curl) {
|
2019-05-21 16:44:16 +08:00
|
|
|
struct tm *lt;
|
|
|
|
struct tm *gmt;
|
|
|
|
time_t tt;
|
|
|
|
time_t tt_local;
|
|
|
|
time_t tt_gmt;
|
|
|
|
double tzonediffFloat;
|
|
|
|
int tzonediffWord;
|
|
|
|
char timeBuf[61];
|
|
|
|
char tzoneBuf[16];
|
|
|
|
|
2006-02-05 02:08:54 +08:00
|
|
|
SyncTime_CURL_Init(curl, conf->http_proxy, conf->proxy_user);
|
|
|
|
|
|
|
|
/* Calculating time diff between GMT and localtime */
|
|
|
|
tt = time(0);
|
|
|
|
lt = localtime(&tt);
|
|
|
|
tt_local = mktime(lt);
|
|
|
|
gmt = gmtime(&tt);
|
|
|
|
tt_gmt = mktime(gmt);
|
|
|
|
tzonediffFloat = difftime(tt_local, tt_gmt);
|
|
|
|
tzonediffWord = (int)(tzonediffFloat/3600.0);
|
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if((double)(tzonediffWord * 3600) == tzonediffFloat)
|
2006-02-05 02:08:54 +08:00
|
|
|
snprintf(tzoneBuf, 15, "%+03d'00'", tzonediffWord);
|
|
|
|
else
|
|
|
|
snprintf(tzoneBuf, 15, "%+03d'30'", tzonediffWord);
|
|
|
|
|
|
|
|
/* Get current system time and local time */
|
|
|
|
GetSystemTime(&SYSTime);
|
|
|
|
GetLocalTime(&LOCALTime);
|
|
|
|
snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ",
|
|
|
|
DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay,
|
|
|
|
MthStr[LOCALTime.wMonth-1], LOCALTime.wYear,
|
|
|
|
LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond,
|
|
|
|
LOCALTime.wMilliseconds);
|
2006-11-20 05:55:34 +08:00
|
|
|
|
|
|
|
fprintf(stderr, "Fetch: %s\n\n", conf->timeserver);
|
|
|
|
fprintf(stderr, "Before HTTP. Date: %s%s\n\n", timeBuf, tzoneBuf);
|
2006-02-05 02:08:54 +08:00
|
|
|
|
|
|
|
/* HTTP HEAD command to the Webserver */
|
|
|
|
SyncTime_CURL_Fetch(curl, conf->timeserver, "index.htm",
|
|
|
|
HTTP_COMMAND_HEAD);
|
|
|
|
|
|
|
|
GetLocalTime(&LOCALTime);
|
|
|
|
snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ",
|
|
|
|
DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay,
|
|
|
|
MthStr[LOCALTime.wMonth-1], LOCALTime.wYear,
|
|
|
|
LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond,
|
|
|
|
LOCALTime.wMilliseconds);
|
|
|
|
fprintf(stderr, "\nAfter HTTP. Date: %s%s\n", timeBuf, tzoneBuf);
|
|
|
|
|
2016-02-11 16:42:38 +08:00
|
|
|
if(AutoSyncTime == 3) {
|
2006-02-05 02:08:54 +08:00
|
|
|
/* Synchronising computer clock */
|
2016-02-11 16:42:38 +08:00
|
|
|
if(!SetSystemTime(&SYSTime)) { /* Set system time */
|
2006-02-05 02:08:54 +08:00
|
|
|
fprintf(stderr, "ERROR: Unable to set system time.\n");
|
|
|
|
RetValue = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Successfully re-adjusted computer clock */
|
|
|
|
GetLocalTime(&LOCALTime);
|
|
|
|
snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ",
|
|
|
|
DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay,
|
|
|
|
MthStr[LOCALTime.wMonth-1], LOCALTime.wYear,
|
|
|
|
LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond,
|
|
|
|
LOCALTime.wMilliseconds);
|
|
|
|
fprintf(stderr, "\nNew System's Date: %s%s\n", timeBuf, tzoneBuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cleanup before exit */
|
|
|
|
conf_init(conf);
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
}
|
|
|
|
return RetValue;
|
|
|
|
}
|