dns_add_answer() now has a ttl parameter
authorJohn Crispin <blogic@openwrt.org>
Thu, 28 Aug 2014 08:15:21 +0000 (10:15 +0200)
committerJohn Crispin <blogic@openwrt.org>
Thu, 28 Aug 2014 08:15:21 +0000 (10:15 +0200)
Signed-off-by: John Crispin <blogic@openwrt.org>
dns.c
dns.h
service.c

diff --git a/dns.c b/dns.c
index 585b40f78a650b3a3856b691cdb736506def1f10..6fac7d19f440df32fb76ae3467d821834778ab1f 100644 (file)
--- a/dns.c
+++ b/dns.c
@@ -120,7 +120,7 @@ dns_init_answer(void)
 }
 
 void
-dns_add_answer(int type, const uint8_t *rdata, uint16_t rdlength)
+dns_add_answer(int type, const uint8_t *rdata, uint16_t rdlength, int ttl)
 {
        struct blob_attr *attr;
        struct dns_answer *a;
@@ -129,7 +129,7 @@ dns_add_answer(int type, const uint8_t *rdata, uint16_t rdlength)
        a = blob_data(attr);
        a->type = cpu_to_be16(type);
        a->class = cpu_to_be16(1);
-       a->ttl = cpu_to_be32(announce_ttl);
+       a->ttl = cpu_to_be32(ttl);
        a->rdlength = cpu_to_be16(rdlength);
        memcpy(a + 1, rdata, rdlength);
 
diff --git a/dns.h b/dns.h
index a238db4b228be0524a998f998cf399dac423e616..da4fb2149e876673ff7419814df3e54ae3e23b64 100644 (file)
--- a/dns.h
+++ b/dns.h
@@ -71,7 +71,7 @@ struct interface;
 
 void dns_send_question(struct interface *iface, const char *question, int type);
 void dns_init_answer(void);
-void dns_add_answer(int type, const uint8_t *rdata, uint16_t rdlength);
+void dns_add_answer(int type, const uint8_t *rdata, uint16_t rdlength, int ttl);
 void dns_send_answer(struct interface *iface, const char *answer);
 const char* dns_type_string(uint16_t type);
 void dns_handle_packet(struct interface *iface, uint8_t *buf, int len);
index 6b885deb03f6a084b19948bdba0af09796da0d9c..e4ec319c7deb950def9526fcd314a24de616bd1c 100644 (file)
--- a/service.c
+++ b/service.c
@@ -33,6 +33,7 @@
 #include "service.h"
 #include "util.h"
 #include "interface.h"
+#include "announce.h"
 
 enum {
        SERVICE_PORT,
@@ -85,7 +86,7 @@ service_add_ptr(const char *host)
        if (len < 1)
                return;
 
-       dns_add_answer(TYPE_PTR, mdns_buf, len);
+       dns_add_answer(TYPE_PTR, mdns_buf, len, announce_ttl);
 }
 
 static void
@@ -99,7 +100,7 @@ service_add_srv(struct service *s)
                return;
 
        sd->port = cpu_to_be16(s->port);
-       dns_add_answer(TYPE_SRV, mdns_buf, len);
+       dns_add_answer(TYPE_SRV, mdns_buf, len, announce_ttl);
 }
 
 #define TOUT_LOOKUP    60
@@ -135,7 +136,7 @@ service_reply_a(struct interface *iface, int type)
                        sa = (struct sockaddr_in *) ifa->ifa_addr;
                        addr = inet_ntoa(sa->sin_addr);
                        printf("Interface: %s\tAddress4: %s\n", ifa->ifa_name, addr);
-                       dns_add_answer(TYPE_A, (uint8_t *) &sa->sin_addr, 4);
+                       dns_add_answer(TYPE_A, (uint8_t *) &sa->sin_addr, 4, announce_ttl);
                }
                if (ifa->ifa_addr->sa_family==AF_INET6) {
                        uint8_t ll_prefix[] = {0xfe, 0x80 };
@@ -144,7 +145,7 @@ service_reply_a(struct interface *iface, int type)
                        if (!memcmp(&sa6->sin6_addr, &ll_prefix, 2)) {
                                if (inet_ntop(AF_INET6, &sa6->sin6_addr, buf, 64))
                                        printf("Interface: %s\tAddress6: %s\n", ifa->ifa_name, buf);
-                               dns_add_answer(TYPE_AAAA, (uint8_t *) &sa6->sin6_addr, 16);
+                               dns_add_answer(TYPE_AAAA, (uint8_t *) &sa6->sin6_addr, 16, announce_ttl);
                        }
                }
        }
@@ -177,7 +178,7 @@ service_reply(struct interface *iface, const char *match)
                dns_init_answer();
                service_add_srv(s);
                if (s->txt && s->txt_len)
-                       dns_add_answer(TYPE_TXT, (uint8_t *) s->txt, s->txt_len);
+                       dns_add_answer(TYPE_TXT, (uint8_t *) s->txt, s->txt_len, announce_ttl);
                dns_send_answer(iface, host);
        }