This commit is contained in:
anlicheng 2026-04-13 14:51:17 +08:00
parent d009bba5b6
commit 2ec2380a54
2 changed files with 5 additions and 3 deletions

View File

@ -33,7 +33,7 @@ init([]) ->
Name = dns_server:get_name(Id),
#{
id => Name,
start => {sdlan_stun, start_link, [Name, Port]},
start => {dns_server, start_link, [Name, Port]},
restart => permanent,
shutdown => 2000,
type => worker,

View File

@ -19,7 +19,8 @@ init() ->
-spec lookup(FullHostname :: binary()) -> error | {ok, Ip :: inet:ip4_address()}.
lookup(FullHostname) when is_binary(FullHostname) ->
case ets:lookup(?TABLE, FullHostname) of
LowerFullHostname = string:lowercase(FullHostname),
case ets:lookup(?TABLE, LowerFullHostname) of
[{_, Ip}] ->
{ok, Ip};
[] ->
@ -29,7 +30,8 @@ lookup(FullHostname) when is_binary(FullHostname) ->
-spec insert(any(), Domain :: binary(), Ip :: integer()) -> no_return().
insert(HostName, Domain, Ip) when is_binary(HostName), is_binary(Domain), is_integer(Ip), HostName /= <<>> ->
FullHostname = <<HostName/binary, ".", Domain/binary>>,
LowerFullHostname = string:lowercase(FullHostname),
<<Ip0, Ip1, Ip2, Ip3>> = <<Ip:32>>,
true = ets:insert(?TABLE, {FullHostname, {Ip0, Ip1, Ip2, Ip3}});
true = ets:insert(?TABLE, {LowerFullHostname, {Ip0, Ip1, Ip2, Ip3}});
insert(_, _, _) ->
ok.