diff options
author | John Estabrook <jestabro@vyos.io> | 2024-05-22 09:15:06 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-22 09:15:06 -0500 |
commit | 897e78cabc9ae3a24bd2439f2bb4f9339d7d0d3a (patch) | |
tree | eaffae0dffcc951b60c35cc3329051e40021a9ee /src/completion/list_interfaces/iface.c | |
parent | 82d12db7ecdecda9953fb8c1ff553818f94bac03 (diff) | |
parent | fdcbb845ddc5cc646cfa01f590b0ea331c31f80b (diff) | |
download | vyos-utils-897e78cabc9ae3a24bd2439f2bb4f9339d7d0d3a.tar.gz vyos-utils-897e78cabc9ae3a24bd2439f2bb4f9339d7d0d3a.zip |
Merge pull request #22 from dmbaturin/reorg
T6380: Reorganize the directory structure and reflect it in the README
Diffstat (limited to 'src/completion/list_interfaces/iface.c')
-rw-r--r-- | src/completion/list_interfaces/iface.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/completion/list_interfaces/iface.c b/src/completion/list_interfaces/iface.c new file mode 100644 index 0000000..bf2f025 --- /dev/null +++ b/src/completion/list_interfaces/iface.c @@ -0,0 +1,38 @@ +/* + * Simple wrapper of getifaddrs for OCaml list of interfaces + */ +#include <ifaddrs.h> +#include <caml/mlvalues.h> +#include <caml/memory.h> +#include <caml/alloc.h> + +CAMLprim value interface_list(value unit) { + struct ifaddrs *ifaddr; + struct ifaddrs *ifa; + + CAMLparam1( unit ); + CAMLlocal2( cli, cons ); + + cli = Val_emptylist; + + if (getifaddrs(&ifaddr) == -1) { + CAMLreturn(cli); + } + for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { + if (ifa->ifa_name == NULL) + continue; + + CAMLlocal1( ml_s ); + cons = caml_alloc(2, 0); + + ml_s = caml_copy_string(ifa->ifa_name); + Store_field( cons, 0, ml_s ); + Store_field( cons, 1, cli ); + + cli = cons; + } + + freeifaddrs(ifaddr); + + CAMLreturn(cli); +} |