From 60610e90b1258b37f6ae946cfc5b2737c192d2ae Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 1 Apr 2020 15:53:43 +0200 Subject: [PATCH] test/net/TestIPv[46]Address: fix Windows build errors --- test/net/TestIPv4Address.cxx | 13 +++++++++++-- test/net/TestIPv6Address.cxx | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/test/net/TestIPv4Address.cxx b/test/net/TestIPv4Address.cxx index aa7f727be..a6c05e681 100644 --- a/test/net/TestIPv4Address.cxx +++ b/test/net/TestIPv4Address.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 Max Kellermann + * Copyright 2012-2020 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,13 +34,22 @@ #include +#ifndef _WIN32 #include +#endif static std::string ToString(const struct in_addr &a) { +#ifdef _WIN32 + /* on mingw32, the parameter is non-const (PVOID) */ + const auto p = const_cast(&a); +#else + const auto p = &a; +#endif + char buffer[256]; - const char *result = inet_ntop(AF_INET, &a, buffer, sizeof(buffer)); + const char *result = inet_ntop(AF_INET, p, buffer, sizeof(buffer)); if (result == nullptr) throw std::runtime_error("inet_ntop() failed"); return result; diff --git a/test/net/TestIPv6Address.cxx b/test/net/TestIPv6Address.cxx index 325d25bbf..cdadf6a7f 100644 --- a/test/net/TestIPv6Address.cxx +++ b/test/net/TestIPv6Address.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 Max Kellermann + * Copyright 2012-2020 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,13 +34,22 @@ #include +#ifndef _WIN32 #include +#endif static std::string ToString(const struct in6_addr &a) { +#ifdef _WIN32 + /* on mingw32, the parameter is non-const (PVOID) */ + const auto p = const_cast(&a); +#else + const auto p = &a; +#endif + char buffer[256]; - const char *result = inet_ntop(AF_INET6, &a, buffer, sizeof(buffer)); + const char *result = inet_ntop(AF_INET6, p, buffer, sizeof(buffer)); if (result == nullptr) throw std::runtime_error("inet_ntop() failed"); return result;