Skip to content

Commit

Permalink
Clean up IpAddress implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Oct 6, 2024
1 parent fd8e6a0 commit 5385f32
Showing 1 changed file with 5 additions and 13 deletions.
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

0 comments on commit 5385f32

Please sign in to comment.