From babf43abf301d072192bda1f72a47440c354b072 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 4 Aug 2017 22:46:45 +0000 Subject: Add the higher layer of libwpactrl --- src/libwpactrl/wpactrl_findnetwork.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/libwpactrl/wpactrl_findnetwork.c (limited to 'src/libwpactrl/wpactrl_findnetwork.c') diff --git a/src/libwpactrl/wpactrl_findnetwork.c b/src/libwpactrl/wpactrl_findnetwork.c new file mode 100644 index 0000000..e5851d0 --- /dev/null +++ b/src/libwpactrl/wpactrl_findnetwork.c @@ -0,0 +1,26 @@ +/* ISC license. */ + +#include +#include +#include +#include "wpactrl-internal.h" + +int wpactrl_findnetwork (wpactrl_t *a, char const *ssid, uint32_t *id, tain_t *stamp) +{ + char buf[WPACTRL_PACKET_MAX] ; + stralloc sa = STRALLOC_ZERO ; + genalloc ga = GENALLOC_ZERO ; /* wpactrl_networks_t */ + size_t i = 0 ; + wpactrl_networks_t *p ; + size_t n ; + ssize_t r = wpactrl_query(a, "LIST_NETWORKS", buf, WPACTRL_PACKET_MAX, stamp) ; + if (r < 0) return -1 ; + if (!wpactrl_networks_parse(buf, r, &ga, &sa)) return -1 ; + n = genalloc_len(wpactrl_networks_t, &ga) ; + p = genalloc_s(wpactrl_networks_t, &ga) ; + for (; i < n ; i++) if (!strcmp(ssid, sa.s + p[i].ssid_start)) break ; + if (i < n) *id = p[i].id ; + genalloc_free(wpactrl_networks_t, &ga) ; + stralloc_free(&sa) ; + return i < n ; +} -- cgit v1.2.3