File 0167-snmp-test-The-new-IPv6-support-check-do-not-work-for.patch of Package erlang
From 9353409986f03030da8a6033336255c91a597a97 Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Thu, 19 Dec 2019 11:16:51 +0100
Subject: [PATCH 07/10] [snmp|test] The new IPv6 support check do not work for
windows
Forgot that 'socket' does not yet support windows.
So the windows platform we need to check this the old
way (using the inet driver and ct).
---
lib/snmp/test/snmp_test_lib.erl | 39 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/lib/snmp/test/snmp_test_lib.erl b/lib/snmp/test/snmp_test_lib.erl
index d193931bfa..e9216a4f55 100644
--- a/lib/snmp/test/snmp_test_lib.erl
+++ b/lib/snmp/test/snmp_test_lib.erl
@@ -413,7 +413,14 @@ os_based_skip_check(OsName, OsNames) ->
%% A modern take on the "Check if our host handle IPv6" question.
%%
has_support_ipv6() ->
- socket:supports(ipv6) andalso has_valid_ipv6_address().
+ case os:type() of
+ {win32, _} ->
+ %% We do not yet have support for windows in the socket nif,
+ %% so for windows we need to use the old style...
+ old_has_support_ipv6();
+ _ ->
+ socket:supports(ipv6) andalso has_valid_ipv6_address()
+ end.
has_valid_ipv6_address() ->
case net:getifaddrs(fun(#{addr := #{family := inet6},
@@ -489,6 +496,36 @@ validate_ipv6_address(LocalAddr) ->
end.
+
+
+old_has_support_ipv6() ->
+ case inet:gethostname() of
+ {ok, Hostname} ->
+ old_has_support_ipv6(Hostname) andalso old_is_ipv6_host(Hostname);
+ _ ->
+ false
+ end.
+
+old_has_support_ipv6(Hostname) ->
+ case inet:getaddr(Hostname, inet6) of
+ {ok, Addr} when (size(Addr) =:= 8) andalso
+ (element(1, Addr) =/= 0) andalso
+ (element(1, Addr) =/= 16#fe80) ->
+ true;
+ _ ->
+ false
+ end.
+
+old_is_ipv6_host(Hostname) ->
+ case ct:require(ipv6_hosts) of
+ ok ->
+ lists:member(list_to_atom(Hostname), ct:get_config(ipv6_hosts));
+ _ ->
+ false
+ end.
+
+
+
%% ----------------------------------------------------------------
%% Test suite utility functions
%%
--
2.16.4