summaryrefslogtreecommitdiffstats
path: root/rtemsbsd/mdns
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-06 08:28:06 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-06 08:29:57 +0100
commit7a3fe8ef43993f7b598bacc07cf801a6265b11af (patch)
treebfa69eabc123b82ded1054151fa700d2b20552f8 /rtemsbsd/mdns
parentHOSTNAME(1): Import from FreeBSD (diff)
downloadrtems-libbsd-7a3fe8ef43993f7b598bacc07cf801a6265b11af.tar.bz2
Add rtems_mdns_sethostname()
Use it to set the multi-cast hostname of the default mDNS resolver instance via sethostname().
Diffstat (limited to 'rtemsbsd/mdns')
-rw-r--r--rtemsbsd/mdns/mdns-sethostname-default.c41
-rw-r--r--rtemsbsd/mdns/mdns.c41
2 files changed, 78 insertions, 4 deletions
diff --git a/rtemsbsd/mdns/mdns-sethostname-default.c b/rtemsbsd/mdns/mdns-sethostname-default.c
new file mode 100644
index 00000000..4db2c96a
--- /dev/null
+++ b/rtemsbsd/mdns/mdns-sethostname-default.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <rtems/mdns.h>
+
+static void
+mdns_sethostname_default(const char *hostname)
+{
+ /* Do nothing */
+}
+
+void (*rtems_mdns_sethostname_handler)(const char *hostname) =
+ mdns_sethostname_default;
diff --git a/rtemsbsd/mdns/mdns.c b/rtemsbsd/mdns/mdns.c
index 3cdcfe61..425c1276 100644
--- a/rtemsbsd/mdns/mdns.c
+++ b/rtemsbsd/mdns/mdns.c
@@ -31,6 +31,7 @@
#include <mDNSEmbeddedAPI.h>
#include <mDNSPosix.h>
+#include <DNSCommon.h>
#include <sys/select.h>
#include <sys/socket.h>
@@ -54,7 +55,7 @@
#include <rtems/bsd/util.h>
#include <rtems/mdns.h>
-static rtems_id daemon_id;
+static rtems_id mdns_daemon_id;
static mDNS mDNSStorage;
@@ -223,7 +224,7 @@ mdns_gethostbyname(void *rval, void *cb_data, va_list ap)
ctx.task_id = rtems_task_self();
mDNS_StartQuery(&mDNSStorage, &q);
- rtems_bsd_force_select_timeout(daemon_id);
+ rtems_bsd_force_select_timeout(mdns_daemon_id);
sc = rtems_event_transient_receive(RTEMS_WAIT,
10 * rtems_clock_get_ticks_per_second());
@@ -261,6 +262,36 @@ mdns_daemon(rtems_task_argument arg)
}
}
+static void
+truncate_at_first_dot(domainlabel *name)
+{
+ int c = name->c[0];
+ int n = 0;
+
+ while (n < c && name->c[n + 1] != '.') {
+ ++n;
+ }
+
+ name->c[0] = n;
+}
+
+static void
+mdns_sethostname(const char *hostname)
+{
+ mDNS *m = &mDNSStorage;
+
+ mDNS_Lock(m);
+
+ MakeDomainLabelFromLiteralString(&m->hostlabel, hostname);
+ truncate_at_first_dot(&m->hostlabel);
+
+ mDNS_Unlock(m);
+
+ mDNS_SetFQDN(m);
+
+ rtems_bsd_force_select_timeout(mdns_daemon_id);
+}
+
rtems_status_code
rtems_mdns_initialize(rtems_task_priority daemon_priority,
CacheEntity *rrcachestorage, mDNSu32 rrcachesize)
@@ -279,12 +310,12 @@ rtems_mdns_initialize(rtems_task_priority daemon_priority,
sc = rtems_task_create(rtems_build_name('m', 'D', 'N', 'S'),
daemon_priority, 16 * 1024, RTEMS_DEFAULT_MODES,
- RTEMS_DEFAULT_ATTRIBUTES, &daemon_id);
+ RTEMS_DEFAULT_ATTRIBUTES, &mdns_daemon_id);
if (sc != RTEMS_SUCCESSFUL) {
return (RTEMS_UNSATISFIED);
}
- sc = rtems_task_start(daemon_id, mdns_daemon, 0);
+ sc = rtems_task_start(mdns_daemon_id, mdns_daemon, 0);
if (sc != RTEMS_SUCCESSFUL) {
return (RTEMS_UNSATISFIED);
}
@@ -311,6 +342,8 @@ rtems_mdns_initialize(rtems_task_priority daemon_priority,
}
}
+ rtems_mdns_sethostname_handler = mdns_sethostname;
+
return (RTEMS_SUCCESSFUL);
}