Skip to content

Commit

Permalink
[mdns] Change mDNS host name at runtime.
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian Bulacu <[email protected]>
  • Loading branch information
Cristib05 authored and marius-preda committed Mar 28, 2024
1 parent d7359e9 commit e02d243
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/cli/cli_mdns_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ template <> otError MdnsServer::Process<Cmd("hostname")>(Arg aArgs[])
else
{
VerifyOrExit(aArgs[1].IsEmpty(), error = OT_ERROR_INVALID_ARGS);

error = otMdnsServerSetHostName(GetInstancePtr(), aArgs[0].GetCString());
}

Expand Down
16 changes: 14 additions & 2 deletions src/core/net/mdns_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,20 +1389,32 @@ Error MdnsServer::AddAddress(const Ip6::Address &aIp6Address)

Error MdnsServer::SetHostName(const char *aHostName)
{
Error error = kErrorNone;
Error error = kErrorNone;
Prober *prober = nullptr;

VerifyOrExit(aHostName != nullptr, error = kErrorInvalidArgs);
VerifyOrExit(Name::IsSubDomainOf(aHostName, kDefaultDomainName), error = kErrorInvalidArgs);

if (mHostName.IsNull())
{
error = mHostName.Set(aHostName);
}
else
{
error = StringMatch(mHostName.AsCString(), aHostName, kStringCaseInsensitiveMatch) ? kErrorNone : kErrorFailed;
VerifyOrExit(!StringMatch(mHostName.AsCString(), aHostName, kStringCaseInsensitiveMatch),
error = kErrorDuplicated);
prober = AllocateProber(true, nullptr, 0);
VerifyOrExit(prober != nullptr, error = kErrorNoBufs);
VerifyOrExit(mHostName.Set(aHostName) != kErrorNoBufs, error = kErrorNoBufs);
mIsHostVerifiedUnique = false;
PublishHostAndServices(prober);
}

exit:
if (error == kErrorNoBufs && prober)
{
RemoveProbingInstance(prober->GetId());
}
return error;
}

Expand Down

0 comments on commit e02d243

Please sign in to comment.