mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-10-15 04:59:27 +08:00
Add rtems_mdns_sethostname()
Use it to set the multi-cast hostname of the default mDNS resolver instance via sethostname().
This commit is contained in:
1
Makefile
1
Makefile
@@ -102,6 +102,7 @@ LIB_C_FILES += rtemsbsd/rtems/rtems-syslog-initialize.c
|
||||
LIB_C_FILES += rtemsbsd/rtems/syslog.c
|
||||
LIB_C_FILES += rtemsbsd/ftpd/ftpd.c
|
||||
LIB_C_FILES += rtemsbsd/mdns/mdns.c
|
||||
LIB_C_FILES += rtemsbsd/mdns/mdns-sethostname-default.c
|
||||
LIB_C_FILES += rtemsbsd/pppd/auth.c
|
||||
LIB_C_FILES += rtemsbsd/pppd/ccp.c
|
||||
LIB_C_FILES += rtemsbsd/pppd/chap.c
|
||||
|
@@ -700,6 +700,7 @@ rtems.addRTEMSSourceFiles(
|
||||
'rtems/syslog.c',
|
||||
'ftpd/ftpd.c',
|
||||
'mdns/mdns.c',
|
||||
'mdns/mdns-sethostname-default.c',
|
||||
'pppd/auth.c',
|
||||
'pppd/ccp.c',
|
||||
'pppd/chap.c',
|
||||
|
@@ -56,6 +56,9 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/smp.h>
|
||||
#include <sys/sx.h>
|
||||
#include <rtems/bsd/sys/unistd.h>
|
||||
#ifdef __rtems__
|
||||
#include <rtems/mdns.h>
|
||||
#endif /* __rtems__ */
|
||||
|
||||
SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW, 0,
|
||||
"Sysctl internal magic");
|
||||
@@ -326,6 +329,10 @@ sysctl_hostname(SYSCTL_HANDLER_ARGS)
|
||||
#else /* __rtems__ */
|
||||
(void) cpr;
|
||||
(void) descend;
|
||||
|
||||
if (pr_offset == offsetof(struct prison, pr_hostname)) {
|
||||
rtems_mdns_sethostname(tmpname);
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
mtx_unlock(&pr->pr_mtx);
|
||||
#ifndef __rtems__
|
||||
|
@@ -40,6 +40,9 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* Private variable, do not touch. Use rtems_mdns_sethostname() instead. */
|
||||
extern void (*rtems_mdns_sethostname_handler)(const char *hostname);
|
||||
|
||||
/**
|
||||
* @brief Initializes an mDNS resolver instance.
|
||||
*
|
||||
@@ -67,6 +70,20 @@ rtems_status_code rtems_mdns_initialize(rtems_task_priority daemon_priority,
|
||||
*/
|
||||
mDNS *rtems_mdns_get_instance(void);
|
||||
|
||||
/**
|
||||
* @brief Sets the multi-cast hostname of the mDNS resolver instance.
|
||||
*
|
||||
* In case the mDNS resolver instance is not initialized, then this function
|
||||
* has no effect.
|
||||
*
|
||||
* @param[in] hostname The new multi-cast hostname.
|
||||
*/
|
||||
static inline void
|
||||
rtems_mdns_sethostname(const char *hostname)
|
||||
{
|
||||
(*rtems_mdns_sethostname_handler)(hostname);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
41
rtemsbsd/mdns/mdns-sethostname-default.c
Normal file
41
rtemsbsd/mdns/mdns-sethostname-default.c
Normal file
@@ -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;
|
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user