Encoding a DNS Query correctly

Jarrod Roberson <>
Mon Nov 16 20:56:11 CET 2009


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?


More information about the erlang-questions mailing list