changeset 492:b5b2bb02412a

Socket: add mutable because inet_ntop on Windows is not const
author David Demelier <markand@malikania.fr>
date Thu, 19 Nov 2015 16:41:02 +0100
parents c03f84bdabe9
children 59e2c93af9ed
files modules/sockets/sockets.h
diffstat 1 files changed, 7 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/modules/sockets/sockets.h	Wed Nov 18 14:31:22 2015 +0100
+++ b/modules/sockets/sockets.h	Thu Nov 19 16:41:02 2015 +0100
@@ -1730,8 +1730,8 @@
 	static int m_default;
 
 	union {
-		sockaddr_in m_sin;
-		sockaddr_in6 m_sin6;
+		mutable sockaddr_in m_sin;
+		mutable sockaddr_in6 m_sin6;
 	};
 
 	socklen_t m_length{0};
@@ -1842,18 +1842,16 @@
 	 */
 	std::string ip() const
 	{
-		std::string result;
+		char result[128];
+
+		std::memset(result, 0, sizeof (result));
 
 		if (m_domain == AF_INET6) {
-			result.resize(INET_ADDRSTRLEN);
-
-			if (!inet_ntop(AF_INET6, &m_sin6.sin6_addr, &result[0], INET_ADDRSTRLEN)) {
+			if (!inet_ntop(AF_INET6, &m_sin6.sin6_addr, result, sizeof (result))) {
 				throw Error{Error::System, "inet_ntop"};
 			}
 		} else {
-			result.resize(INET6_ADDRSTRLEN);
-
-			if (!inet_ntop(AF_INET, &m_sin.sin_addr, &result[0], INET6_ADDRSTRLEN)) {
+			if (!inet_ntop(AF_INET, &m_sin.sin_addr, result, sizeof (result))) {
 				throw Error{Error::System, "inet_ntop"};
 			}
 		}