summaryrefslogtreecommitdiff
path: root/src/socket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/socket.cpp')
-rw-r--r--src/socket.cpp51
1 files changed, 18 insertions, 33 deletions
diff --git a/src/socket.cpp b/src/socket.cpp
index 63b373cce..3ee996193 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -145,13 +145,16 @@ bool irc::sockets::aptosa(const std::string& addr, int port, irc::sockets::socka
memset(&sa, 0, sizeof(sa));
if (addr.empty() || addr.c_str()[0] == '*')
{
-#ifdef IPV6
- sa.in6.sin6_family = AF_INET6;
- sa.in6.sin6_port = htons(port);
-#else
- sa.in4.sin_family = AF_INET;
- sa.in4.sin_port = htons(port);
-#endif
+ if (ServerInstance->Config->WildcardIPv6)
+ {
+ sa.in6.sin6_family = AF_INET6;
+ sa.in6.sin6_port = htons(port);
+ }
+ else
+ {
+ sa.in4.sin_family = AF_INET;
+ sa.in4.sin_port = htons(port);
+ }
return true;
}
else if (inet_pton(AF_INET, addr.c_str(), &sa.in4.sin_addr) > 0)
@@ -210,35 +213,17 @@ std::string irc::sockets::sockaddrs::str() const
char buffer[MAXBUF];
if (sa.sa_family == AF_INET)
{
-#ifndef IPV6
- if (in4.sin_addr.s_addr == 0)
- {
- sprintf(buffer, "*:%u", ntohs(in4.sin_port));
- }
- else
-#endif
- {
- const uint8_t* bits = reinterpret_cast<const uint8_t*>(&in4.sin_addr);
- sprintf(buffer, "%d.%d.%d.%d:%u", bits[0], bits[1], bits[2], bits[3], ntohs(in4.sin_port));
- }
+ const uint8_t* bits = reinterpret_cast<const uint8_t*>(&in4.sin_addr);
+ sprintf(buffer, "%d.%d.%d.%d:%u", bits[0], bits[1], bits[2], bits[3], ntohs(in4.sin_port));
}
else if (sa.sa_family == AF_INET6)
{
-#ifdef IPV6
- if (!memcmp(all_zero, &in6.sin6_addr, 16))
- {
- sprintf(buffer, "*:%u", ntohs(in6.sin6_port));
- }
- else
-#endif
- {
- buffer[0] = '[';
- if (!inet_ntop(AF_INET6, &in6.sin6_addr, buffer+1, MAXBUF - 10))
- return "<unknown>"; // should never happen, buffer is large enough
- int len = strlen(buffer);
- // no need for snprintf, buffer has at least 9 chars left, max short len = 5
- sprintf(buffer + len, "]:%u", ntohs(in6.sin6_port));
- }
+ buffer[0] = '[';
+ if (!inet_ntop(AF_INET6, &in6.sin6_addr, buffer+1, MAXBUF - 10))
+ return "<unknown>"; // should never happen, buffer is large enough
+ int len = strlen(buffer);
+ // no need for snprintf, buffer has at least 9 chars left, max short len = 5
+ sprintf(buffer + len, "]:%u", ntohs(in6.sin6_port));
}
else
return "<unknown>";