anchor.diff:  
   %% get_avp/3
   %%
  -%% Find an AVP in a message of one of three forms:
  -%%
  -%% - a message record (as generated from a .dia spec) or
  -%% - a list of an atom message name followed by 2-tuple, avp name/value pairs.
  -%% - a list of a #diameter_header{} followed by #diameter_avp{} records,
  -%%
  -%% In the first two forms a dictionary module is used at encode to
  -%% identify the type of the AVP and its arity in the message in
  -%% question. The third form allows messages to be sent as is, without
  -%% a dictionary, which is needed in the case of relay agents, for one.
  +%% Find an AVP in a message in one of the decoded formats, or as a
  +%% header/avps list. There are only four AVPs that are extracted here:
  +%% Result-Code and Experimental-Result in order when constructing
  +%% counter keys, and Destination-Host/Realm when selecting a next-hop
  +%% peer. Experimental-Result is the only of type Grouped, and is given
  +%% special treatment in order to return the value as a record.
   
   %% Messages will be header/avps list as a relay and the only AVP's we
   %% look for are in the common dictionary. This is required since the
  
positive.code: get_avp(_, Name, [_MsgName | Avps]) ->
      case find(Name, Avps) of
          {_, V} ->
              #diameter_avp{name = Name, value = V};
          _ ->
              undefined
      end;
  
  %% ... or record (but not necessarily).
  get_avp(Dict, Name, Rec) ->
      try
          #diameter_avp{name = Name, value = Dict:'#get-'(Name, Rec)}
      catch
          error:_ ->
              undefined
      end.
  
  %% find/2
  
  
negative.code: get_avp(?RELAY, Name, Msg) ->
      get_avp(?BASE, Name, Msg);
  
  %% Message as header/avps list.
  get_avp(Dict, Name, [#diameter_header{} | Avps]) ->
      try
          {Code, _, Vid} = Dict:avp_header(Name),
          A = find_avp(Code, Vid, Avps),
          avp_decode(Dict, Name, ungroup(A))
      catch
          error: _ ->
              undefined
  