From: Rafał Miłecki Date: Tue, 14 Feb 2017 12:31:07 +0000 (+0100) Subject: Add helper for checking if cached entry is for a host X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=ae4adf3736f43aea1a288d6693a1439ee04de969;p=project%2Fmdnsd.git Add helper for checking if cached entry is for a host Signed-off-by: Rafał Miłecki --- diff --git a/cache.h b/cache.h index 6c38977..7830b4f 100644 --- a/cache.h +++ b/cache.h @@ -54,6 +54,9 @@ void cache_cleanup(struct interface *iface); void cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struct dns_answer *a, uint8_t *rdata, int flush); int cache_host_is_known(char *record); +static inline bool cache_service_is_host(struct cache_service *s) { + return *((char *)s->avl.key) != '_'; +} void cache_dump_records(struct blob_buf *buf, const char *name); void cache_dump_recursive(struct blob_buf *b, const char *name, uint16_t type, struct interface *iface); diff --git a/ubus.c b/ubus.c index 69db2ac..a74df6c 100644 --- a/ubus.c +++ b/ubus.c @@ -59,7 +59,7 @@ umdns_browse(struct ubus_context *ctx, struct ubus_object *obj, blob_buf_init(&b, 0); avl_for_each_element(&services, s, avl) { char *local; - if (*((char *) s->avl.key) != '_') + if (cache_service_is_host(s)) continue; snprintf(buffer, MAX_NAME_LEN, "%s", (const char *) s->avl.key); local = strstr(buffer, ".local"); @@ -103,7 +103,7 @@ umdns_hosts(struct ubus_context *ctx, struct ubus_object *obj, blob_buf_init(&b, 0); avl_for_each_element(&services, s, avl) { char *local; - if (*((char *) s->avl.key) == '_') + if (!cache_service_is_host(s)) continue; snprintf(buffer, MAX_NAME_LEN, "%s", (const char *) s->entry); local = strstr(buffer, "._");