Permalink
Browse files

Fix switching

Since the MAC address is identical, the key was overwritten. Switch to
an ordered set, since duplicates should not exist.
  • Loading branch information...
1 parent 6d1edbe commit 886fe380c6672030f420efe5ad14308969e3c7c7 @msantos committed Dec 29, 2010
Showing with 6 additions and 6 deletions.
  1. +6 −6 src/evum_data.erl
View
@@ -104,7 +104,7 @@ init([Pid]) ->
Ifindex = packet:ifindex(IP, If),
State = #state{
- mac = dict:new(),
+ mac = ordsets:new(),
ip = IP,
arp = ARP,
ifindex = Ifindex,
@@ -141,20 +141,20 @@ handle_call(name, _From, #state{sun = Sun} = State) ->
%% VM's. If the VM is not responding, remove it from the list of VM
%% addresses.
handle_call({net, Data}, _From, #state{s = Socket, mac = MAC} = State) ->
- Alive = dict:filter(
- fun(_Ether,Sun) -> ok == procket:sendto(Socket, Data, 0, Sun) end,
+ MAC1 = ordsets:filter(
+ fun(Sun) -> ok == procket:sendto(Socket, Data, 0, Sun) end,
MAC
),
- {reply, ok, State#state{mac = Alive}};
+ {reply, ok, State#state{mac = MAC1}};
handle_call({unix, Sun, Data}, _From, #state{ip = IP, arp = ARP, ifindex = Ifindex, mac = MAC} = State) ->
- {#ether{shost = Ether, type = Type}, _Packet} = pkt:ether(Data),
+ {#ether{type = Type}, _Packet} = pkt:ether(Data),
Socket = case Type of
?ETH_P_ARP -> ARP;
?ETH_P_IP -> IP
end,
ok = packet:send(Socket, Ifindex, Data),
- {reply, ok, State#state{mac = dict:store(Ether, Sun, MAC)}};
+ {reply, ok, State#state{mac = ordsets:add_element(Sun, MAC)}};
handle_call(stop, {Pid,_}, #state{pid = Pid} = State) ->
{stop, shutdown, ok, State}.

0 comments on commit 886fe38

Please sign in to comment.