From 3acbda1c5d19f2c380dacfedae87fd0f63a1c690 Mon Sep 17 00:00:00 2001 From: A Weinlein Date: Fri, 21 Dec 2012 18:02:50 +0100 Subject: [PATCH] Added API and test to add additional RRs (lAAAA RRs i.e.) --- mdnsd.c | 14 ++++++++++++++ mdnsd.h | 3 +++ testmdnsd.c | 11 +++++++++++ 3 files changed, 28 insertions(+) diff --git a/mdnsd.c b/mdnsd.c index f82e24b..b481665 100644 --- a/mdnsd.c +++ b/mdnsd.c @@ -46,6 +46,14 @@ #include #include +/* + * Define a proper IP socket level if not already done. + * Required to compile on OS X + */ +#ifndef SOL_IP +#define SOL_IP IPPROTO_IP +#endif + #include "mdns.h" #include "mdnsd.h" @@ -446,6 +454,12 @@ void mdnsd_set_hostname(struct mdnsd *svr, const char *hostname, uint32_t ip) { pthread_mutex_unlock(&svr->data_lock); } +void mdnsd_add_rr(struct mdnsd *svr, struct rr_entry *rr) { + pthread_mutex_lock(&svr->data_lock); + rr_group_add(&svr->group, rr); + pthread_mutex_unlock(&svr->data_lock); +} + struct mdns_service *mdnsd_register_svc(struct mdnsd *svr, const char *instance_name, const char *type, uint16_t port, const char *hostname, const char *txt[]) { struct rr_entry *txt_e = NULL, diff --git a/mdnsd.h b/mdnsd.h index c820f96..99f1b86 100644 --- a/mdnsd.h +++ b/mdnsd.h @@ -44,6 +44,9 @@ void mdnsd_stop(struct mdnsd *s); // sets the hostname for the given MDNS responder instance void mdnsd_set_hostname(struct mdnsd *svr, const char *hostname, uint32_t ip); +// adds an additional RR +void mdnsd_add_rr(struct mdnsd *svr, struct rr_entry *rr); + // registers a service with the MDNS responder instance struct mdns_service *mdnsd_register_svc(struct mdnsd *svr, const char *instance_name, const char *type, uint16_t port, const char *hostname, const char *txt[]); diff --git a/testmdnsd.c b/testmdnsd.c index a910650..08e6e60 100644 --- a/testmdnsd.c +++ b/testmdnsd.c @@ -47,6 +47,17 @@ int main(int argc, char *argv[]) { mdnsd_set_hostname(svr, hostname, inet_addr("192.168.0.29")); + struct rr_entry *a2_e = NULL; + a2_e = rr_create_a(create_nlabel(hostname), inet_addr("192.168.0.31")); + mdnsd_add_rr(svr, a2_e); + + struct rr_entry *aaaa_e = NULL; + struct in6_addr v6addr; + inet_pton(AF_INET6, "fe80::e2f8:47ff:fe20:28e0", &v6addr); + aaaa_e = rr_create_aaaa(create_nlabel(hostname), &v6addr); + + mdnsd_add_rr(svr, aaaa_e); + const char *txt[] = { "path=/mywebsite", NULL