diff --git a/libmdnsd/1035.c b/libmdnsd/1035.c index cfd0c73..38fbfdc 100644 --- a/libmdnsd/1035.c +++ b/libmdnsd/1035.c @@ -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; diff --git a/libmdnsd/1035.h b/libmdnsd/1035.h index e2f403b..9409165 100644 --- a/libmdnsd/1035.h +++ b/libmdnsd/1035.h @@ -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 @@ -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; diff --git a/libmdnsd/mdnsd.c b/libmdnsd/mdnsd.c index b84627c..8e75dc4 100644 --- a/libmdnsd/mdnsd.c +++ b/libmdnsd/mdnsd.c @@ -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; @@ -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: diff --git a/libmdnsd/mdnsd.h b/libmdnsd/mdnsd.h index c796e61..0ff0f5c 100644 --- a/libmdnsd/mdnsd.h +++ b/libmdnsd/mdnsd.h @@ -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; diff --git a/src/mdnsd.c b/src/mdnsd.c index 3da7098..6c9d76b 100644 --- a/src/mdnsd.c +++ b/src/mdnsd.c @@ -71,7 +71,7 @@ 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: @@ -79,6 +79,11 @@ static void record_received(const struct resource *r, void *data) 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; diff --git a/src/mquery.c b/src/mquery.c index d601af1..67d9091 100644 --- a/src/mquery.c +++ b/src/mquery.c @@ -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)"; @@ -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; @@ -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: