summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fib_macos.erl33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/fib_macos.erl b/src/fib_macos.erl
index 3df046d..a2dd6cd 100644
--- a/src/fib_macos.erl
+++ b/src/fib_macos.erl
@@ -76,25 +76,30 @@ parse_rt(Rt0, BinaryAddrs) ->
metrics_init = bitmask(?RTV, Rt0#macos_rt.metrics_init),
metrics_lock = bitmask(?RTV, Rt0#macos_rt.metrics_lock)},
logger:warning("fib_macos:monitor Rt = ~p~nBinary: ~p", [Rt1, BinaryAddrs]),
- Rt = get_addrs(Rt1#macos_rt.addrs, BinaryAddrs, Rt1),
+ Rt = get_addrs(BinaryAddrs, Rt1#macos_rt.addrs, Rt1),
logger:warning("fib_macos:monitor Rt = ~p", [Rt]),
Rt.
-get_addrs([_Type | Rest], <<0:32/little-unsigned-integer, Binary/binary>>, Rt) ->
- get_addrs(Rest, Binary, Rt);
-get_addrs([Type | Rest], <<Len:8/little-unsigned-integer, Family:8/little-unsigned-integer, Content/binary>>, Rt) ->
- logger:error("fib_macos:get_addrs() ~p len=~p family=~p ~nbinary ~p", [Type, Len, Family, Content]),
- ToRead = case Type of
- netmask -> Len - 1;
- _Other -> Len - 2
- end,
- <<BinaryAddr:ToRead/binary, Binary/binary>> = Content,
- Idx = string:str(record_info(fields, macos_rt), [Type]),
- logger:warning("fib_macos:get_addrs() - get_addr ~p = ~p~nRest ~p~nBinRest = ~p", [Type, BinaryAddr, Rest, Binary]),
- get_addrs(Rest, Binary, setelement(Idx+1, Rt, process_address(Family, BinaryAddr)));
-get_addrs([], _, Rt) ->
+get_addrs(<<0:32/little-unsigned-integer, Binary/binary>>, [netmask | Rest], Rt) ->
+ get_addrs(Binary, Rest, set_rt_addr(netmask, {0, 0, 0, 0}, Rt));
+get_addrs(<<Len:8/little-unsigned-integer, Family:8/little-unsigned-integer, Content/binary>>, [netmask | Rest], Rt) ->
+ <<BinaryAddr:(Len - 1)/binary, Binary/binary>> = Content,
+ get_addrs(Binary, Rest, set_rt_addr(netmask, process_address(Family, BinaryAddr), Rt));
+get_addrs(<<Len:8/little-unsigned-integer, Family:8/little-unsigned-integer, Content/binary>>, [Type | Rest], Rt) ->
+ <<BinaryAddr:(Len - 2)/binary, Binary/binary>> = Content,
+ get_addrs(Binary, Rest, set_rt_addr(Type, process_address(Family, BinaryAddr), Rt));
+get_addrs(_, [], Rt) ->
Rt.
+set_rt_addr(destination, Value, Rt) -> Rt#macos_rt{destination = Value};
+set_rt_addr(gateway, Value, Rt) -> Rt#macos_rt{gateway = Value};
+set_rt_addr(netmask, Value, Rt) -> Rt#macos_rt{netmask = Value};
+set_rt_addr(clonemask, Value, Rt) -> Rt#macos_rt{clonemask = Value};
+set_rt_addr(ifp, Value, Rt) -> Rt#macos_rt{ifp = Value};
+set_rt_addr(ifa, Value, Rt) -> Rt#macos_rt{ifa = Value};
+set_rt_addr(author, Value, Rt) -> Rt#macos_rt{author = Value};
+set_rt_addr(brd, Value, Rt) -> Rt#macos_rt{brd = Value}.
+
%% sockaddr_in, without the zeros (? only in netmasks)
process_address(?AF_INET, <<_Port:16/little-unsigned-integer, A, B, C, D>>) ->
{A, B, C, D};