From 832e5840d42e688fc0055b1b3ab96f8fd2b82940 Mon Sep 17 00:00:00 2001 From: lezhan Date: Thu, 11 Apr 2024 16:04:02 +0000 Subject: [PATCH] [cli] Update command "borderagent discovery" to allow network interface selection for mDNS binding. Within the OTBR practice application, the BR host will have several interfaces. When users want to discover the border agent using mDNS, they'll need to choose the specific interface the border agent is bound to. This change introduces a new option for the CLI command `borderagent dicover`. Users can now specify a network interface using the syntax `borderagent discovery `. The chosen interface will be used for mDNS binding through socket options. --- src/app/br_discover.cpp | 5 +++-- src/app/cli/interpreter.cpp | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/br_discover.cpp b/src/app/br_discover.cpp index 5edde091..c5818c0e 100644 --- a/src/app/br_discover.cpp +++ b/src/app/br_discover.cpp @@ -53,8 +53,9 @@ Error DiscoverBorderAgent(BorderAgentHandler aBorderAgentHandler, size_t aTimeou int socket = mdns_socket_open_ipv4(); VerifyOrExit(socket >= 0, error = ERROR_IO_ERROR("failed to open mDNS IPv4 socket")); - if (aNetIf != "" && setsockopt(socket, SOL_SOCKET, SO_BINDTODEVICE, &aNetIf[0], sizeof(aNetIf)) < 0) { - ExitNow(error = ERROR_IO_ERROR("failed to bind network interface: {}", aNetIf)); + if (aNetIf != "" && setsockopt(socket, SOL_SOCKET, SO_BINDTODEVICE, &aNetIf[0], sizeof(aNetIf)) < 0) + { + ExitNow(error = ERROR_SOCKET_BIND_ERROR("failed to bind network interface: {}", aNetIf)); } if (mdns_query_send(socket, kMdnsQueryType, kServiceName, strlen(kServiceName), buf, sizeof(buf)) != 0) diff --git a/src/app/cli/interpreter.cpp b/src/app/cli/interpreter.cpp index 722a8c96..afa1f751 100644 --- a/src/app/cli/interpreter.cpp +++ b/src/app/cli/interpreter.cpp @@ -1788,6 +1788,7 @@ Interpreter::Value Interpreter::ProcessBorderAgent(const Expression &aExpr) if (CaseInsensitiveEqual(aExpr[1], "discover")) { uint64_t timeout = 4000; + std::string netIf = ""; if (aExpr.size() >= 3) {