|
8 | 8 | #include <zephyr/logging/log.h> |
9 | 9 | LOG_MODULE_DECLARE(net_shell); |
10 | 10 |
|
| 11 | +#include <zephyr/net/socket.h> |
11 | 12 | #include <zephyr/net/dns_resolve.h> |
12 | 13 |
|
13 | 14 | #include "net_shell_private.h" |
@@ -59,29 +60,55 @@ static void dns_result_cb(enum dns_resolve_status status, |
59 | 60 | PR_WARNING("dns: Unhandled status %d received\n", status); |
60 | 61 | } |
61 | 62 |
|
| 63 | +static const char *printable_iface(const char *iface_name, |
| 64 | + const char *found, |
| 65 | + const char *not_found) |
| 66 | +{ |
| 67 | + if (iface_name[0] != '\0') { |
| 68 | + return found; |
| 69 | + } |
| 70 | + |
| 71 | + return not_found; |
| 72 | +} |
| 73 | + |
62 | 74 | static void print_dns_info(const struct shell *sh, |
63 | 75 | struct dns_resolve_context *ctx) |
64 | 76 | { |
65 | | - int i; |
| 77 | + int i, ret; |
66 | 78 |
|
67 | 79 | PR("DNS servers:\n"); |
68 | 80 |
|
69 | 81 | for (i = 0; i < CONFIG_DNS_RESOLVER_MAX_SERVERS + |
70 | 82 | DNS_MAX_MCAST_SERVERS; i++) { |
| 83 | + char iface_name[IFNAMSIZ] = { 0 }; |
| 84 | + |
| 85 | + if (ctx->servers[i].if_index > 0) { |
| 86 | + ret = net_if_get_name( |
| 87 | + net_if_get_by_index(ctx->servers[i].if_index), |
| 88 | + iface_name, sizeof(iface_name)); |
| 89 | + if (ret < 0) { |
| 90 | + snprintk(iface_name, sizeof(iface_name), "%d", |
| 91 | + ctx->servers[i].if_index); |
| 92 | + } |
| 93 | + } |
| 94 | + |
71 | 95 | if (ctx->servers[i].dns_server.sa_family == AF_INET) { |
72 | | - PR("\t%s:%u\n", |
| 96 | + PR("\t%s:%u%s%s\n", |
73 | 97 | net_sprint_ipv4_addr( |
74 | 98 | &net_sin(&ctx->servers[i].dns_server)-> |
75 | 99 | sin_addr), |
76 | | - ntohs(net_sin( |
77 | | - &ctx->servers[i].dns_server)->sin_port)); |
| 100 | + ntohs(net_sin(&ctx->servers[i].dns_server)->sin_port), |
| 101 | + printable_iface(iface_name, " via ", ""), |
| 102 | + printable_iface(iface_name, iface_name, "")); |
| 103 | + |
78 | 104 | } else if (ctx->servers[i].dns_server.sa_family == AF_INET6) { |
79 | | - PR("\t[%s]:%u\n", |
| 105 | + PR("\t[%s]:%u%s%s\n", |
80 | 106 | net_sprint_ipv6_addr( |
81 | 107 | &net_sin6(&ctx->servers[i].dns_server)-> |
82 | 108 | sin6_addr), |
83 | | - ntohs(net_sin6( |
84 | | - &ctx->servers[i].dns_server)->sin6_port)); |
| 109 | + ntohs(net_sin6(&ctx->servers[i].dns_server)->sin6_port), |
| 110 | + printable_iface(iface_name, " via ", ""), |
| 111 | + printable_iface(iface_name, iface_name, "")); |
85 | 112 | } |
86 | 113 | } |
87 | 114 |
|
|
0 commit comments