openwrt用户空间进中通信常用的通信方式是使用ubus通信,下面给出一个例子,是客户端向服务器请求ap的个数。
服务器端代码
#include
#include
#include "libubus.h"
static struct ubus_context *ctx;
static struct blob_buf b;
enum {
REQ_STATION_COUNT,
REQ_AP_NAME,
__REQ_MAX
};
/* 接收的解析格式, client发送过来的调用是 blobmsg_add_u32(&b, "getcnt", ap_index); */
static const struct blobmsg_policy fun2_message_parse_policy[__REQ_MAX] = {
[REQ_STATION_COUNT] = { .name = "getcnt", .type = BLOBMSG_TYPE_INT32 },
[REQ_STATION_COUNT] = { .name = "apname", .type = BLOBMSG_TYPE_STRING },
};
static int fun2_handler(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
stru