Get clients for all hostapd ifaces

This commit is contained in:
PolynomialDivision 2017-07-16 21:15:13 +02:00
parent e444dd57db
commit 742b6d9cf2
3 changed files with 21 additions and 7 deletions

View file

@ -7,5 +7,6 @@
int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir); int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir);
int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req); int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req);
char* hostapd_dir_glob;
#endif #endif

View file

@ -35,6 +35,7 @@ int main(int argc, char **argv) {
case 'h': case 'h':
snprintf(opt_hostapd_dir, BUFSIZE_DIR, "%s", optarg); snprintf(opt_hostapd_dir, BUFSIZE_DIR, "%s", optarg);
printf("hostapd dir: %s\n", opt_hostapd_dir); printf("hostapd dir: %s\n", opt_hostapd_dir);
hostapd_dir_glob = optarg;
default: default:
break; break;
} }

View file

@ -349,11 +349,23 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_
} }
static int ubus_get_clients() { static int ubus_get_clients() {
DIR *dirp;
struct dirent *entry;
dirp = opendir(hostapd_dir_glob); // error handling?
while ((entry = readdir(dirp)) != NULL) {
if (entry->d_type == DT_SOCK) {
char hostapd_iface[256];
uint32_t id; uint32_t id;
int ret = ubus_lookup_id(ctx, "hostapd.wlan0", &id); sprintf(hostapd_iface, "hostapd.%s", entry->d_name);
if (ret) printf("Subscribing to %s\n", hostapd_iface);
return ret; int ret = ubus_lookup_id(ctx, hostapd_iface, &id);
if(!ret)
{
int timeout = 1; int timeout = 1;
int ubus_shit = ubus_invoke(ctx, id, "get_clients", NULL, ubus_get_clients_cb, NULL, timeout * 1000); ubus_invoke(ctx, id, "get_clients", NULL, ubus_get_clients_cb, NULL, timeout * 1000);
return ubus_shit; }
}
}
return 0;
} }