diff options
author | Attila Molnar <attilamolnar@hush.com> | 2013-06-05 17:52:39 -0700 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2013-06-05 17:52:39 -0700 |
commit | f00ac52c5d593fcb761fc316b2582bb06158035c (patch) | |
tree | bec88a8a69c4a912606636c9df6283c154962fef /src/socket.cpp | |
parent | d9d99cd02dadf34bfcc220734ba0c422f0acb3e6 (diff) | |
parent | 5d0b2b7cfccf057e7abab94c41065f94420899cd (diff) |
Merge pull request #544 from SaberUK/master+kill-maxbuf
Purge MAXBUF in favour of a configuration option.
Diffstat (limited to 'src/socket.cpp')
-rw-r--r-- | src/socket.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/socket.cpp b/src/socket.cpp index 12fb632a7..9ec7544f2 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -221,24 +221,22 @@ static const char all_zero[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 }; std::string irc::sockets::sockaddrs::str() const { - char buffer[MAXBUF]; if (sa.sa_family == AF_INET) { - 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)); + char ipaddr[INET_ADDRSTRLEN]; + inet_ntop(AF_INET, &in4.sin_addr, ipaddr, sizeof(ipaddr)); + return InspIRCd::Format("%s:%u", ipaddr, ntohs(in4.sin_port)); } - else if (sa.sa_family == AF_INET6) + + if (sa.sa_family == AF_INET6) { - 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)); + char ipaddr[INET6_ADDRSTRLEN]; + inet_ntop(AF_INET6, &in6.sin6_addr, ipaddr, sizeof(ipaddr)); + return InspIRCd::Format("[%s]:%u", ipaddr, ntohs(in6.sin6_port)); } - else - return "<unknown>"; - return std::string(buffer); + + // This should never happen. + return "<unknown>"; } int irc::sockets::sockaddrs::sa_size() const |