anchor.diff:  %%
   res_gethostbyaddr(IP, Rec) ->
       {ok, {IP1, HType, HLen}} = dnt(IP),
  -    RRs = lists:map(fun lower_rr/1, Rec#dns_rec.anlist),
  -    res_cache_answer(Rec#dns_rec{anlist = RRs}),
  -    ent_gethostbyaddr(Rec#dns_rec.anlist, IP1, HType, HLen).
  -
  -ent_gethostbyaddr(RRs, IP, AddrType, Length) ->
  -    case RRs of
  -	[] -> {error, nxdomain};
  -	[RR|TR] ->
  -	    %% debug
  -	    if TR =/= [] ->
  -		    ?dbg("gethostbyaddr found extra=~p~n", [TR]);
  -	       true -> ok
  -	    end,
  -            Type = RR#dns_rr.type,
  -	    Domain = RR#dns_rr.data,
  -	    H = #hostent { h_name = Domain,
  -			   h_aliases = lookup_cname(Domain, Type),
  -			   h_addr_list = [IP],
  -			   h_addrtype = AddrType,
  -			   h_length = Length },
  -	    {ok, H}
  -    end.
  +    RRs =
  +        [RR#dns_rr{domain = tolower(N)} ||
  +            #dns_rr{
  +               domain = N,
  +               class = in,
  +               type = T} = RR <- Rec#dns_rec.anlist,
  +            T =:= ?S_PTR orelse T =:= ?S_CNAME],
  +    res_cache_answer(RRs),
  +    case [RR || #dns_rr{type = ?S_PTR} = RR <- RRs] of
  +        [] ->
  +            {error, nxdomain};
  +        PtrRRs ->
  +            ent_gethostbyaddr(PtrRRs, IP1, HType, HLen)
  +    end.
  +
  +ent_gethostbyaddr([RR|RRs], IP, AddrType, Length) ->
  +    %% debug
  +    if RRs =/= [] ->
  +            ?dbg("gethostbyaddr found extra=~p~n", [RRs]);
  +       true -> ok
  +    end,
  +    Domain = RR#dns_rr.data,
  +    H =
  +        #hostent{
  +           h_name = Domain,
  +           %% Since a PTR record should point to
  +           %% the canonical name, this Domain should
  +           %% have no canonical name, so it this really reasonable?
  +           h_aliases = lookup_cname(Domain),
  +           h_addr_list = [IP],
  +           h_addrtype = AddrType,
  +           h_length = Length },
  +    {ok, H}.
  +
   
   dnip(IP) ->
       case dnt(IP) of
  
positive.code: %% match data field directly and cache RRs.
  %%
  res_hostent_by_domain(Domain, Type, Rec) ->
      RRs = lists:map(fun lower_rr/1, Rec#dns_rec.anlist),
      res_cache_answer(Rec#dns_rec{anlist = RRs}),
      ?dbg("res_hostent_by_domain: ~p - ~p~n", [Domain, RRs]),
      res_hostent_by_domain(stripdot(Domain), [], [], Type, RRs).
  
  res_hostent_by_domain(Domain, Aliases, LAliases, Type, RRs) ->
      LDomain = tolower(Domain),
      case res_lookup_type(LDomain, Type, RRs) of
  	[] ->
  	    case res_lookup_type(LDomain, ?S_CNAME, RRs) of
  		[] ->  
  		    {error, nxdomain};
  		[CName | _] ->
  		    case lists:member(tolower(CName), [LDomain | LAliases]) of
  			true -> 
  			    {error, nxdomain};
  			false ->
  			    res_hostent_by_domain(CName, [Domain | Aliases],
  						  [LDomain | LAliases], Type,
  						  RRs)
  		    end
  	    end;
  	Addrs ->
  
negative.code:     {Domain, Class, Type, Data}.
  
  
  %%
  %% Case fold upper-case to lower-case according to RFC 4343
  %% "Domain Name System (DNS) Case Insensitivity Clarification".
  