Allow filtering with instance name in service_reply
authorRafał Miłecki <rafal@milecki.pl>
Wed, 10 May 2017 20:45:48 +0000 (22:45 +0200)
committerRafał Miłecki <rafal@milecki.pl>
Fri, 12 May 2017 08:38:48 +0000 (10:38 +0200)
This will allow sending replies more flexibly.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
dns.c
service.c
service.h

diff --git a/dns.c b/dns.c
index 68a088f7fba6ba62fa6e8a981dedb714821c21b7..bccaa29525fdafde1de30060050b769ecc04b6a5 100644 (file)
--- a/dns.c
+++ b/dns.c
@@ -369,7 +369,7 @@ parse_question(struct interface *iface, struct sockaddr *from, char *name, struc
        case TYPE_ANY:
                if (!strcmp(name, mdns_hostname_local)) {
                        dns_reply_a(iface, to, announce_ttl);
-                       service_reply(iface, to, NULL, announce_ttl);
+                       service_reply(iface, to, NULL, NULL, announce_ttl);
                }
                break;
 
@@ -386,7 +386,7 @@ parse_question(struct interface *iface, struct sockaddr *from, char *name, struc
                        /* Make sure it's query for the instance name we use */
                        if (len && len == strlen(umdns_host_label) &&
                            !strncmp(name, umdns_host_label, len))
-                               service_reply(iface, to, dot + 1, announce_ttl);
+                               service_reply(iface, to, NULL, dot + 1, announce_ttl);
                }
                break;
 
index e6d9618d447c5156e51ba81314b1b6567fd66bd3..67e8f40a53b8c50417ba419e042863a226845011 100644 (file)
--- a/service.c
+++ b/service.c
@@ -152,13 +152,16 @@ service_reply_single(struct interface *iface, struct sockaddr *to, struct servic
 }
 
 void
-service_reply(struct interface *iface, struct sockaddr *to, const char *match, int ttl)
+service_reply(struct interface *iface, struct sockaddr *to, const char *instance, const char *service_domain, int ttl)
 {
        struct service *s;
 
        vlist_for_each_element(&services, s, node) {
-               if (!match || !strcmp(s->service, match))
-                       service_reply_single(iface, to, s, ttl, 0);
+               if (instance && strcmp(s->instance, instance))
+                       continue;
+               if (service_domain && strcmp(s->service, service_domain))
+                       continue;
+               service_reply_single(iface, to, s, ttl, 0);
        }
 }
 
index 086a0afb7c1d4ee6c806bf4faff1439d57d36754..db8f374256f445603bcbead6f8bdf62d726db6bc 100644 (file)
--- a/service.h
+++ b/service.h
@@ -16,7 +16,7 @@
 
 extern void service_init(int announce);
 extern void service_cleanup(void);
-extern void service_reply(struct interface *iface, struct sockaddr *to, const char *match, int ttl);
+extern void service_reply(struct interface *iface, struct sockaddr *to, const char *instance, const char *service_domain, int ttl);
 extern void service_announce_services(struct interface *iface, struct sockaddr *to, int ttl);
 
 #endif