diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-08-04 22:46:45 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-08-04 22:46:45 +0000 |
commit | babf43abf301d072192bda1f72a47440c354b072 (patch) | |
tree | d917d33ebb97d2b783e163f299b360be4f5b3a0a /src/libwpactrl/wpactrl_findnetwork.c | |
parent | 69099d84949a8044fdfc74e9d7ff6b9e57fc0bcd (diff) | |
download | bcnm-babf43abf301d072192bda1f72a47440c354b072.tar.xz |
Add the higher layer of libwpactrl
Diffstat (limited to 'src/libwpactrl/wpactrl_findnetwork.c')
-rw-r--r-- | src/libwpactrl/wpactrl_findnetwork.c | 26 |
1 files changed, 26 insertions, 0 deletions
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 <skalibs/stralloc.h> +#include <skalibs/genalloc.h> +#include <bcnm/wpactrl.h> +#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 ; +} |