1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
-module(fib_freebsd).
-behaviour(fib_behaviour).
-export([default_table/0, current_table/0, tables/0]).
-export([list/1]).
default_table() ->
1.
current_table() ->
case os:cmd("sysctl net.my_fibnum") of
[$n, $e, $t, $., $m, $y, $_, $f, $i, $n, $b, $u, $m, $:, $\s | Rest] ->
{ok, list_to_integer(string:trim(Rest))};
_ ->
error
end.
tables() ->
case os:cmd("sysctl net.fibs") of
[$n, $e, $t, $., $f, $i, $b, $s, $:, $\s | Rest] ->
Count = list_to_integer(string:trim(Rest)),
{ok, lists:seq(1, Count)};
_ ->
error
end.
list(Table) ->
case lists:member(fib:tables(), Table) of
true ->
do_list(Table);
_ ->
{error, {no_table, Table}}
end.
do_list(Table) ->
os:cmd(["setfib ", Table, " netstat -rn"]).
|