@@ -10,6 +10,8 @@ LOG_MODULE_DECLARE(net_shell);
10
10
11
11
#include <zephyr/net/socket.h>
12
12
#include <zephyr/net/dns_resolve.h>
13
+ #include <zephyr/net/dns_sd.h>
14
+ #include "dns/dns_sd.h"
13
15
14
16
#include "net_shell_private.h"
15
17
@@ -256,13 +258,62 @@ static int cmd_net_dns(const struct shell *sh, size_t argc, char *argv[])
256
258
return 0 ;
257
259
}
258
260
261
+ static int cmd_net_dns_list (const struct shell * sh , size_t argc , char * argv [])
262
+ {
263
+ #if defined(CONFIG_DNS_SD )
264
+ #define MAX_PORT_LEN 6
265
+ char buf [MAX_PORT_LEN ];
266
+ int n_records = 0 ;
267
+
268
+ DNS_SD_FOREACH (record ) {
269
+ if (!dns_sd_rec_is_valid (record )) {
270
+ continue ;
271
+ }
272
+
273
+ if (n_records == 0 ) {
274
+ PR (" DNS service records\n" );
275
+ }
276
+
277
+ ++ n_records ;
278
+
279
+ if (record -> port != NULL ) {
280
+ snprintk (buf , sizeof (buf ), "%u" , ntohs (* record -> port ));
281
+ }
282
+
283
+ PR ("[%2d] %s.%s%s%s%s%s%s%s\n" ,
284
+ n_records ,
285
+ record -> instance != NULL ? record -> instance : "" ,
286
+ record -> service != NULL ? record -> service : "" ,
287
+ record -> proto != NULL ? "." : "" ,
288
+ record -> proto != NULL ? record -> proto : "" ,
289
+ record -> domain != NULL ? "." : "" ,
290
+ record -> domain != NULL ? record -> domain : "" ,
291
+ record -> port != NULL ? ":" : "" ,
292
+ record -> port != NULL ? buf : "" );
293
+ }
294
+
295
+ if (n_records == 0 ) {
296
+ PR ("No DNS service records found.\n" );
297
+ return 0 ;
298
+ }
299
+ #else
300
+ PR_INFO ("DNS service discovery not supported. Set CONFIG_DNS_SD to "
301
+ "enable it.\n" );
302
+ #endif
303
+
304
+ return 0 ;
305
+ }
306
+
259
307
SHELL_STATIC_SUBCMD_SET_CREATE (net_cmd_dns ,
260
308
SHELL_CMD (cancel , NULL , "Cancel all pending requests." ,
261
309
cmd_net_dns_cancel ),
262
310
SHELL_CMD (query , NULL ,
263
311
"'net dns <hostname> [A or AAAA]' queries IPv4 address "
264
312
"(default) or IPv6 address for a host name." ,
265
313
cmd_net_dns_query ),
314
+ SHELL_CMD (list , NULL ,
315
+ "List local DNS service records." ,
316
+ cmd_net_dns_list ),
266
317
SHELL_SUBCMD_SET_END
267
318
);
268
319
0 commit comments