diff options
author | Peter Powell <petpow@saberuk.com> | 2017-08-28 15:37:15 +0100 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2017-09-12 15:05:24 +0100 |
commit | fb13dca410541f01db84287f2721d1e256eaf2b5 (patch) | |
tree | 53b1c9de79ba80719a7e054de455d86c27676384 /src | |
parent | 3b595d39a50e38283768bc6ec8aeb9e73071224f (diff) |
Store the server endpoint as a sockaddrs in ListenSocket.
Diffstat (limited to 'src')
-rw-r--r-- | src/coremods/core_stats.cpp | 10 | ||||
-rw-r--r-- | src/listensocket.cpp | 12 | ||||
-rw-r--r-- | src/modules/m_flashpolicyd.cpp | 2 | ||||
-rw-r--r-- | src/socket.cpp | 7 |
4 files changed, 9 insertions, 22 deletions
diff --git a/src/coremods/core_stats.cpp b/src/coremods/core_stats.cpp index b91653908..9d1fdf3fe 100644 --- a/src/coremods/core_stats.cpp +++ b/src/coremods/core_stats.cpp @@ -99,18 +99,10 @@ void CommandStats::DoStats(Stats::Context& stats) for (std::vector<ListenSocket*>::const_iterator i = ServerInstance->ports.begin(); i != ServerInstance->ports.end(); ++i) { ListenSocket* ls = *i; - std::string ip = ls->bind_addr; - if (ip.empty()) - ip.assign("*"); - else if (ip.find_first_of(':') != std::string::npos) - { - ip.insert(ip.begin(), '['); - ip.insert(ip.end(), ']'); - } std::string type = ls->bind_tag->getString("type", "clients"); std::string hook = ls->bind_tag->getString("ssl", "plaintext"); - stats.AddRow(249, ip + ":"+ConvToStr(ls->bind_port) + " (" + type + ", " + hook + ")"); + stats.AddRow(249, ls->bind_sa.str() + " (" + type + ", " + hook + ")"); } } break; diff --git a/src/listensocket.cpp b/src/listensocket.cpp index b56e97025..4ec6c2b06 100644 --- a/src/listensocket.cpp +++ b/src/listensocket.cpp @@ -27,11 +27,8 @@ ListenSocket::ListenSocket(ConfigTag* tag, const irc::sockets::sockaddrs& bind_to) : bind_tag(tag) + , bind_sa(bind_to) { - bind_addr = bind_to.addr(); - bind_port = bind_to.port(); - bind_desc = bind_to.str(); - fd = socket(bind_to.sa.sa_family, SOCK_STREAM, 0); if (this->fd == -1) @@ -119,12 +116,12 @@ ListenSocket::~ListenSocket() void ListenSocket::OnEventHandlerRead() { irc::sockets::sockaddrs client; - irc::sockets::sockaddrs server; + irc::sockets::sockaddrs server(bind_sa); socklen_t length = sizeof(client); int incomingSockfd = SocketEngine::Accept(this, &client.sa, &length); - ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Accepting connection on socket %s fd %d", bind_desc.c_str(), incomingSockfd); + ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Accepting connection on socket %s fd %d", bind_sa.str().c_str(), incomingSockfd); if (incomingSockfd < 0) { ServerInstance->stats.Refused++; @@ -135,7 +132,6 @@ void ListenSocket::OnEventHandlerRead() if (getsockname(incomingSockfd, &server.sa, &sz)) { ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Can't get peername: %s", strerror(errno)); - irc::sockets::aptosa(bind_addr, bind_port, server); } if (client.sa.sa_family == AF_INET6) @@ -189,7 +185,7 @@ void ListenSocket::OnEventHandlerRead() { ServerInstance->stats.Refused++; ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Refusing connection on %s - %s", - bind_desc.c_str(), res == MOD_RES_DENY ? "Connection refused by module" : "Module for this port not found"); + bind_sa.str().c_str(), res == MOD_RES_DENY ? "Connection refused by module" : "Module for this port not found"); SocketEngine::Close(incomingSockfd); } } diff --git a/src/modules/m_flashpolicyd.cpp b/src/modules/m_flashpolicyd.cpp index b44b72dbf..4e7af4b83 100644 --- a/src/modules/m_flashpolicyd.cpp +++ b/src/modules/m_flashpolicyd.cpp @@ -126,7 +126,7 @@ class ModuleFlashPD : public Module if (ls->bind_tag->getString("type", "clients") != "clients" || ls->bind_tag->getString("ssl", "plaintext") != "plaintext") continue; - to_ports.append(ConvToStr(ls->bind_port)).push_back(','); + to_ports.append(ConvToStr(ls->bind_sa.port())).push_back(','); } if (to_ports.empty()) diff --git a/src/socket.cpp b/src/socket.cpp index 0ba57a810..a5c1c679a 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -45,12 +45,11 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports) irc::sockets::sockaddrs bindspec; if (!irc::sockets::aptosa(Addr, portno, bindspec)) continue; - std::string bind_readable = bindspec.str(); bool skip = false; for (std::vector<ListenSocket*>::iterator n = old_ports.begin(); n != old_ports.end(); ++n) { - if ((**n).bind_desc == bind_readable) + if ((**n).bind_sa == bindspec) { (*n)->bind_tag = tag; // Replace tag, we know addr and port match, but other info (type, ssl) may not (*n)->ResetIOHookProvider(); @@ -71,7 +70,7 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports) } else { - failed_ports.push_back(std::make_pair(bind_readable, strerror(errno))); + failed_ports.push_back(std::make_pair(bindspec.str(), strerror(errno))); delete ll; } } @@ -90,7 +89,7 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports) } this->Logs->Log("SOCKET", LOG_DEFAULT, "Port binding %s was removed from the config file, closing.", - (**n).bind_desc.c_str()); + (**n).bind_sa.str().c_str()); delete *n; // this keeps the iterator valid, pointing to the next element |