#include <stdio.h>
#include <libubox/blobmsg.h>
#include <libubox/blobmsg_json.h>
#define _GNU_SOURCE
static struct blob_buf b;
enum {
DEV_ADDRESSES,
__DEV_MAX,
};
static const struct blobmsg_policy dev_policy[__DEV_MAX] = {
[DEV_ADDRESSES] = { .name = "address", .type = BLOBMSG_TYPE_ARRAY },
};
static void ubus_callback(struct ubus_request *req, int type, struct blob_attr *msg) {
struct blob_attr *tb[__DEV_MAX];
int rem;
struct blob_attr *cur;
blobmsg_parse(dev_policy, __DEV_MAX, tb, blob_data(msg), blob_len(msg));
blobmsg_for_each_attr(cur, tb[DEV_ADDRESSES], rem) {
printf("device addr: %s\n", blobmsg_data
(cur
));
}
}
int main() {
static struct ubus_context *ubus_ctx;
uint32_t ubus_id;
//const char *ubus_socket = NULL;
ubus_ctx = ubus_connect(NULL);
if(!ubus_ctx)
return -1;
ubus_lookup_id(ubus_ctx, "network.interface.lan", &ubus_id);
ubus_invoke(ubus_ctx, ubus_id, "status", b.head, ubus_callback, NULL, 1000); //TODO: timeout chosen in arbitrary way - find sane value
}