erlang - 如何在 Erlang 中构建 DNS 查询记录?

标签 erlang dns bonjour zeroconf

我正在构建一个本地 Bonjour/Zeroconf 库,需要构建 DNS 查询记录以广播到其他机器。我试过查看 Erlang 源代码,但由于我对 Erlang 比较陌生,所以它在所有 inet_XXX.erl 和 .hrl 文件的内部都变得有点密集。我有一个用于接收和解析 DNS 记录有效负载的监听器,但我不知道如何创建查询记录。我真正需要知道的是我需要传递给 inet_dns:encode() 以获得我可以发送的二进制文件。这就是我想要做的。

{ok,P} = inet_dns:encode(#dns_query{domain="_daap._tcp.local",type=ptr,class=in})

这是我得到的错误
10> test:send().
** exception error: {badrecord,dns_rec}
     in function  inet_dns:encode/1
     in call from test:send/0
11> 

最佳答案

我终于弄明白了。

send(Domain) ->
    {ok,S} = gen_udp:open(5555,[{reuseaddr,true}, {ip,{224,0,0,251}}, {multicast_ttl,4}, {multicast_loop,false}, {broadcast,true}, binary]),
    P = #dns_rec{header=#dns_header{},qdlist=[#dns_query{domain=Domain,type=ptr,class=in}]},
    gen_udp:send(S,{224,0,0,251},5353,inet_dns:encode(P)),
    gen_udp:close(S).

关于erlang - 如何在 Erlang 中构建 DNS 查询记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1740297/

相关文章:

security - 如何让其他用户在 Google Cloud Storage 中创建域名存储桶?

linux - NSLOOKUP 困惑 : Where is it getting its information locally?

c - 错误 C2016 : C requires that a struct or union has at least one member (while compiling Bonjour)

ios - 如何在 iOS 中发送和接收网络 MIDI 数据?

erlang - centos无法安装erlang

erlang - gen_server 中的数据被其主管重新启动后会保留吗?

linux - echo ${1 +"$@"} 是什么意思

ide - Erlang 开发的首选 IDE 是什么?

用于 http 重定向到 .azurewebsites.net 的 Azure CDN 自定义域

objective-c - NSNetService 委托(delegate)未被调用