Fix replying to "QU" questions received on unicast interface
[project/mdnsd.git] / dns.c
diff --git a/dns.c b/dns.c
index 4c3dbf9..51a0150 100644 (file)
--- a/dns.c
+++ b/dns.c
@@ -99,7 +99,7 @@ dns_send_question(struct interface *iface, const char *question, int type, int m
 
        DBG(1, "Q <- %s %s\n", dns_type_string(type), question);
        if (interface_send_packet(iface, NULL, iov, ARRAY_SIZE(iov)) < 0)
-               perror("failed to send question :");
+               perror("failed to send question");
 }
 
 
@@ -178,7 +178,7 @@ dns_send_answer(struct interface *iface, struct sockaddr *to, const char *answer
        }
 
        if (interface_send_packet(iface, to, iov, n_iov) < 0)
-               fprintf(stderr, "failed to send question\n");
+               perror("failed to send answer");
 }
 
 void
@@ -351,15 +351,14 @@ parse_answer(struct interface *iface, uint8_t *buffer, int len, uint8_t **b, int
 static void
 parse_question(struct interface *iface, struct sockaddr *from, char *name, struct dns_question *q)
 {
-       struct sockaddr *to;
+       struct sockaddr *to = NULL;
        char *host;
 
        /* TODO: Multicast if more than one quarter of TTL has passed */
-       if ((q->class & CLASS_UNICAST) && iface->multicast) {
-               iface = iface->peer;
+       if (q->class & CLASS_UNICAST) {
                to = from;
-       } else {
-               to = NULL;
+               if (iface->multicast)
+                       iface = iface->peer;
        }
 
        DBG(1, "Q -> %s %s\n", dns_type_string(q->type), name);
@@ -373,7 +372,8 @@ parse_question(struct interface *iface, struct sockaddr *from, char *name, struc
                break;
 
        case TYPE_PTR:
-               if (!strcmp(name, sdudp)) {
+               if (!strcmp(name, C_DNS_SD)) {
+                       dns_reply_a(iface, to, announce_ttl);
                        service_announce_services(iface, to, announce_ttl);
                } else {
                        /* First dot separates instance name from the rest */
@@ -412,7 +412,7 @@ dns_handle_packet(struct interface *iface, struct sockaddr *s, uint16_t port, ui
                return;
        }
 
-       if (h->questions && !iface->multicast && port != 5353)
+       if (h->questions && !iface->multicast && port != MCAST_PORT)
                /* silently drop unicast questions that dont originate from port 5353 */
                return;