fix udp server

This commit is contained in:
anlicheng 2025-12-03 17:50:07 +08:00
parent 1e2aa32bde
commit 0c370d5eda
2 changed files with 15 additions and 8 deletions

View File

@ -35,6 +35,14 @@ init([]) ->
shutdown => 2000,
type => supervisor,
modules => ['dns_handler_sup']
},
#{
id => dns_server,
start => {dns_server, start_link, []},
restart => permanent,
shutdown => 2000,
type => worker,
modules => ['dns_server']
}
],
{ok, {SupFlags, ChildSpecs}}.

View File

@ -1,11 +1,14 @@
-module(dns_server).
-export([start/0, stop/0]).
-export([start_link/0, init/0]).
-define(LISTEN_PORT, 53).
-define(LISTEN_PORT, 15353).
start() ->
start_link() ->
{ok, spawn_link(?MODULE, init, [])}.
init() ->
dns_cache:init(),
dns_zone_loader:load("priv/local.zone"),
%dns_zone_loader:load("priv/local.zone"),
%% DNS
Upstreams = [
@ -18,10 +21,6 @@ start() ->
io:format("DNS Forwarder started on UDP port ~p~n", [?LISTEN_PORT]),
loop(Sock).
stop() ->
gen_udp:close(?LISTEN_PORT),
ok.
loop(Sock) ->
receive
{udp, Sock, Ip, Port, Packet} ->