Merge pull request #5743 from lafirest/fix/connector

fix(emqx_schema): support get ip address by host name
This commit is contained in:
lafirest 2021-09-15 15:21:54 +08:00 committed by GitHub
commit 75f528e08d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -1093,9 +1093,18 @@ to_bar_separated_list(Str) ->
to_ip_port(Str) ->
case string:tokens(Str, ":") of
[Ip, Port] ->
PortVal = list_to_integer(Port),
case inet:parse_address(Ip) of
{ok, R} -> {ok, {R, list_to_integer(Port)}};
_ -> {error, Str}
{ok, R} ->
{ok, {R, PortVal}};
_ ->
%% check is a rfc1035's hostname
case inet_parse:domain(Ip) of
true ->
{ok, {Ip, PortVal}};
_ ->
{error, Str}
end
end;
_ -> {error, Str}
end.