Browse Source

Allow filtering with instance name in service_reply

This will allow sending replies more flexibly.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Rafał Miłecki 7 years ago
parent
commit
26ce7dca80
3 changed files with 9 additions and 6 deletions
  1. 2 2
      dns.c
  2. 6 3
      service.c
  3. 1 1
      service.h

+ 2 - 2
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;
 

+ 6 - 3
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);
 	}
 }
 

+ 1 - 1
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