%%%------------------------------------------------------------------- %%% @author anlicheng %%% @copyright (C) 2025, %%% @doc %%% 内部地址协议注册表 %%% @end %%% Created : 13. 12月 2025 21:09 %%%------------------------------------------------------------------- -module(sdlan_hostname_regedit). -author("anlicheng"). %% API -export([init/0, lookup/1, insert/3]). -define(TABLE, sdlan_hostname_regedit). init() -> ets:new(?TABLE, [named_table, set, public, {read_concurrency, true}, {write_concurrency, true}]). -spec lookup(FullHostname :: binary()) -> error | {ok, Ip :: inet:ip4_address()}. lookup(FullHostname) when is_binary(FullHostname) -> LowerFullHostname = string:lowercase(FullHostname), case ets:lookup(?TABLE, LowerFullHostname) of [{_, Ip}] -> {ok, Ip}; [] -> error end. -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 = <>, LowerFullHostname = string:lowercase(FullHostname), <> = <>, true = ets:insert(?TABLE, {LowerFullHostname, {Ip0, Ip1, Ip2, Ip3}}); insert(_, _, _) -> ok.