Skip to content

Commit 261ee13

Browse files
committed
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 <[email protected]>
1 parent 07fb29f commit 261ee13

File tree

7 files changed

+342
-0
lines changed

7 files changed

+342
-0
lines changed

examples/mdnsd/Kconfig

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# For a description of the syntax of this configuration file,
3+
# see the file kconfig-language.txt in the NuttX tools repository.
4+
#
5+
6+
config EXAMPLES_MDNSD
7+
tristate "MDNS daemon example"
8+
default n
9+
depends on NETUTILS_MDNS_DAEMON
10+
---help---
11+
Enable the MDNS daemon example
12+
13+
if EXAMPLES_MDNSD
14+
15+
config EXAMPLES_MDNS_SERVICE
16+
string "Name of the mdns service"
17+
default "_nuttx._tcp.local"
18+
---help---
19+
This is the name of the service to be advertised by this example.
20+
The format is _service.protocol.domain where
21+
- "service" identifies the type of service being advertised such as
22+
_http, or _printer
23+
- "protocol" as used by the service (e.g. _udp or _tcp)
24+
- "domain" which for mDNS is most likely _local
25+
26+
config EXAMPLES_MDNS_SERVICE_PORT
27+
string "The port that the advertised service uses"
28+
default "32000"
29+
---help---
30+
The port the advertised service uses. The default is randomly chosen.
31+
32+
endif

examples/mdnsd/Make.defs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
############################################################################
2+
# apps/examples/mdnsd/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_EXAMPLES_MDNSD),)
24+
CONFIGURED_APPS += $(APPDIR)/examples/mdnsd
25+
endif

examples/mdnsd/Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
############################################################################
2+
# apps/examples/mdnsd/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 Daemon Example
26+
27+
CSRCS = mdnsd_daemon.c
28+
29+
MAINSRC = mdnsd_start.c mdnsd_stop.c
30+
31+
# MDNSD built-in application info
32+
33+
PROGNAME = mdnsd_start mdnsd_stop
34+
PRIORITY = SCHED_PRIORITY_DEFAULT
35+
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
36+
MODULE = $(CONFIG_EXAMPLES_MDNSD)
37+
38+
include $(APPDIR)/Application.mk

examples/mdnsd/mdnsd_daemon.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/****************************************************************************
2+
* apps/examples/mdnsd/mdnsd_daemon.c
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+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <nuttx/config.h>
28+
29+
#include <stdint.h>
30+
#include <stdlib.h>
31+
32+
#include "netutils/netlib.h"
33+
#include "netutils/mdnsd.h"
34+
#include "mdnsd_daemon.h"
35+
36+
/****************************************************************************
37+
* Preprocessor Definitions
38+
****************************************************************************/
39+
40+
/* Configuration Checks *****************************************************/
41+
42+
/* BEWARE:
43+
* There are other configuration settings needed in netutils/mdnsd/mdnsdc.c,
44+
* but there are default values for those so we cannot check them here.
45+
*/
46+
47+
#ifndef CONFIG_NET
48+
# error "You must define CONFIG_NET"
49+
#endif
50+
51+
#ifndef CONFIG_NET_UDP
52+
# error "You must define CONFIG_NET_UDP"
53+
#endif
54+
55+
#ifndef CONFIG_NET_BROADCAST
56+
# error "You must define CONFIG_NET_BROADCAST"
57+
#endif
58+
59+
/****************************************************************************
60+
* Private Types
61+
****************************************************************************/
62+
63+
/****************************************************************************
64+
* Private Function Prototypes
65+
****************************************************************************/
66+
67+
/****************************************************************************
68+
* Private Data
69+
****************************************************************************/
70+
71+
/****************************************************************************
72+
* Public Data
73+
****************************************************************************/
74+
75+
/****************************************************************************
76+
* Private Functions
77+
****************************************************************************/
78+
79+
/****************************************************************************
80+
* mdnsd_showusage
81+
****************************************************************************/
82+
83+
/****************************************************************************
84+
* Public Functions
85+
****************************************************************************/
86+
87+
/****************************************************************************
88+
* Name: mdnsd_daemon
89+
****************************************************************************/
90+
91+
int mdnsd_daemon(int argc, FAR char *argv[], bool start)
92+
{
93+
/* No arguments are needed for the example app */
94+
95+
if (start)
96+
{
97+
return mdnsd_start(CONFIG_EXAMPLES_MDNS_SERVICE,
98+
CONFIG_EXAMPLES_MDNS_SERVICE_PORT);
99+
}
100+
else
101+
{
102+
return mdnsd_stop();
103+
}
104+
}

examples/mdnsd/mdnsd_daemon.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/****************************************************************************
2+
* apps/examples/mdnsd/mdnsd_daemon.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_EXAMPLES_MDNSD_H
24+
#define __APPS_EXAMPLES_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_daemon(int argc, FAR char *argv[], bool start);
51+
52+
#undef EXTERN
53+
#ifdef __cplusplus
54+
}
55+
#endif
56+
57+
#endif /* __APPS_EXAMPLES_MDNSD_H */

examples/mdnsd/mdnsd_start.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/****************************************************************************
2+
* apps/examples/mdnsd/mdnsd_start.c
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+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <nuttx/config.h>
28+
#include <stdio.h>
29+
30+
#include "mdnsd_daemon.h"
31+
32+
/****************************************************************************
33+
* Public Functions
34+
****************************************************************************/
35+
36+
/****************************************************************************
37+
* Name: mdnsd_start_main
38+
****************************************************************************/
39+
40+
int main(int argc, FAR char *argv[])
41+
{
42+
return mdnsd_daemon(argc, argv, true);
43+
}

examples/mdnsd/mdnsd_stop.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/****************************************************************************
2+
* apps/examples/mdnsd/mdnsd_stop.c
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+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <nuttx/config.h>
28+
#include <stdio.h>
29+
30+
#include "mdnsd_daemon.h"
31+
32+
/****************************************************************************
33+
* Public Functions
34+
****************************************************************************/
35+
36+
/****************************************************************************
37+
* Name: mdnsd_stop_main
38+
****************************************************************************/
39+
40+
int main(int argc, char **argv)
41+
{
42+
return mdnsd_daemon(argc, argv, false);
43+
}

0 commit comments

Comments
 (0)