diff --git a/apps/kolab_guam/src/kolab_guam_listener.erl b/apps/kolab_guam/src/kolab_guam_listener.erl --- a/apps/kolab_guam/src/kolab_guam_listener.erl +++ b/apps/kolab_guam/src/kolab_guam_listener.erl @@ -75,7 +75,23 @@ listen_options(none, Addr) end. -default_listen_options() -> [ { reuseaddr, true }, {active, false}, inet6 ]. +default_listen_options() -> [ { reuseaddr, true }, {active, false} | ipv6_opts() ]. + +ipv6_opts() -> + case check_for_ipv6(inet:getifaddrs()) of + true -> [inet6]; + _ -> [] + end. + +check_for_ipv6({ok, Ifaddrs}) -> check_for_ipv6(Ifaddrs); +check_for_ipv6([]) -> false; +check_for_ipv6([{_iface, Attrs}|Ifaddrs]) -> + Addrs = proplists:get_all_values(addr, Attrs), + case lists:any(fun(Addr) -> size(Addr) == 8 end, Addrs) of + true -> true; + _ -> check_for_ipv6(Ifaddrs) + end; +check_for_ipv6(_) -> false. create_initial_listeners(ListenerPoolSize, PID) when is_pid(PID) -> lager:debug("Creating session pool of size ~p for listener ~p", [ListenerPoolSize, PID]),