/*
 * Connect any NTP-Pool server to query the current time.
 */
static void QueryDateAndTime(void)
{
    uint32_t ip;
    time_t now;
    int i;

    /* First connect the DNS server to get the IP address. */
    printf("Is There Anybody Out There? ");
    ip = NutDnsGetHostByName((uint8_t *) "pool.ntp.org");
    if (ip == 0) {
        puts("No?");
    } else {
        /* We do have an IP, now try to connect it. */
        printf("Yes, found %s\n", inet_ntoa(ip));
        for (i = 0; i < 3; i++) {
            printf("What's the time? ");
            if (NutSNTPGetTime(&ip, &now) == 0) {
                /* We got a valid response, display the result. */
                printf("%s GMT\n", Rfc1123TimeString(gmtime(&now)));
                return;
            } else {
                /* It failed. May be the server is too busy. Try
                   again in 5 seconds. */
                puts("Sorry?");
                NutSleep(5000);
            }
        }
    }
    /* We give up after 3 trials. */
    puts("You missed the starting gun.");
}
Beispiel #2
0
void HttpSendStreamHeaderDate(HTTP_STREAM *stream, time_t mtime)
{
#if HTTP_VERSION >= 0x10
    if (mtime) {
        s_vputs(stream, ct_Last_Modified, ": ", Rfc1123TimeString(gmtime(&mtime)), " GMT\r\n", NULL);
    }
#endif
}
Beispiel #3
0
void HttpSendStreamHeaderTop(HTTP_STREAM *stream, int status)
{
#if HTTP_VERSION >= 0x10
    static const char fmt_P[] = "HTTP/%d.%d %d %s\r\nServer: uHTTP 0.0\r\n";

    s_printf(stream, fmt_P, HTTP_MAJOR_VERSION, HTTP_MINOR_VERSION, status, HttpResponseText(status));

#if !defined(HTTPD_EXCLUDE_DATE)
    {
        time_t now = time(NULL);
        s_vputs(stream, ct_Date, ": ", Rfc1123TimeString(gmtime(&now)), " GMT\r\n", NULL);
    }
#endif
#endif
}