(SIGAR-199) add arp_list Erlang binding

This commit is contained in:
Doug MacEachern 2010-02-01 20:45:49 -08:00
parent 8eb87135e4
commit 5e6ec3987e
3 changed files with 48 additions and 0 deletions

View File

@ -305,6 +305,31 @@ static void esigar_cpu_info_list_get(ErlDrvPort port, sigar_t *sigar)
ESIGAR_SEND(port, &x); ESIGAR_SEND(port, &x);
} }
static void esigar_arp_list_get(ErlDrvPort port, sigar_t *sigar)
{
int status;
ei_x_buff x;
sigar_arp_list_t list;
ei_x_new_with_version(&x);
if ((status = sigar_arp_list_get(sigar, &list) == SIGAR_OK)) {
ESIGAR_OK(&x);
esigar_to_list(&x,
(char *)&list.data[0], list.number,
sizeof(*list.data),
(esigar_encoder_func_t)esigar_encode_arp);
sigar_arp_list_destroy(sigar, &list);
}
else {
ESIGAR_ERROR(&x, sigar, status);
}
ESIGAR_SEND(port, &x);
}
static void esigar_who_list_get(ErlDrvPort port, sigar_t *sigar) static void esigar_who_list_get(ErlDrvPort port, sigar_t *sigar)
{ {
int status; int status;
@ -354,6 +379,9 @@ static void outputv(ErlDrvData handle, ErlIOVec *ev) {
case ESIGAR_CPU_INFO_LIST: case ESIGAR_CPU_INFO_LIST:
esigar_cpu_info_list_get(port, sigar); esigar_cpu_info_list_get(port, sigar);
break; break;
case ESIGAR_ARP_LIST:
esigar_arp_list_get(port, sigar);
break;
case ESIGAR_WHO_LIST: case ESIGAR_WHO_LIST:
esigar_who_list_get(port, sigar); esigar_who_list_get(port, sigar);
break; break;

16
bindings/erl/examples/arp.erl Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env escript
%%! -pz ebin
-include(sigar).
main(_) ->
{ok, S} = sigar:start(),
{ok, List} = sigar:arp_list(S),
lists:map(
fun(Arp) ->
lists:map(
fun(K) ->
io:format("~s\t", [sigar:get_value(K, Arp)]) end,
[address, hwaddr, type, ifname]),
io:format("~n")
end, List),
sigar:stop(S).

View File

@ -12,6 +12,7 @@
net_route_list/1, net_route_list/1,
file_system_list/1, file_system_list/1,
cpu_info_list/1, cpu_info_list/1,
arp_list/1,
who_list/1]). who_list/1]).
-define(NETCONN_CLIENT, 0x01). -define(NETCONN_CLIENT, 0x01).
@ -51,6 +52,9 @@ file_system_list({sigar, S}) ->
cpu_info_list({sigar, S}) -> cpu_info_list({sigar, S}) ->
do_command(S, ?CPU_INFO_LIST). do_command(S, ?CPU_INFO_LIST).
arp_list({sigar, S}) ->
do_command(S, ?ARP_LIST).
who_list({sigar, S}) -> who_list({sigar, S}) ->
do_command(S, ?WHO_LIST). do_command(S, ?WHO_LIST).