From: Rafał Miłecki Date: Fri, 10 Feb 2017 21:55:00 +0000 (+0100) Subject: Simplify UDP vs. TCP handling in service_announce_services X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=9879d5fcafed84a912baa8e2e2d3e73df1a9236d;p=oweals%2Fmdnsd.git Simplify UDP vs. TCP handling in service_announce_services Out of 3 calls of this function only one doesn't have TCP vs. UDP hardcoded. It's easier to move string check to that place and make this function take "int tcp" argument instead. Signed-off-by: Rafał Miłecki --- diff --git a/dns.c b/dns.c index de0c21a..550befc 100644 --- a/dns.c +++ b/dns.c @@ -367,7 +367,10 @@ parse_question(struct interface *iface, char *name, struct dns_question *q) break; case TYPE_PTR: - service_announce_services(iface, name, announce_ttl); + if (!strcmp(name, sdudp)) + service_announce_services(iface, 0, announce_ttl); + else if (!strcmp(name, sdtcp)) + service_announce_services(iface, 1, announce_ttl); service_reply(iface, name, announce_ttl); break; diff --git a/service.c b/service.c index 45b9345..e375fce 100644 --- a/service.c +++ b/service.c @@ -65,8 +65,8 @@ service_update(struct vlist_tree *tree, struct vlist_node *node_new, static struct blob_buf b; static VLIST_TREE(services, avl_strcmp, service_update, false, false); -static char *sdudp = "_services._dns-sd._udp.local"; -static char *sdtcp = "_services._dns-sd._tcp.local"; +char *sdudp = "_services._dns-sd._udp.local"; +char *sdtcp = "_services._dns-sd._tcp.local"; static int service_init_announce; static const char * @@ -155,15 +155,9 @@ service_reply(struct interface *iface, const char *match, int ttl) } void -service_announce_services(struct interface *iface, const char *service, int ttl) +service_announce_services(struct interface *iface, int tcp, int ttl) { struct service *s; - int tcp = 1; - - if (!strcmp(service, sdudp)) - tcp = 0; - else if (strcmp(service, sdtcp)) - return; vlist_for_each_element(&services, s, node) { if (!strstr(s->service, "._tcp") && tcp) @@ -186,8 +180,8 @@ service_announce_services(struct interface *iface, const char *service, int ttl) void service_announce(struct interface *iface, int ttl) { - service_announce_services(iface, sdudp, ttl); - service_announce_services(iface, sdtcp, ttl); + service_announce_services(iface, 0, ttl); + service_announce_services(iface, 1, ttl); } static void diff --git a/service.h b/service.h index c2f51f4..901bcbd 100644 --- a/service.h +++ b/service.h @@ -14,10 +14,12 @@ #ifndef _SERVICE_H__ #define _SERVICE_H__ +extern char *sdudp; +extern char *sdtcp; extern void service_init(int announce); extern void service_cleanup(void); extern void service_announce(struct interface *iface, int ttl); -extern void service_announce_services(struct interface *iface, const char *service, int ttl); extern void service_reply(struct interface *iface, const char *match, int ttl); +extern void service_announce_services(struct interface *iface, int tcp, int ttl); #endif