Skip to content

Commit

Permalink
[cli] Update command "br scan" to allow network interface selection for
Browse files Browse the repository at this point in the history
mDNS binding.

Within the OTBR practice application, the BR host will have several
interfaces. When users want to discover the border router using mDNS,
they will need to choose the specific interface.

This change introduces a new option for the CLI command `br scan`. User
can now specify a network interface using the syntax `br scan --netif
<network interface>. The chosen interface will be used for mDNS binding
through socket options.
  • Loading branch information
ZhangLe2016 committed Apr 12, 2024
1 parent 688867a commit 6a068ab
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/app/cli/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,8 @@ Interpreter::Value Interpreter::ProcessBr(const Expression &aExpr)

auto it = std::find(mContext.mCommandKeys.begin(), mContext.mCommandKeys.end(), "--timeout");

if (it != mContext.mCommandKeys.end()) {
if (it != mContext.mCommandKeys.end())
{
try
{
scanTimeout = stol(mContext.mCommandKeys[std::distance(mContext.mCommandKeys.begin(), it) + 1]);
Expand All @@ -1447,15 +1448,17 @@ Interpreter::Value Interpreter::ProcessBr(const Expression &aExpr)

it = std::find(mContext.mCommandKeys.begin(), mContext.mCommandKeys.end(), "--netif");

if (it != mContext.mCommandKeys.end()) {
if (it != mContext.mCommandKeys.end())
{
netIf = mContext.mCommandKeys[std::distance(mContext.mCommandKeys.begin(), it) + 1];
}

// Open IPv4 mDNS socket
mdnsSocket = mdns_socket_open_ipv4();
VerifyOrExit(mdnsSocket >= 0, value = ERROR_IO_ERROR("failed to open mDNS IPv4 socket"));

if (!netIf.empty() && setsockopt(mdnsSocket, SOL_SOCKET, SO_BINDTODEVICE, netIf.c_str(), netIf.size()) < 0) {
if (!netIf.empty() && setsockopt(mdnsSocket, SOL_SOCKET, SO_BINDTODEVICE, netIf.c_str(), netIf.size()) < 0)
{
ExitNow(value = ERROR_SOCKET_BIND_ERROR("failed to bind network interface: {}", netIf));
}

Expand Down

0 comments on commit 6a068ab

Please sign in to comment.