anchor.diff:  weight()                -> 95.
   targettime()            -> 50.
   
  +%% Used as a callback when qry results arrive:
   send_response(A, Qid, Ip, Port) -> 
       gen_server:cast(?MODULE, {send_response, A, Qid, Ip, Port}).
   
   %% gen_server callbacks
   init([]) ->
  -    LAddr = {192,168,1,67},
  +	{R1,R2,R3} = now(),
  +	random:seed(R1,R2,R3),
  +	SQ = ets:new(seenqids,[]),
  +	LAddr = {0,0,0,0},
       {ok, Sock} = gen_udp:open(60210, [binary, 
                                        {reuseaddr, true},{ip, ?BROADCAST}, 
                                        {add_membership, {?BROADCAST, LAddr}}]),
  -    {ok, #state{sock=Sock}}.
  +    {ok, #state{sock=Sock, seenqids=SQ}}.
   
   handle_call(_Request, _From, State) ->
       Reply = ok,
  
positive.code: -module(lan_resolver).
  
  -behaviour(gen_server).
  
negative.code:                     Url = io_lib:format("http://~w.~w.~w.~w:60210/sid/~s",
                                          [A,B,C,D,Sid]),
                      qry:add_result(Qpid, {struct, 
                                            [{<<"url">>, list_to_binary(Url)}|L2]}),
                      {noreply, State};
                  _ ->
                      {noreply, State}
              end;
          
          <<"rq">> ->
              Qid = proplists:get_value(<<"qid">>, L),
              % do nothing if we dispatched, or already received this qid
              case ets:lookup(State#state.seenqids, Qid) of
                  [{Qid, true}] -> {noreply, State};
                  _ ->           
                      ets:insert(State#state.seenqids, {Qid,true}),
                      Cbs = [ fun(Ans)-> ?MODULE:send_response(Ans, Qid, Ip, 60210) end ],
                      resolver:dispatch({struct,L}, Qid, Cbs),
                      {noreply, State}
              end;
              
          _ -> {noreply, State}
      end.
      
  terminate(_Reason, State) ->
      gen_udp:close(State#state.sock),
      ok.
  