From e804173595d49a537503ea08bec4663117bae047 Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Tue, 2 Apr 2019 21:31:33 +0200 Subject: Codechange: If something is a vector of strings, use a vector of strings instead of an AutoFreeSmallVector. --- src/network/core/address.cpp | 11 +++++------ src/network/core/address.h | 2 +- src/network/core/tcp_listen.h | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'src/network/core') 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); } diff --git a/src/network/core/address.h b/src/network/core/address.h index 2f26a3d00..bd1bab676 100644 --- a/src/network/core/address.h +++ b/src/network/core/address.h @@ -129,7 +129,7 @@ public: } bool IsFamily(int family); - bool IsInNetmask(char *netmask); + bool IsInNetmask(const char *netmask); /** * Compare the address of this class with the address of another. diff --git a/src/network/core/tcp_listen.h b/src/network/core/tcp_listen.h index 744f8841f..5668e48b2 100644 --- a/src/network/core/tcp_listen.h +++ b/src/network/core/tcp_listen.h @@ -54,13 +54,13 @@ public: /* Check if the client is banned */ bool banned = false; - for (char *entry : _network_ban_list) { - banned = address.IsInNetmask(entry); + for (const auto &entry : _network_ban_list) { + banned = address.IsInNetmask(entry.c_str()); if (banned) { Packet p(Tban_packet); p.PrepareToSend(); - DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), entry); + DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), entry.c_str()); if (send(s, (const char*)p.buffer, p.size, 0) < 0) { DEBUG(net, 0, "send failed with error %d", GET_LAST_ERROR()); -- cgit v1.2.3-70-g09d2