Ejemplo n.º 1
0
static int generate_srv_record(void *dns_record, char *buf)
{
	struct srv_record *record = dns_record;
	uint16_t priority = htons(record->priority);
	uint16_t weight = htons(record->weight);
	uint16_t port = htons(record->port);
	char *ptr = buf;

	if (!record->ignore_priority) {
		memcpy(ptr, &priority, sizeof(priority));
		ptr += sizeof(priority);
	}

	if (!record->ignore_weight) {
		memcpy(ptr, &weight, sizeof(weight));
		ptr += sizeof(weight);
	}

	if (!record->ignore_port) {
		memcpy(ptr, &port, sizeof(port));
		ptr += sizeof(port);
	}

	if (!record->ignore_host) {
		ptr += ast_dns_test_write_domain(record->host, ptr);
	}

	return ptr - buf;
}
Ejemplo n.º 2
0
/*!
 * \brief Given a NAPTR record, generate a binary form, as would appear in DNS RDATA
 *
 * This is part of a DNS answer, specific to NAPTR. It consists of all parts of
 * the NAPTR record, encoded as it should be in a DNS record.
 *
 * There is no buffer size passed to this function since we provide
 * the data ourselves and have sized the buffer to be way larger
 * than necessary for the tests.
 *
 * \param string The NAPTR record to encode
 * \param buf The buffer to write the record into
 * \return The number of bytes written to the buffer
 */
static int generate_naptr_record(void *dns_record, char *buf)
{
	struct naptr_record *record = dns_record;
	uint16_t net_order = htons(record->order);
	uint16_t net_preference = htons(record->preference);
	char *ptr = buf;

	memcpy(ptr, &net_order, sizeof(net_order));
	ptr += sizeof(net_order);

	memcpy(ptr, &net_preference, sizeof(net_preference));
	ptr += sizeof(net_preference);

	ptr += ast_dns_test_write_string(&record->flags, ptr);
	ptr += ast_dns_test_write_string(&record->services, ptr);
	ptr += ast_dns_test_write_string(&record->regexp, ptr);
	ptr += ast_dns_test_write_domain(record->replacement, ptr);

	return ptr - buf;
}