Skip to content

Commit 07fb29f

Browse files
committed
apps/netutils: add mdns library support
This commit allows an external mDNS library to be included in NuttX. It originates from here: <https://github.com/mjansson/mdns> It is declared as being in the Public Domain as per <http://unlicense.org> Signed-off-by: Tim Hardisty <[email protected]>
1 parent a8740c2 commit 07fb29f

File tree

6 files changed

+468
-0
lines changed

6 files changed

+468
-0
lines changed

include/netutils/mdnsd.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/****************************************************************************
2+
* apps/netutils/mdnsd.h
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
#ifndef __APPS_INCLUDE_NETUTILS_MDNSD_H
24+
#define __APPS_INCLUDE_NETUTILS_MDNSD_H
25+
26+
/****************************************************************************
27+
* Included Files
28+
****************************************************************************/
29+
30+
/****************************************************************************
31+
* Pre-processor Definitions
32+
****************************************************************************/
33+
34+
/****************************************************************************
35+
* Public Types
36+
****************************************************************************/
37+
38+
/****************************************************************************
39+
* Public Function Prototypes
40+
****************************************************************************/
41+
42+
#ifdef __cplusplus
43+
#define EXTERN extern "C"
44+
extern "C"
45+
{
46+
#else
47+
#define EXTERN extern
48+
#endif
49+
50+
int mdnsd_start(FAR char *service_name, FAR char *service_port);
51+
int mdnsd_stop(void);
52+
53+
#undef EXTERN
54+
#ifdef __cplusplus
55+
}
56+
#endif
57+
58+
#endif /* __APPS_INCLUDE_NETUTILS_MDNSD_H */

netutils/mdns/Kconfig

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
config LIB_MDNS
2+
bool "MDNS library"
3+
default n
4+
---help---
5+
Enable the mDNS library. This allows calls to the library to be made.
6+
7+
This external library is "unlicensed" using the methodology from
8+
http://unlicense.org
9+
10+
You should be sure that this license is acceptable for your usage.
11+
12+
By default, the "built-in" demo is added as an application that can
13+
be run from nsh <mdns>.
14+
15+
This is also needed for the optional daemon that allows the demo
16+
app's mDNS functionality to be started and stopped from user
17+
applications. There is an associated example app
18+
(CONFIG_EXAMPLES_MDNSD) to allow the daemon to be tried from nsh.
19+
20+
Ultimately, this should be used simply as a library, and neither the
21+
demo app nor the daemon utilised. If just built as a library,the
22+
relevant header file <mdns.h> is copied to the usual netutils
23+
include location and can be utilised be including it:
24+
25+
#include <netutils/mdns.h>
26+
27+
if LIB_MDNS
28+
29+
config NETUTILS_MDNS
30+
tristate "Enable mdns built-in demo app"
31+
default n
32+
---help---
33+
Enable the author's original built-in MDNS demo app. This allows the
34+
functionality of the library to be demonstrated. Information on using
35+
it is available from the original git repo for this external library:
36+
37+
https://github.com/mjansson/mdns
38+
39+
if NETUTILS_MDNS
40+
41+
config NETUTILS_MDNS_PROGNAME
42+
string "mDNS program name"
43+
default "mdns"
44+
---help---
45+
This is the name of the program that will be used when the NSH ELF
46+
program is installed.
47+
48+
config NETUTILS_MDNS_PRIORITY
49+
int "mDNS task priority"
50+
default 100
51+
52+
config NETUTILS_MDNS_STACKSIZE
53+
int "mDNS stack size"
54+
default DEFAULT_TASK_STACKSIZE
55+
---help---
56+
The default (4KiB) is adequate for simple networks but this will
57+
most likely need to be increased if there are many network devices
58+
attached that could send queries.
59+
60+
config NETUTILS_MDNS_VERBOSE
61+
bool "Enable verbose printf output from built-in mdns demo"
62+
default y
63+
endif
64+
65+
config NETUTILS_MDNS_DAEMON
66+
tristate "Wrap mdns demo app as a daemon, which can be started/stopped"
67+
default n
68+
depends on NETUTILS_MDNS
69+
---help---
70+
This option wraps the mdns demo app as a daemon, so requires
71+
CONFIG_NETUTILS_MDNS to be selected.
72+
73+
There is also an example app (CONFIG_EXAMPLES_MDNSD) to allow the
74+
mdns daemon to be started/stopped via the NuttX shell.
75+
76+
config NETUTILS_MDNS_DAEMON_STOP_SIGNAL
77+
int "Signal used to stop the MDNSD daemon"
78+
default 22
79+
depends on NETUTILS_MDNS_DAEMON
80+
81+
endif #NETUTILS_MDNS

