anchor.diff:  new_id(Int)
     when is_integer(Int) andalso Int >= 10 andalso Int =< 31 -> Int + 87.
   
  -active_rr_fun() -> Now = dns:unix_time(), active_rr_fun(Now).
  -
  -active_rr_fun(Now) when is_integer(Now) ->
  -    fun(RR) -> ?MODULE:active_rr(Now, RR) end.
  -
  -active_rr(Now, RRs) when is_list(RRs) ->
  -    [ RR || RR <- RRs, active_rr(Now, RR) ];
  -active_rr(Now, #dnsxd_rr{incept = Incept})
  -  when is_integer(Incept) andalso Incept > Now -> false; %% not yet active
  -active_rr(Now, #dnsxd_rr{expire = Expire})
  -  when is_integer(Expire) andalso Expire =< Now -> false; %% expired
  -active_rr(_Now, #dnsxd_rr{}) -> true.
  -
  -to_dns_rr(RRs) when is_list(RRs) -> [ to_dns_rr(RR) || RR <- RRs ];
  -to_dns_rr(#dnsxd_rr{name = Name, class = Class, type = Type, ttl = TTL,
  -		    data = Data}) ->
  -    #dns_rr{name = Name, class = Class, type = Type, ttl = TTL, data = Data}.
  -
  -to_dns_rr(Now, RRs) when is_integer(Now) andalso is_list(RRs) ->
  -    {DnsRR, TTLs} = lists:mapfoldl(fun(RR, Acc) -> to_dns_rr(Now, RR, Acc) end,
  -				   gb_trees:empty(), RRs),
  -    GetTTL = fun(#dns_rr{} = RR) ->
  -		     Hash = hash(RR),
  -		     gb_trees:get(Hash, TTLs)
  -	     end,
  -    [ RR#dns_rr{ttl = GetTTL(RR)} || RR <- DnsRR ].
  -
  -to_dns_rr(Now, #dnsxd_rr{name = Name, class = Class, type = Type,
  -			 ttl = TTL, data = Data, expire = Expire} = RR, TTLs)
  -  when is_integer(Now) ->
  -    DynTTL = case is_integer(Expire) of
  -		 true ->
  -		     TTE = Expire - Now,
  -		     if TTE =< 0 -> 0;
  -			TTE < TTL -> TTE;
  -			true -> TTL end;
  -		 false -> TTL
  -	     end,
  -    Hash = hash(RR),
  -    NewTTLs = case gb_trees:lookup(Hash, TTLs) of
  -		  {value, Value} when Value < DynTTL -> TTLs;
  -		  {value, _} -> gb_trees:update(Hash, DynTTL, TTLs);
  -		  none -> gb_trees:insert(Hash, DynTTL, TTLs)
  -	      end,
  -    NewRR = #dns_rr{name = Name, class = Class, type = Type, data = Data},
  -    {NewRR, NewTTLs}.
  -
   is_dnssd_rr(ZoneName, #dns_rr{name = Name, type = Type}) ->
       is_dnssd_rr(ZoneName, Name, Type);
   is_dnssd_rr(ZoneName, #dnsxd_rr{name = Name, type = Type}) ->
       is_dnssd_rr(ZoneName, Name, Type).
   
  -is_dnssd_rr(ZoneName, Name, Type) when is_atom(Type) ->
  -    NewType = dns:type_to_int(Type),
  -    is_dnssd_rr(ZoneName, Name, NewType);
   is_dnssd_rr(ZoneName, Name, Type) when is_binary(ZoneName) ->
       ZoneNameLabels = dns:dname_to_labels(ZoneName),
       is_dnssd_rr(ZoneNameLabels, Name, Type);
  
positive.code: -include("dnsxd_internal.hrl").
  
  %% API
  -export([ensure_apps_started/1, new_id/0,
  	 active_rr_fun/0, active_rr_fun/1, active_rr/2,
  	 to_dns_rr/1, to_dns_rr/2, is_dnssd_rr/2,
  	 use_procket/0, procket_open/4, cancel_timer/1,
  	 ip_to_txt/1]).
  
  %%%===================================================================
  %%% API
  
negative.code: 	<<"::FFFF:", Bin/binary>> -> Bin;
  	Bin -> Bin
      end.
  