Skip to content

Commit

Permalink
[cli] Update command "borderagent discovery" to allow network interfa…
Browse files Browse the repository at this point in the history
…ce 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 <timeout> <network interface>`. The chosen
interface will be used for mDNS binding through socket options.
  • Loading branch information
ZhangLe2016 committed Apr 12, 2024
1 parent ad55466 commit 832e584
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/app/br_discover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/app/cli/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 832e584

Please sign in to comment.