netutils/mdns/Make.defs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
############################################################################
2+
# apps/netutils/mdns/Make.defs
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more
7+
# contributor license agreements. See the NOTICE file distributed with
8+
# this work for additional information regarding copyright ownership. The
9+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
# "License"); you may not use this file except in compliance with the
11+
# License. You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
############################################################################
22+
23+
ifneq ($(CONFIG_LIB_MDNS),)
24+
CONFIGURED_APPS += $(APPDIR)/netutils/mdns
25+
endif

netutils/mdns/Makefile

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
############################################################################
2+
# netutils/mdns/Makefile
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more
7+
# contributor license agreements. See the NOTICE file distributed with
8+
# this work for additional information regarding copyright ownership. The
9+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
# "License"); you may not use this file except in compliance with the
11+
# License. You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
############################################################################
22+
23+
include $(APPDIR)/Make.defs
24+
25+
# mDNS application
26+
27+
############################################################################
28+
# Flags
29+
############################################################################
30+
31+
MDNS_URL ?= "https://github.com/mjansson/mdns/archive"
32+
33+
MDNS_VERSION = main
34+
MDNS_ZIP = $(MDNS_VERSION).zip
35+
36+
MDNS_UNPACKNAME = mdns
37+
UNPACK ?= unzip -q -o
38+
39+
VPATH += $(MDNS_UNPACKNAME)
40+
VPATH += $(MDNS_UNPACKNAME)$(DELIM)posix
41+
DEPPATH += --dep-path $(MDNS_UNPACKNAME)
42+
DEPPATH += --dep-path $(MDNS_UNPACKNAME)$(DELIM)posix
43+
44+
CFLAGS += -Wno-strict-prototypes -Wno-undef -Wno-format
45+
46+
APPS_INCDIR = $(APPDIR)$(DELIM)include$(DELIM)netutils
47+
48+
############################################################################
49+
# Targets
50+
############################################################################
51+
52+
$(MDNS_ZIP):
53+
@echo "Downloading: $(MDNS_URL)/$(MDNS_ZIP)"
54+
$(Q) curl -O -L $(MDNS_URL)/$(MDNS_ZIP)
55+
56+
$(MDNS_UNPACKNAME): $(MDNS_ZIP)
57+
@echo "Unpacking: $(MDNS_ZIP) -> $(MDNS_UNPACKNAME)"
58+
$(Q) $(UNPACK) $(MDNS_ZIP)
59+
$(Q) mv mdns-$(MDNS_VERSION) $(MDNS_UNPACKNAME)
60+
$(Q) cp $(MDNS_UNPACKNAME)$(DELIM)mdns.h $(APPS_INCDIR)
61+
$(Q) patch -p0 < verbose_option.patch # Update to enable non-verbose mode
62+
$(Q) touch $(MDNS_UNPACKNAME)
63+
64+
clean::
65+
$(call DELFILE, $(OBJS))
66+
67+
# Download and unpack tarball if no git repo found
68+
69+
ifeq ($(wildcard $(MDNS_UNPACKNAME)/.git),)
70+
context:: $(MDNS_UNPACKNAME)
71+
72+
distclean::
73+
$(call DELFILE, $(OBJS))
74+
$(call DELDIR, $(MDNS_UNPACKNAME))
75+
$(call DELFILE, $(APPS_INCDIR)$(DELIM)mdns.h)
76+
$(call DELFILE, $(MDNS_ZIP))
77+
endif
78+
79+
############################################################################
80+
# Applications Configuration
81+
############################################################################
82+
83+
include $(APPDIR)/Make.defs
84+
85+
ifneq ($(CONFIG_NETUTILS_MDNS),)
86+
PROGNAME = $(CONFIG_NETUTILS_MDNS_PROGNAME)
87+
PRIORITY = $(CONFIG_NETUTILS_MDNS_PRIORITY)
88+
STACKSIZE = $(CONFIG_NETUTILS_MDNS_STACKSIZE)
89+
MODULE = $(CONFIG_NETUTILS_MDNS)
90+
91+
MAINSRC = mdns/mdns.c
92+
else
93+
CSRCS += mdns/mdns.c
94+
endif
95+
96+
ifneq ($(CONFIG_NETUTILS_MDNS_DAEMON),)
97+
CSRCS += mdnsd.c
98+
endif
99+
100+
# This is an external library so we accept NuttX style violations
101+
102+
CFLAGS += -Wno-undef -Wno-strict-prototypes -Wno-unused-variable \
103+
-Wno-pointer-sign -Wno-unused-but-set-variable -Wno-shadow \
104+
-Wno-format
105+
106+
include $(APPDIR)/Application.mk

0 commit comments

Comments
 (0)