#include "nist.h"

void query_server()
{
    char
        the_time[200];
    int
        sock;
    struct sockaddr_in
        servername;

    if ((sock = socket (PF_INET, SOCK_STREAM, 0)) < 0) /* Create the socket. */
        error("Can't create a socket");

    init_sockaddr (&servername, host, 13);  /* Connect to the server.   */
    if
    (
        connect(sock, (struct sockaddr *) &servername, sizeof (servername)) 
        < 0
    )
        error("Can't connect to %s", host);

    read(sock, the_time, 199);      /* read info from the socket */

    close(sock);                    /* done */

    if
    (
        !nistserver(the_time)       /* find the type of server */
        &&
        !linuxserver(the_time)
    )
        error("Failed to retrieve time information from %s", host);

    if (display)
        printf(the_time);
}
