



// Structures

// Not used
struct DNS_REQUEST {
    int size;

   /*************************************************
    *                  DNS HEADER                   *
    *************************************************/
 /*
     0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                      ID                       |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |QR|   Opcode  |AA|TC|RD|RA|   Z    |   RCODE   |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    QDCOUNT                    |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    ANCOUNT                    |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    NSCOUNT                    |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    ARCOUNT                    |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 *
 */


/* Line 0 - ID */
    unsigned int id;           // A 16-bit identifer assigned by the program that generates
                               // any kind of query. This identifer is copied to the corresponding
                               // reply and can be used by the requester to match up replies
                               // to outstanding queries. You should select a new, random 16-bit
                               // number for each request.
/* Line 1 - OR, OPCODE, AA, TC, RD, RA, Z, RCODE */
    unsigned int flags;        // 0      : OR - set by query to 0, response returns 1
                               // 1 - 4  : OPCODE - set by query to 0 for standard query
                               // 5      : AA - set to 1 by response if athoritative response
                               // 6      : TC - respose truncated indicates error
                               // 7      : RD - set by query to 1 if recursion desired
                               // 8      : RA - recursion desired, 0 returned if unsupported
                               // 9-11   : Z - query sets to zero
                               // 12-15  : RCODE - query sets to 0
/* Line 2 - QDCOUNT*/
    unsigned int qdcount;      // 0 15   : how many queries - set to 1
/* Line 3 - ANCOUNT */
    unsigned int ancount;      // Stuff for the server to fill out. Query sets to 0
/* Line 4 - NSCOUNT */
    unsigned int nscount;      // Query sets to 0
/* Line 5 - ARCOUNT */
    unsigned int arcount;      // Query sets to 0

  /**************************************************
   *                  DNS QUESTION                  *
   **************************************************/
/*
      0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                                               |
    /                     QNAME                     /
    /                                               /
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                     QTYPE                     |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                     QCLASS                    |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*/
    unsigned char *query;    // Pointer to QNAME
    unsigned int qtype;      // Set by query to 0x0001
    unsigned int qclass;     // Set by query to 0x0001
};


// Not used
typedef struct
{
    uint8_t li_vn_mode;      // Eight bits. li, vn, and mode.
                             // li.   Two bits.   Leap indicator.
                             // vn.   Three bits. Version number of the protocol.
                             // mode. Three bits. Client will pick mode 3 for client.

    uint8_t stratum;         // Eight bits. Stratum level of the local clock.
    uint8_t poll;            // Eight bits. Maximum interval between successive messages.
    uint8_t precision;       // Eight bits. Precision of the local clock.

    uint32_t rootDelay;      // 32 bits. Total round trip delay time.
    uint32_t rootDispersion; // 32 bits. Max error aloud from primary clock source.
    uint32_t refId;          // 32 bits. Reference clock identifier.

    uint32_t refTm_s;        // 32 bits. Reference time-stamp seconds.
    uint32_t refTm_f;        // 32 bits. Reference time-stamp fraction of a second.

    uint32_t origTm_s;       // 32 bits. Originate time-stamp seconds.
    uint32_t origTm_f;       // 32 bits. Originate time-stamp fraction of a second.

    uint32_t rxTm_s;         // 32 bits. Received time-stamp seconds.
    uint32_t rxTm_f;         // 32 bits. Received time-stamp fraction of a second.

    uint32_t txTm_s;         // 32 bits and the most important field the client cares about. Transmit time-stamp seconds.
    uint32_t txTm_f;         // 32 bits. Transmit time-stamp fraction of a second.

} ntp_packet;                // Total: 384 bits or 48 bytes.


