Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read AAAA records #57

Merged
merged 3 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions libmdnsd/1035.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,16 @@ static int _rrparse(struct message *m, struct resource *rr, int count, unsigned
*bufp += sizeof(rr[i].known.a.ip.s_addr);
break;

case QTYPE_AAAA:
if (m->_len + INET6_ADDRSTRLEN > MAX_PACKET_LEN)
return 1;
rr[i].known.aaaa.name = (char *)m->_packet + m->_len;
m->_len += INET6_ADDRSTRLEN;
inet_ntop(AF_INET6, *bufp, rr[i].known.aaaa.name, INET6_ADDRSTRLEN);
memcpy(rr[i].known.aaaa.ip6.s6_addr, *bufp, sizeof(rr[i].known.aaaa.ip6.s6_addr));
*bufp += sizeof(rr[i].known.aaaa.ip6.s6_addr);
break;

case QTYPE_NS:
if (_label(m, bufp, &(rr[i].known.ns.name)))
return 1;
Expand Down
5 changes: 5 additions & 0 deletions libmdnsd/1035.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct question {
#define QTYPE_CNAME 5
#define QTYPE_PTR 12
#define QTYPE_TXT 16
#define QTYPE_AAAA 28
#define QTYPE_SRV 33
#define QTYPE_ANY 255

Expand All @@ -67,6 +68,10 @@ struct resource {
struct in_addr ip;
char *name;
} a;
struct {
struct in6_addr ip6;
char *name;
} aaaa;
struct {
char *name;
} ns;
Expand Down
7 changes: 7 additions & 0 deletions libmdnsd/mdnsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ static int _a_match(struct resource *r, mdns_answer_t *a)
if (r->type == QTYPE_A || !memcmp(&r->known.a.ip, &a->ip, 4))
return 1;

if (r->type == QTYPE_AAAA || !memcmp(&r->known.aaaa.ip6, &a->ip6, 16))
return 1;

if (r->rdlength == a->rdlen && !memcmp(r->rdata, a->rdata, r->rdlength))
return 1;

Expand Down Expand Up @@ -561,6 +564,10 @@ static int _cache(mdns_daemon_t *d, struct resource *r, struct in_addr ip)
c->rr.ip = r->known.a.ip;
break;

case QTYPE_AAAA:
c->rr.ip6 = r->known.aaaa.ip6;
break;

case QTYPE_NS:
case QTYPE_CNAME:
case QTYPE_PTR:
Expand Down
1 change: 1 addition & 0 deletions libmdnsd/mdnsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef struct mdns_answer {
unsigned short int rdlen;
unsigned char *rdata;
struct in_addr ip; /* A, network byte order */
struct in6_addr ip6; /* AAAA, network byte order */
char *rdname; /* NS/CNAME/PTR/SRV */
struct {
unsigned short int priority, weight, port;
Expand Down
7 changes: 6 additions & 1 deletion src/mdnsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,19 @@ void mdnsd_conflict(char *name, int type, void *arg)

static void record_received(const struct resource *r, void *data)
{
char ipinput[INET_ADDRSTRLEN];
char ipinput[INET6_ADDRSTRLEN];

switch(r->type) {
case QTYPE_A:
inet_ntop(AF_INET, &(r->known.a.ip), ipinput, INET_ADDRSTRLEN);
DBG("Got %s: A %s->%s", r->name, r->known.a.name, ipinput);
break;

case QTYPE_AAAA:
inet_ntop(AF_INET6, &(r->known.aaaa.ip6), ipinput, INET6_ADDRSTRLEN);
DBG("Got %s: AAAA %s->%s", r->name, r->known.aaaa.name, ipinput);
break;

case QTYPE_NS:
DBG("Got %s: NS %s", r->name, r->known.ns.name);
break;
Expand Down
12 changes: 11 additions & 1 deletion src/mquery.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ static const char *type2str(int type)
case QTYPE_TXT:
return "TXT (16)";

case QTYPE_AAAA:
return "AAAA (28)";

case QTYPE_SRV:
return "SRV (33)";

Expand All @@ -130,6 +133,7 @@ static const char *type2str(int type)
static int ans(mdns_answer_t *a, void *arg)
{
int now;
char ipinput[INET6_ADDRSTRLEN];

if (a->ttl == 0)
now = 0;
Expand All @@ -155,7 +159,13 @@ static int ans(mdns_answer_t *a, void *arg)

switch (a->type) {
case QTYPE_A:
printf("A %s for %d seconds to ip %s\n", a->name, now, inet_ntoa(a->ip));
inet_ntop(AF_INET, &(a->ip), ipinput, INET_ADDRSTRLEN);
printf("A %s for %d seconds to ip %s\n", a->name, now, ipinput);
break;

case QTYPE_AAAA:
inet_ntop(AF_INET6, &(a->ip6), ipinput, INET6_ADDRSTRLEN);
printf("AAAA %s for %d seconds to ip %s\n", a->name, now, ipinput);
break;

case QTYPE_PTR:
Expand Down