[erlang-questions] Encoding a DNS Query correctly

Andrew Thompson andrew@REDACTED
Mon Nov 16 22:15:04 CET 2009


On Mon, Nov 16, 2009 at 02:56:11PM -0500, Jarrod Roberson wrote:
> I am writing a Bonjour/Zeroconf implemenation in native Erlang. This is
> basically multicast DNS.
> I have the listener and parser for the resulting DNS records working.
> What I can't get right is the encoding for sending.
> 
> Here is what I am trying:
> 
> send() ->
>     {ok,S} = gen_udp:open(5353,[{reuseaddr,true}, {ip,{224,0,0,251}},
> {multicast_ttl,4}, {multicast_loop,false}, {broadcast,true}, binary]),
>     {ok,P} =
> inet_dns:encode(#dns_query{domain="_daap._tcp.local",type=ptr,class=in}),
>     gen_udp:send(S,{224,0,0,251},5353,P),
>     gen_udp:close(S).
> 
> Here is what I am getting in the console when I call :send()
> 
> 24> test:send().
> ** exception error: {badrecord,dns_rec}
>      in function  inet_dns:encode/1
>      in call from test:send/0
> 25>
> 
> If I can get over this hump I will have a basic implementation done.
> Anyone have any ideas?

Maybe try adding

-include_lib("kernel/src/inet_dns.hrl").

or something? It looks like you're missing the definition of the dns_rec
record.

Andrew


More information about the erlang-questions mailing list