libdnsc/src/header.c

41 lines
788 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <netinet/in.h>
#include "header.h"
#include "constants.h"
static uint16_t next_packet_id = 0;
static uint16_t dns_header_get_next_packet_id (void) {
if (next_packet_id == 0) {
next_packet_id = 1 + ((int) (65534.0 * rand () / (RAND_MAX + 1.0)));
}
return next_packet_id++;;
}
void dns_header_init (DNSHeader *header) {
header->id = dns_header_get_next_packet_id ();
//header->id = 0x72de;
header->qr = QR_QUERY;
header->opcode = OPCODE_QUERY;
header->aa = 0;
header->tc = 0;
header->rd = 1;
header->ra = 0;
header->z = 0;
header->ad = 0;
header->cd = 0;
header->rcode = RCODE_NOERROR;
header->qdcount = 1;
header->ancount = 0;
header->nscount = 0;
header->arcount = 0;
}