From 026abfb7ae8475987626dab4c600821c66e628c0 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 10 Nov 2014 08:27:32 +0100 Subject: Add rtems_mdns_gethostname() --- Makefile | 2 +- freebsd-to-rtems.py | 2 +- rtemsbsd/include/rtems/mdns.h | 27 ++++++++++++-- rtemsbsd/mdns/mdns-hostname-default.c | 61 ++++++++++++++++++++++++++++++++ rtemsbsd/mdns/mdns-sethostname-default.c | 41 --------------------- rtemsbsd/mdns/mdns.c | 25 ++++++++++++- 6 files changed, 111 insertions(+), 47 deletions(-) create mode 100644 rtemsbsd/mdns/mdns-hostname-default.c delete mode 100644 rtemsbsd/mdns/mdns-sethostname-default.c diff --git a/Makefile b/Makefile index 63a31782..db8bd24d 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +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/mdns/mdns-hostname-default.c LIB_C_FILES += rtemsbsd/pppd/auth.c LIB_C_FILES += rtemsbsd/pppd/ccp.c LIB_C_FILES += rtemsbsd/pppd/chap.c diff --git a/freebsd-to-rtems.py b/freebsd-to-rtems.py index 6c3450e4..31039b66 100755 --- a/freebsd-to-rtems.py +++ b/freebsd-to-rtems.py @@ -700,7 +700,7 @@ rtems.addRTEMSSourceFiles( 'rtems/syslog.c', 'ftpd/ftpd.c', 'mdns/mdns.c', - 'mdns/mdns-sethostname-default.c', + 'mdns/mdns-hostname-default.c', 'pppd/auth.c', 'pppd/ccp.c', 'pppd/chap.c', diff --git a/rtemsbsd/include/rtems/mdns.h b/rtemsbsd/include/rtems/mdns.h index d95978f3..b9c48dc3 100644 --- a/rtemsbsd/include/rtems/mdns.h +++ b/rtemsbsd/include/rtems/mdns.h @@ -41,7 +41,10 @@ extern "C" { #endif /* __cplusplus */ /* Private variable, do not touch. Use rtems_mdns_sethostname() instead. */ -extern void (*rtems_mdns_sethostname_handler)(const char *hostname); +extern int (*rtems_mdns_sethostname_handler)(const char *hostname); + +/* Private variable, do not touch. Use rtems_mdns_gethostname() instead. */ +extern int (*rtems_mdns_gethostname_handler)(char *hostname, size_t size); /** * @brief Initializes an mDNS resolver instance. @@ -77,11 +80,29 @@ mDNS *rtems_mdns_get_instance(void); * has no effect. * * @param[in] hostname The new multicast hostname. + * + * @retval 0 Successful operation. + * @retval -1 An error occurred. The errno is set to indicate the error. */ -static inline void +static inline int rtems_mdns_sethostname(const char *hostname) { - (*rtems_mdns_sethostname_handler)(hostname); + return (*rtems_mdns_sethostname_handler)(hostname); +} + +/** + * @brief Gets the multicast hostname of the mDNS resolver instance. + * + * @param[in] hostname The multicast hostname buffer. + * @param[in] size The size of the multicast hostname buffer. + * + * @retval 0 Successful operation. + * @retval -1 An error occurred. The errno is set to indicate the error. + */ +static inline int +rtems_mdns_gethostname(char *hostname, size_t size) +{ + return (*rtems_mdns_gethostname_handler)(hostname, size); } #ifdef __cplusplus diff --git a/rtemsbsd/mdns/mdns-hostname-default.c b/rtemsbsd/mdns/mdns-hostname-default.c new file mode 100644 index 00000000..a1d1f5f9 --- /dev/null +++ b/rtemsbsd/mdns/mdns-hostname-default.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2014 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * 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 + +#include + +static int +mdns_sethostname_default(const char *hostname) +{ + (void)hostname; + + errno = ENXIO; + + return (-1); +} + +static int +mdns_gethostname_default(char *hostname, size_t size) +{ + (void)hostname; + (void)size; + + errno = ENXIO; + + return (-1); +} + +int (*rtems_mdns_sethostname_handler)(const char *hostname) = + mdns_sethostname_default; + +int (*rtems_mdns_gethostname_handler)(char *hostname, size_t size) = + mdns_gethostname_default; diff --git a/rtemsbsd/mdns/mdns-sethostname-default.c b/rtemsbsd/mdns/mdns-sethostname-default.c deleted file mode 100644 index 4db2c96a..00000000 --- a/rtemsbsd/mdns/mdns-sethostname-default.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2014 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * 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 - -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 425c1276..2248e5b0 100644 --- a/rtemsbsd/mdns/mdns.c +++ b/rtemsbsd/mdns/mdns.c @@ -275,7 +275,7 @@ truncate_at_first_dot(domainlabel *name) name->c[0] = n; } -static void +static int mdns_sethostname(const char *hostname) { mDNS *m = &mDNSStorage; @@ -290,6 +290,28 @@ mdns_sethostname(const char *hostname) mDNS_SetFQDN(m); rtems_bsd_force_select_timeout(mdns_daemon_id); + + return (0); +} + +static int +mdns_gethostname(char *hostname, size_t size) +{ + mDNS *m = &mDNSStorage; + + if (size < MAX_ESCAPED_DOMAIN_LABEL) { + errno = ERANGE; + + return (-1); + } + + mDNS_Lock(m); + + ConvertDomainLabelToCString(&m->hostlabel, hostname); + + mDNS_Unlock(m); + + return (0); } rtems_status_code @@ -343,6 +365,7 @@ rtems_mdns_initialize(rtems_task_priority daemon_priority, } rtems_mdns_sethostname_handler = mdns_sethostname; + rtems_mdns_gethostname_handler = mdns_gethostname; return (RTEMS_SUCCESSFUL); } -- cgit v1.2.3