summaryrefslogtreecommitdiff
path: root/src/network/core/address.cpp
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2019-04-02 21:31:33 +0200
committerMichael Lutz <michi@icosahedron.de>2019-04-09 22:45:15 +0200
commite804173595d49a537503ea08bec4663117bae047 (patch)
treeaca1af9b44daefab8ded671615d87e08a3a96059 /src/network/core/address.cpp
parentc7b9987d081ae4e0103309b18c93deecc395dec9 (diff)
downloadopenttd-e804173595d49a537503ea08bec4663117bae047.tar.xz
Codechange: If something is a vector of strings, use a vector of strings instead of an AutoFreeSmallVector.
Diffstat (limited to 'src/network/core/address.cpp')
-rw-r--r--src/network/core/address.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp
index 952229776..11b5d753f 100644
--- a/src/network/core/address.cpp
+++ b/src/network/core/address.cpp
@@ -156,7 +156,7 @@ bool NetworkAddress::IsFamily(int family)
* @note netmask without /n assumes all bits need to match.
* @return true if this IP is within the netmask.
*/
-bool NetworkAddress::IsInNetmask(char *netmask)
+bool NetworkAddress::IsInNetmask(const char *netmask)
{
/* Resolve it if we didn't do it already */
if (!this->IsResolved()) this->GetAddress();
@@ -166,17 +166,16 @@ bool NetworkAddress::IsInNetmask(char *netmask)
NetworkAddress mask_address;
/* Check for CIDR separator */
- char *chr_cidr = strchr(netmask, '/');
+ const char *chr_cidr = strchr(netmask, '/');
if (chr_cidr != NULL) {
int tmp_cidr = atoi(chr_cidr + 1);
/* Invalid CIDR, treat as single host */
if (tmp_cidr > 0 || tmp_cidr < cidr) cidr = tmp_cidr;
- /* Remove and then replace the / so that NetworkAddress works on the IP portion */
- *chr_cidr = '\0';
- mask_address = NetworkAddress(netmask, 0, this->address.ss_family);
- *chr_cidr = '/';
+ /* Remove the / so that NetworkAddress works on the IP portion */
+ std::string ip_str(netmask, chr_cidr - netmask);
+ mask_address = NetworkAddress(ip_str.c_str(), 0, this->address.ss_family);
} else {
mask_address = NetworkAddress(netmask, 0, this->address.ss_family);
}