summaryrefslogtreecommitdiff
path: root/src/session.cpp
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-04-04 11:53:03 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-04-07 16:32:07 +0800
commit4c904905f5f0667786d4c4b32d150b3d4328cfc2 (patch)
treea397604070be947ea051f0db3555c34e604686df /src/session.cpp
parent48c6f2384592c42a0fdbb6e420c77f6e10209f24 (diff)
session: use std::string for m_ip instead of c char
Diffstat (limited to 'src/session.cpp')
-rw-r--r--src/session.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/session.cpp b/src/session.cpp
index 36c2c6f..50f55bb 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -17,9 +17,11 @@ CSession::CSession()
if (!m_sockfd.isValid())
throw std::runtime_error("session: Failed to create socket");
- inet_ntop(AF_INET, &m_addr.sin_addr, m_ip, INET_ADDRSTRLEN);
+ m_ip.resize(INET_ADDRSTRLEN);
+ inet_ntop(AF_INET, &m_addr.sin_addr, &m_ip[0], INET_ADDRSTRLEN);
+ m_ip.resize(strlen(m_ip.c_str()));
m_port = ntohs(m_addr.sin_port);
- m_isAdmin = std::ranges::any_of(m_adminIps, [this](const char *ip) { return strcmp(ip, m_ip) == 0; });
+ m_isAdmin = std::ranges::any_of(m_adminIps, [this](const char *ip) { return m_ip == ip; });
log(LOG, "Client {} connected on port {}", m_ip, m_port);
log(TRACE, "session: initialized");
@@ -260,7 +262,7 @@ const std::string &CSession::getName() const {
return m_name;
}
-const char *CSession::getIp() const {
+const std::string &CSession::getIp() const {
return m_ip;
}