inet_dns module

Magnus Fröberg <>
Thu Dec 2 08:19:32 CET 1999


Emmanuelle BERNARD wrote:
> 
> Hi,
> 
> I would like to use the functions encode and decode of the inet_dns
> module
> How to use them?
> 
> The little program :
> """"""""""""""""""""""""""""""""""""""""""""""""""""
> -module(i).
> -export([test/0]).
> 
>   test()->
> 
> Var={dns_rec,{dns_header,10,0,0,0,0,1,0,0,0},[{dns_query,"ada.eu.org",a,in}],[],[],[]},
> 
>       io:format("~p~n", [Var]),
>       Packet=inet_dns:encode(Var),
>       io:format("~p~n", [Packet]),
>       Result=inet_dns:decode(Packet),
>       io:format("~p~n", [Result]).
>   """""""""""""""""""""""""""""""""""""""""""""""
> 
> 
> Why is there a format error?

inet_dns:encode returns {ok, P}, i.e. you should match that tuple.
As you supplies {ok, P} to inet_dns:decode/1 you got the {error, fmt}.

	...
	{ok, Pkt} = inet_dns:encode(Var),
	Result = inet_dns:decode(Pkt),
	...

Instead of creating the dns_rec tuple you should include inet_dns.hrl
and use the record definitions. You have to include it as:
-include("$ERL/lib/kernel-$KERNEL_VSN/src/inet_dns.hrl") as the inet_dns
module was not intended for use outside the kernel application (e.g. you
cant find a man-page for it). (Note: $ERL above is your erlang install
directory and $KERNEL_VSN is the version of the kernel application in
your installation)

/Magnus

-- 
Magnus Fröberg                          Tel: +46 (0)8 692 22 06
Bluetail AB                             Email: 
Hantverkargatan 78                      WWW: http://www.bluetail.com
SE-112 38 Stockholm, SWEDEN



More information about the erlang-questions mailing list