27 #include "asterisk/dns_test.h"
32 const char DNS_HEADER[] = {
64 static int generate_dns_header(
unsigned short num_records,
char *buf)
66 unsigned short net_num_records = htons(num_records);
68 memcpy(buf, DNS_HEADER, ARRAY_LEN(DNS_HEADER));
70 memcpy(&buf[6], &net_num_records,
sizeof(num_records));
72 return ARRAY_LEN(DNS_HEADER);
75 const char DNS_QUESTION [] = {
77 0x05, 0x67, 0x6f, 0x6f, 0x73, 0x65,
79 0x08, 0x66, 0x65, 0x61, 0x74, 0x68, 0x65, 0x72, 0x73,
102 static int generate_dns_question(
char *buf)
104 memcpy(buf, DNS_QUESTION, ARRAY_LEN(DNS_QUESTION));
105 return ARRAY_LEN(DNS_QUESTION);
108 const char NAPTR_ANSWER [] = {
116 0x00, 0x00, 0x30, 0x39,
136 static int generate_dns_answer(
int ttl,
char *buf)
138 int net_ttl = htonl(ttl);
140 memcpy(buf, NAPTR_ANSWER, ARRAY_LEN(NAPTR_ANSWER));
143 memcpy(&buf[6], &net_ttl,
sizeof(
int));
146 return ARRAY_LEN(NAPTR_ANSWER);
151 uint8_t len =
string->len;
152 size_t actual_len = strlen(string->val);
160 memcpy(&buf[1], string->val, strlen(string->val));
163 return actual_len + 1;
166 int ast_dns_test_write_domain(
const char *
string,
char *buf)
178 part = strsep(©,
".");
179 if (ast_strlen_zero(part)) {
182 dns_str.len = strlen(part);
185 ptr += ast_dns_test_write_string(&dns_str, ptr);
187 ptr += ast_dns_test_write_string(&null_label, ptr);
192 int ast_dns_test_generate_result(
struct ast_dns_query *query,
void *records,
size_t num_records,
193 size_t record_size, record_fn generate,
char *buffer)
198 ptr += generate_dns_header(num_records, ptr);
199 ptr += generate_dns_question(ptr);
201 for (record_iter = records; record_iter < (
char *) records + num_records * record_size; record_iter += record_size) {
202 unsigned short rdlength;
203 unsigned short net_rdlength;
206 ptr += generate_dns_answer(0, ptr);
207 rdlength = generate(record_iter, ptr + 2);
208 net_rdlength = htons(rdlength);
209 memcpy(ptr, &net_rdlength, 2);
224 int ast_dns_test_write_domain(
const char *
string,
char *buf)
229 int ast_dns_test_generate_result(
struct ast_dns_query *query,
void *records,
size_t num_records,
230 size_t record_size, record_fn generate,
char *buffer)
Asterisk main include file. File version handling, generic pbx functions.
Representation of a string in DNS.
static int copy(char *infile, char *outfile)
Utility function to copy a file.
#define ast_strdupa(s)
duplicate a string in memory from the stack