From 920c62a794290deb962fff5d8b0c42009740e15e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Wed, 10 May 2017 22:45:47 +0200 Subject: [PATCH] Store instance name in the struct service MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This will allow using custom instace names in the future. Right now we always set it to the host-specific label so there is no behavior change yet with this patch. Signed-off-by: Rafał Miłecki --- service.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/service.c b/service.c index c8187de..e6d9618 100644 --- a/service.c +++ b/service.c @@ -46,6 +46,7 @@ struct service { time_t t; const char *id; + const char *instance; const char *service; const uint8_t *txt; int txt_len; @@ -74,14 +75,14 @@ static int service_init_announce; * * Service Instance Name = . . * - * @service_domain: service name (a pair of labels) with domain name appended + * @s: service to generate service instance name for */ static const char * -service_instance_name(const char *service_domain) +service_instance_name(struct service *s) { static char buffer[256]; - snprintf(buffer, sizeof(buffer), "%s.%s", umdns_host_label, service_domain); + snprintf(buffer, sizeof(buffer), "%s.%s", s->instance, s->service); return buffer; } @@ -127,7 +128,7 @@ service_timeout(struct service *s) static void service_reply_single(struct interface *iface, struct sockaddr *to, struct service *s, int ttl, int force) { - const char *host = service_instance_name(s->service); + const char *host = service_instance_name(s); char *service = strstr(host, "._"); time_t t = service_timeout(s); @@ -140,7 +141,7 @@ service_reply_single(struct interface *iface, struct sockaddr *to, struct servic s->t = t; dns_init_answer(); - service_add_ptr(service_instance_name(s->service), ttl); + service_add_ptr(service_instance_name(s), ttl); dns_send_answer(iface, to, service); dns_init_answer(); @@ -229,6 +230,7 @@ service_load_blob(struct blob_attr *b) s->port = blobmsg_get_u32(_tb[SERVICE_PORT]); s->id = strcpy(d_id, blobmsg_name(b)); + s->instance = umdns_host_label; s->service = strcpy(d_service, blobmsg_get_string(_tb[SERVICE_SERVICE])); s->active = 1; s->t = 0; -- 2.25.1