Skip to content

Commit

Permalink
fix(windows): Fixed broadcast hostnames not being used.
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyost committed Jan 9, 2024
1 parent 808aade commit 57c8c9a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 15 deletions.
10 changes: 2 additions & 8 deletions packages/bonsoir_windows/windows/bonsoir_broadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,10 @@ namespace bonsoir_windows {
propertyKeys.push_back(nullptr);
propertyValues.push_back(nullptr);

PIP4_ADDRESS ipAddress = nullptr;
if (servicePtr->host.has_value() && isValidIPv4(servicePtr->host.value())) {
DWORD ip = std::stoul(servicePtr->host.value());
ipAddress = &ip;
}

auto computerHost = (getComputerName() + L".local");
std::wstring host = servicePtr->host.has_value() ? toUtf16(servicePtr->host.value()) : (getComputerName() + L".local");
PDNS_SERVICE_INSTANCE serviceInstance = DnsServiceConstructInstance(
toUtf16(servicePtr->name + "." + servicePtr->type + ".local").c_str(),
computerHost.c_str(),
host.c_str(),
nullptr,
nullptr,
static_cast<WORD>(servicePtr->port),
Expand Down
5 changes: 0 additions & 5 deletions packages/bonsoir_windows/windows/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,4 @@ namespace bonsoir_windows {
}
return &computerName[0];
}

bool isValidIPv4(const std::string &ipAddress) {
const std::regex ipv4Regex(R"(\b(?:\d{1,3}\.){3}\d{1,3}\b)");
return std::regex_match(ipAddress, ipv4Regex);
}
} // namespace bonsoir_windows
2 changes: 0 additions & 2 deletions packages/bonsoir_windows/windows/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ namespace bonsoir_windows {
std::tuple<std::string, std::string> parseBonjourFqdn(const std::string fqdn);

std::wstring getComputerName();

bool isValidIPv4(const std::string &ipAddress);
} // namespace bonsoir_windows

0 comments on commit 57c8c9a

Please sign in to comment.