From ae4adf3736f43aea1a288d6693a1439ee04de969 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Tue, 14 Feb 2017 13:31:07 +0100 Subject: [PATCH] Add helper for checking if cached entry is for a host MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Rafał Miłecki --- cache.h | 3 +++ ubus.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) 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, "._"); -- 2.25.1