Skip to content

Commit

Permalink
[mDNS][DNS] Move dup code into common file
Browse files Browse the repository at this point in the history
  • Loading branch information
Devon Kerkhove committed Oct 31, 2014
1 parent a3300c1 commit 578e4ee
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
17 changes: 3 additions & 14 deletions modules/pico_dns_client.c
Expand Up @@ -221,7 +221,7 @@ static struct pico_dns_query *pico_dns_client_idcheck(uint16_t id)
return pico_tree_findKey(&DNSTable, &test);
}

static int pico_dns_client_query_header(struct pico_dns_header *pre)
static int pico_dns_client_query_header(struct pico_dns_header *hdr)
{
uint16_t id = 0;
uint8_t retry = 32;
Expand All @@ -233,19 +233,8 @@ static int pico_dns_client_query_header(struct pico_dns_header *pre)
if (!retry)
return -1;

pre->id = short_be(id);
pre->qr = PICO_DNS_QR_QUERY;
pre->opcode = PICO_DNS_OPCODE_QUERY;
pre->aa = PICO_DNS_AA_NO_AUTHORITY;
pre->tc = PICO_DNS_TC_NO_TRUNCATION;
pre->rd = PICO_DNS_RD_IS_DESIRED;
pre->ra = PICO_DNS_RA_NO_SUPPORT;
pre->z = 0;
pre->rcode = PICO_DNS_RCODE_NO_ERROR;
pre->qdcount = short_be(1);
pre->ancount = short_be(0);
pre->nscount = short_be(0);
pre->arcount = short_be(0);
hdr->id = short_be(id);
pico_dns_fill_record_header(hdr, 1, 0); /* 1 query, no answers */

return 0;
}
Expand Down
26 changes: 26 additions & 0 deletions modules/pico_dns_common.c
Expand Up @@ -16,6 +16,32 @@
#include "pico_dns_client.h"
#include "pico_tree.h"

void pico_dns_fill_record_header(struct pico_dns_header *hdr, uint16_t qdcount, uint16_t ancount)
{

/* hdr->id should be filled by caller */

if(qdcount > 0) {
hdr->qr = PICO_DNS_QR_QUERY;
hdr->aa = PICO_DNS_AA_NO_AUTHORITY;
}
else {
hdr->qr = PICO_DNS_QR_RESPONSE;
hdr->aa = PICO_DNS_AA_IS_AUTHORITY;
}

hdr->opcode = PICO_DNS_OPCODE_QUERY;
hdr->tc = PICO_DNS_TC_NO_TRUNCATION;
hdr->rd = PICO_DNS_RD_NO_DESIRE;
hdr->ra = PICO_DNS_RA_NO_SUPPORT;
hdr->z = 0; /* Z, AD, CD are 0 */
hdr->rcode = PICO_DNS_RCODE_NO_ERROR;
hdr->qdcount = short_be(qdcount);
hdr->ancount = short_be(ancount);
hdr->nscount = short_be(0);
hdr->arcount = short_be(0);
}

/* determine len of string */
uint16_t pico_dns_client_strlen(const char *url)
{
Expand Down
1 change: 1 addition & 0 deletions modules/pico_dns_common.h
Expand Up @@ -88,6 +88,7 @@ enum pico_dns_arpa
PICO_DNS_NO_ARPA,
};

void pico_dns_fill_record_header(struct pico_dns_header *hdr, uint16_t qdcount, uint16_t ancount);
uint16_t pico_dns_client_strlen(const char *url);
int pico_dns_client_query_domain(char *ptr);
int pico_dns_client_answer_domain(char *ptr);
Expand Down
18 changes: 1 addition & 17 deletions modules/pico_mdns.c
Expand Up @@ -246,23 +246,7 @@ static struct pico_dns_header *pico_mdns_add_cookie(struct pico_dns_header *hdr,
static void pico_mdns_fill_header(struct pico_dns_header *hdr, uint16_t qdcount, uint16_t ancount)
{
hdr->id = short_be(0);
if(qdcount) {
hdr->qr = PICO_DNS_QR_QUERY;
hdr->aa = PICO_DNS_AA_NO_AUTHORITY;
} else {
hdr->qr = PICO_DNS_QR_RESPONSE;
hdr->aa = PICO_DNS_AA_IS_AUTHORITY;
}

hdr->opcode = PICO_DNS_OPCODE_QUERY;
hdr->tc = PICO_DNS_TC_NO_TRUNCATION;
hdr->rd = PICO_DNS_RD_NO_DESIRE;
hdr->ra = PICO_DNS_RA_NO_SUPPORT;
hdr->z = 0; /* 3 reserved zero bits */
hdr->qdcount = short_be(qdcount);
hdr->ancount = short_be(ancount);
hdr->nscount = short_be(0);
hdr->arcount = short_be(0);
pico_dns_fill_record_header(hdr, qdcount, ancount);
}

static void pico_mdns_answer_suffix(struct pico_dns_answer_suffix *asuf, uint16_t qtype, uint16_t qclass, uint32_t ttl, uint16_t rdlength)
Expand Down

0 comments on commit 578e4ee

Please sign in to comment.