mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-07-23 04:07:37 +08:00
Add rtems_mdns_gethostname()
This commit is contained in:
parent
4153ebe419
commit
026abfb7ae
2
Makefile
2
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/rtems/syslog.c
|
||||||
LIB_C_FILES += rtemsbsd/ftpd/ftpd.c
|
LIB_C_FILES += rtemsbsd/ftpd/ftpd.c
|
||||||
LIB_C_FILES += rtemsbsd/mdns/mdns.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/auth.c
|
||||||
LIB_C_FILES += rtemsbsd/pppd/ccp.c
|
LIB_C_FILES += rtemsbsd/pppd/ccp.c
|
||||||
LIB_C_FILES += rtemsbsd/pppd/chap.c
|
LIB_C_FILES += rtemsbsd/pppd/chap.c
|
||||||
|
@ -700,7 +700,7 @@ rtems.addRTEMSSourceFiles(
|
|||||||
'rtems/syslog.c',
|
'rtems/syslog.c',
|
||||||
'ftpd/ftpd.c',
|
'ftpd/ftpd.c',
|
||||||
'mdns/mdns.c',
|
'mdns/mdns.c',
|
||||||
'mdns/mdns-sethostname-default.c',
|
'mdns/mdns-hostname-default.c',
|
||||||
'pppd/auth.c',
|
'pppd/auth.c',
|
||||||
'pppd/ccp.c',
|
'pppd/ccp.c',
|
||||||
'pppd/chap.c',
|
'pppd/chap.c',
|
||||||
|
@ -41,7 +41,10 @@ extern "C" {
|
|||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
/* Private variable, do not touch. Use rtems_mdns_sethostname() instead. */
|
/* 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.
|
* @brief Initializes an mDNS resolver instance.
|
||||||
@ -77,11 +80,29 @@ mDNS *rtems_mdns_get_instance(void);
|
|||||||
* has no effect.
|
* has no effect.
|
||||||
*
|
*
|
||||||
* @param[in] hostname The new multicast hostname.
|
* @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(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
|
#ifdef __cplusplus
|
||||||
|
@ -31,11 +31,31 @@
|
|||||||
|
|
||||||
#include <rtems/mdns.h>
|
#include <rtems/mdns.h>
|
||||||
|
|
||||||
static void
|
#include <errno.h>
|
||||||
|
|
||||||
|
static int
|
||||||
mdns_sethostname_default(const char *hostname)
|
mdns_sethostname_default(const char *hostname)
|
||||||
{
|
{
|
||||||
/* Do nothing */
|
(void)hostname;
|
||||||
|
|
||||||
|
errno = ENXIO;
|
||||||
|
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void (*rtems_mdns_sethostname_handler)(const char *hostname) =
|
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;
|
mdns_sethostname_default;
|
||||||
|
|
||||||
|
int (*rtems_mdns_gethostname_handler)(char *hostname, size_t size) =
|
||||||
|
mdns_gethostname_default;
|
@ -275,7 +275,7 @@ truncate_at_first_dot(domainlabel *name)
|
|||||||
name->c[0] = n;
|
name->c[0] = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
mdns_sethostname(const char *hostname)
|
mdns_sethostname(const char *hostname)
|
||||||
{
|
{
|
||||||
mDNS *m = &mDNSStorage;
|
mDNS *m = &mDNSStorage;
|
||||||
@ -290,6 +290,28 @@ mdns_sethostname(const char *hostname)
|
|||||||
mDNS_SetFQDN(m);
|
mDNS_SetFQDN(m);
|
||||||
|
|
||||||
rtems_bsd_force_select_timeout(mdns_daemon_id);
|
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
|
rtems_status_code
|
||||||
@ -343,6 +365,7 @@ rtems_mdns_initialize(rtems_task_priority daemon_priority,
|
|||||||
}
|
}
|
||||||
|
|
||||||
rtems_mdns_sethostname_handler = mdns_sethostname;
|
rtems_mdns_sethostname_handler = mdns_sethostname;
|
||||||
|
rtems_mdns_gethostname_handler = mdns_gethostname;
|
||||||
|
|
||||||
return (RTEMS_SUCCESSFUL);
|
return (RTEMS_SUCCESSFUL);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user