Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up sfIpAddress implementation #369

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions src/CSFML/Network/IpAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,13 @@ namespace
// Helper function for converting a SFML address to a CSFML one
[[nodiscard]] sfIpAddress fromSFMLAddress(std::optional<sf::IpAddress> address)
{
sfIpAddress result{};

if (address)
{
std::strncpy(result.address, address->toString().c_str(), 15);
}
if (!address)
return sfIpAddress_None;

sfIpAddress result{};
std::strncpy(result.address, address->toString().c_str(), 15);
return result;
}

// Helper function for converting a CSFML address to a SFML one
[[nodiscard]] std::optional<sf::IpAddress> toSFMLAddress(sfIpAddress address)
{
return sf::IpAddress::resolve(address.address);
}
} // namespace


Expand Down Expand Up @@ -104,7 +96,7 @@ void sfIpAddress_toString(sfIpAddress address, char* string)
////////////////////////////////////////////////////////////
uint32_t sfIpAddress_toInteger(sfIpAddress address)
{
auto sfmlAddress = toSFMLAddress(address);
const auto sfmlAddress = sf::IpAddress::resolve(address.address);
return sfmlAddress ? sfmlAddress->toInteger() : 0;
}

Expand Down
Loading