examples: add mdnsd example application to accompany netutils/mdns library

This commit adds a new example app to allow the newly added netutils/mdns
library and associated daemon to be exeercised.

Signed-off-by: Tim Hardisty <timh@jti.uk.com>
This commit is contained in:
Tim Hardisty 2025-05-21 15:43:07 +01:00 committed by Xiang Xiao
parent 30b1c024a1
commit f0eb00ffd9
7 changed files with 342 additions and 0 deletions

32
examples/mdnsd/Kconfig Normal file
View file

@ -0,0 +1,32 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config EXAMPLES_MDNSD
tristate "MDNS daemon example"
default n
depends on NETUTILS_MDNS_DAEMON
---help---
Enable the MDNS daemon example
if EXAMPLES_MDNSD
config EXAMPLES_MDNS_SERVICE
string "Name of the mdns service"
default "_nuttx._tcp.local"
---help---
This is the name of the service to be advertised by this example.
The format is _service.protocol.domain where
- "service" identifies the type of service being advertised such as
_http, or _printer
- "protocol" as used by the service (e.g. _udp or _tcp)
- "domain" which for mDNS is most likely _local
config EXAMPLES_MDNS_SERVICE_PORT
string "The port that the advertised service uses"
default "32000"
---help---
The port the advertised service uses. The default is randomly chosen.
endif

25
examples/mdnsd/Make.defs Normal file
View file

@ -0,0 +1,25 @@
############################################################################
# apps/examples/mdnsd/Make.defs
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifneq ($(CONFIG_EXAMPLES_MDNSD),)
CONFIGURED_APPS += $(APPDIR)/examples/mdnsd
endif

38
examples/mdnsd/Makefile Normal file
View file

@ -0,0 +1,38 @@
############################################################################
# apps/examples/mdnsd/Makefile
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(APPDIR)/Make.defs
# MDNS Daemon Example
CSRCS = mdnsd_daemon.c
MAINSRC = mdnsd_start.c mdnsd_stop.c
# MDNSD built-in application info
PROGNAME = mdnsd_start mdnsd_stop
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
MODULE = $(CONFIG_EXAMPLES_MDNSD)
include $(APPDIR)/Application.mk

View file

@ -0,0 +1,104 @@
/****************************************************************************
* apps/examples/mdnsd/mdnsd_daemon.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdlib.h>
#include "netutils/netlib.h"
#include "netutils/mdnsd.h"
#include "mdnsd_daemon.h"
/****************************************************************************
* Preprocessor Definitions
****************************************************************************/
/* Configuration Checks *****************************************************/
/* BEWARE:
* There are other configuration settings needed in netutils/mdnsd/mdnsdc.c,
* but there are default values for those so we cannot check them here.
*/
#ifndef CONFIG_NET
# error "You must define CONFIG_NET"
#endif
#ifndef CONFIG_NET_UDP
# error "You must define CONFIG_NET_UDP"
#endif
#ifndef CONFIG_NET_BROADCAST
# error "You must define CONFIG_NET_BROADCAST"
#endif
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* mdnsd_showusage
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mdnsd_daemon
****************************************************************************/
int mdnsd_daemon(int argc, FAR char *argv[], bool start)
{
/* No arguments are needed for the example app */
if (start)
{
return mdnsd_start(CONFIG_EXAMPLES_MDNS_SERVICE,
CONFIG_EXAMPLES_MDNS_SERVICE_PORT);
}
else
{
return mdnsd_stop();
}
}

View file

@ -0,0 +1,57 @@
/****************************************************************************
* apps/examples/mdnsd/mdnsd_daemon.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __APPS_EXAMPLES_MDNSD_H
#define __APPS_EXAMPLES_MDNSD_H
/****************************************************************************
* Included Files
****************************************************************************/
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
int mdnsd_daemon(int argc, FAR char *argv[], bool start);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __APPS_EXAMPLES_MDNSD_H */

View file

@ -0,0 +1,43 @@
/****************************************************************************
* apps/examples/mdnsd/mdnsd_start.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include "mdnsd_daemon.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mdnsd_start_main
****************************************************************************/
int main(int argc, FAR char *argv[])
{
return mdnsd_daemon(argc, argv, true);
}

View file

@ -0,0 +1,43 @@
/****************************************************************************
* apps/examples/mdnsd/mdnsd_stop.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include "mdnsd_daemon.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mdnsd_stop_main
****************************************************************************/
int main(int argc, char **argv)
{
return mdnsd_daemon(argc, argv, false);
}