ubus call network.interface.wan status 用C的 API接口

将ubus call network.interface status 用C的API接口?

  • 通俗点说,ubus就是一个用于进程间通讯的通用框架。ubus具备很强的可移植性,能够很方便的移植到其余Linux平台上使用。
  • ubus模块被设计用于提供守护进程(daemons)和应用程序(applications)间的通信,包含了守护进程ubusd、库以及一些例子。ubusd能够认为是一个消息管理服务器(Server),须要通讯的进程能够经过提供的libubus使用ubus,而ubus又依赖于ubox。
  • 主要思路:可以参考网上的相关的例程,尝试读懂个大概,模仿下即可,因为读懂了过几天可能会忘记,获取到数据后,后面繁琐的就是需要解析下JSON的数据,总体来说不是很难。

ubus实现进程间通信举例

ubus分析

调用一个对象的子模块举例子

ubus call network.device status '{"name":"lo"}' 截取了lo设备的信息
ubus call network.interface status '{"interface":"lan"}' 等价于 ubus call network.interface.lan status

在这里插入图片描述

#include <libubox/blobmsg_json.h>
#include "uloop.h"
#include <string.h>
#include <stdlib.h>
#include <libubox/ustream.h>
#include <libubox/utils.h>
#include <libubus.h>
#include <libubox/blobmsg_json.h>
#include "cJSON.h"
#include "json.h"

static struct ubus_context * ctx = NULL;
static struct blob_buf b;
static const char * cli_path;
char *jsonstr = NULL;

enum
{
	SCAN_CHNID,
	SCAN_POLICY_MAX,
};

static const struct blobmsg_policy scan_policy[SCAN_POLICY_MAX] = {
		[SCAN_CHNID] = {.name = "name", .type = BLOBMSG_TYPE_STRING},
};

static int timeout = 30;
static bool simple_output = false;

static void scanreq_prog_cb(struct ubus_request *req, int type, struct blob_attr *msg)
{
	
	if (
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值