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 15, 2024
1 parent 14235a0 commit 80f2148
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/app/cli/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ const std::map<std::string, std::string> &Interpreter::mUsageMap = *new std::map
{"br", "br list [--nwk <network-alias-list> | --dom <domain-name>]\n"
"br add <json-file-path>\n"
"br delete (<br-record-id> | --nwk <network-alias-list> | --dom <domain-name>)\n"
"br scan [--nwk <network-alias-list> | --dom <domain-name>] [--export <json-file-path>] [--timeout <ms>] [--netif <network-interface>]\n"},
"br scan [--nwk <network-alias-list> | --dom <domain-name>] [--export <json-file-path>] [--timeout <ms>] "
"[--netif <network-interface>]\n"},
{"domain", "domain list [--dom <domain-name>]"},
{"network", "network save <network-data-file>\n"
"network sync\n"
Expand Down Expand Up @@ -1421,7 +1422,7 @@ Interpreter::Value Interpreter::ProcessBr(const Expression &aExpr)
const std::string kServiceName = "_meshcop._udp.local";

uint32_t scanTimeout = 10000;
std::string netIf = "";
std::string netIf = "";
int mdnsSocket = -1;
FDGuard fdgMdnsSocket;
std::thread selectThread;
Expand All @@ -1446,15 +1447,20 @@ Interpreter::Value Interpreter::ProcessBr(const Expression &aExpr)
{
ExitNow(value = ERROR_INVALID_ARGS("Imparsable timeout value '{}'", *it));
}
} else {
}
else
{
ExitNow(value = ERROR_INVALID_ARGS("Missing {} value", *--it));
}
} else if (*it == "--netif")
}
else if (*it == "--netif")
{
if (++it != mContext.mCommandKeys.end())
{
netIf = *it;
} else {
}
else
{
ExitNow(value = ERROR_INVALID_ARGS("Missing {} value", *--it));
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/common/error_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@
{ \
ErrorCode::kUnknown, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) \
}
#define ERROR_SOCKET_BIND_ERROR(aFormat, ...) \
Error \
{ \
ErrorCode::kSocketBindError, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) \
#define ERROR_SOCKET_BIND_ERROR(aFormat, ...) \
Error \
{ \
ErrorCode::kSocketBindError, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) \
}

#endif // ERROR_MACROS_HPP_

0 comments on commit 80f2148

Please sign in to comment.