This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit f0eb00ffd99d6a520348c2ae552fff77e851957d
Author: Tim Hardisty <56726697+tim...@users.noreply.github.com>
AuthorDate: Wed May 21 15:43:07 2025 +0100

    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 <t...@jti.uk.com>
---
 examples/mdnsd/Kconfig        |  32 +++++++++++++
 examples/mdnsd/Make.defs      |  25 ++++++++++
 examples/mdnsd/Makefile       |  38 +++++++++++++++
 examples/mdnsd/mdnsd_daemon.c | 104 ++++++++++++++++++++++++++++++++++++++++++
 examples/mdnsd/mdnsd_daemon.h |  57 +++++++++++++++++++++++
 examples/mdnsd/mdnsd_start.c  |  43 +++++++++++++++++
 examples/mdnsd/mdnsd_stop.c   |  43 +++++++++++++++++
 7 files changed, 342 insertions(+)

diff --git a/examples/mdnsd/Kconfig b/examples/mdnsd/Kconfig
new file mode 100644
index 000000000..5b142d5d1
--- /dev/null
+++ b/examples/mdnsd/Kconfig
@@ -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
diff --git a/examples/mdnsd/Make.defs b/examples/mdnsd/Make.defs
new file mode 100644
index 000000000..96008aa5c
--- /dev/null
+++ b/examples/mdnsd/Make.defs
@@ -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
diff --git a/examples/mdnsd/Makefile b/examples/mdnsd/Makefile
new file mode 100644
index 000000000..316e6d817
--- /dev/null
+++ b/examples/mdnsd/Makefile
@@ -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
diff --git a/examples/mdnsd/mdnsd_daemon.c b/examples/mdnsd/mdnsd_daemon.c
new file mode 100644
index 000000000..bfa7759e8
--- /dev/null
+++ b/examples/mdnsd/mdnsd_daemon.c
@@ -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();
+    }
+}
diff --git a/examples/mdnsd/mdnsd_daemon.h b/examples/mdnsd/mdnsd_daemon.h
new file mode 100644
index 000000000..4fda59587
--- /dev/null
+++ b/examples/mdnsd/mdnsd_daemon.h
@@ -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 */
diff --git a/examples/mdnsd/mdnsd_start.c b/examples/mdnsd/mdnsd_start.c
new file mode 100644
index 000000000..865bde967
--- /dev/null
+++ b/examples/mdnsd/mdnsd_start.c
@@ -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);
+}
diff --git a/examples/mdnsd/mdnsd_stop.c b/examples/mdnsd/mdnsd_stop.c
new file mode 100644
index 000000000..45da47dd2
--- /dev/null
+++ b/examples/mdnsd/mdnsd_stop.c
@@ -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);
+}

Reply via email to