anchor.diff:  		true ->
   		    %% probably a ipv4 address
   		    case catch parse_ipv4hostport(HostPort) of
  -			{error,_} ->
  -			    parse_domain_hostport(HostPort);
  -			R ->
  -			    R
  +			{ok, Host, Port} when is_list(Host), is_list(Port); Port == none ->
  +			    {Host, Port};
  +			_ ->
  +			    %% was not IPv4 address, try to parse as IPv6 address without
  +			    %% brackets, and then as hostname
  +			    {ok, Host, Port} = parse_hostport_v6_or_hostname(HostPort),
  +			    {Host, Port}
   		    end;
   		false ->
  -		    %% must be a domain name
  -		    parse_domain_hostport(HostPort)
  +		    %% must be a hostname, or an IPv6 address without brackets
  +		    {ok, Host, Port} = parse_hostport_v6_or_hostname(HostPort),
  +		    {Host, Port}
   	    end
       end.
   
  -parse_ipv6hostport([$[ | IPv6Hostport]) ->
  +parse_hostport_v6_or_hostname(In) ->
  +    case catch parse_ipv6hostport(In) of
  +	{ok, Host, Port} ->
  +	    {ok, Host, Port};
  +	_ ->
  +	    parse_domain_hostport(In)
  +    end.
  +
  +parse_ipv6hostport([91 | IPv6Hostport]) ->	%% 91 is $[
       {IPv6Ref, Port} = get_ipv6ref_and_port(IPv6Hostport),
       case Port of
   	none -> ok;
  
positive.code: 	    list_to_integer(Port),
  	    %% throw if not a hostname
  	    is_hostname(Host),
  	    {rm_trailing_dot_from_hostname(Host), Port};
  	{Host} ->
  	    %% throw if not a hostname
  	    is_hostname(Host),
  	    {rm_trailing_dot_from_hostname(Host), none}
      end.
  
  rm_trailing_dot_from_hostname(H) ->
  
negative.code: 	    %% throw if not a numeric string
  	    list_to_integer(Port),
  	    %% throw if not a IPv4 address string
  	    {ok, is_IPv4address(Host), Port};
  	{Host} ->
  	    %% throw if not a IPv4 address string
  	    {ok, is_IPv4address(Host), none}
      end.
  
  
  