diff options
Diffstat (limited to 'src/network/core/address.h')
-rw-r--r-- | src/network/core/address.h | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/network/core/address.h b/src/network/core/address.h index 65546818b..b4364c95a 100644 --- a/src/network/core/address.h +++ b/src/network/core/address.h @@ -28,10 +28,10 @@ typedef SmallMap<NetworkAddress, SOCKET> SocketList; ///< Type for a mapping */ class NetworkAddress { private: - char hostname[NETWORK_HOSTNAME_LENGTH]; ///< The hostname - int address_length; ///< The length of the resolved address - sockaddr_storage address; ///< The resolved address - bool resolved; ///< Whether the address has been (tried to be) resolved + std::string hostname; ///< The hostname + int address_length; ///< The length of the resolved address + sockaddr_storage address; ///< The resolved address + bool resolved; ///< Whether the address has been (tried to be) resolved /** * Helper function to resolve something to a socket. @@ -52,7 +52,6 @@ public: address(address), resolved(address_length != 0) { - *this->hostname = '\0'; } /** @@ -64,7 +63,6 @@ public: address_length(address_length), resolved(address_length != 0) { - *this->hostname = '\0'; memset(&this->address, 0, sizeof(this->address)); memcpy(&this->address, address, address_length); } @@ -75,16 +73,15 @@ public: * @param port the port * @param family the address family */ - NetworkAddress(const char *hostname = "", uint16 port = 0, int family = AF_UNSPEC) : + NetworkAddress(std::string_view hostname = "", uint16 port = 0, int family = AF_UNSPEC) : address_length(0), resolved(false) { - /* Also handle IPv6 bracket enclosed hostnames */ - if (StrEmpty(hostname)) hostname = ""; - if (*hostname == '[') hostname++; - strecpy(this->hostname, StrEmpty(hostname) ? "" : hostname, lastof(this->hostname)); - char *tmp = strrchr(this->hostname, ']'); - if (tmp != nullptr) *tmp = '\0'; + if (!hostname.empty() && hostname.front() == '[' && hostname.back() == ']') { + hostname.remove_prefix(1); + hostname.remove_suffix(1); + } + this->hostname = hostname; memset(&this->address, 0, sizeof(this->address)); this->address.ss_family = family; |