gpt4 book ai didi

c - OpenWrt LibUbi 实现

转载 作者:太空宇宙 更新时间:2023-11-04 08:34:10 24 4
gpt4 key购买 nike

我正在尝试使用 libuci 为 OpenWrt 路由器开发一个应用程序(用 ANSI C 编写)。我读过这篇有用的帖子:How to find out if the eth0 mode is static or dhcp?

我开发了一个应用程序,它能够使用 uci 库读取网络数据(在本例中我读取是否启用了 ppp)。

char path[]="network.ppp.enabled";
struct uci_ptr ptr;
struct uci_context *c = uci_alloc_context();

if(!c) return;

if (strcmp(typeCmd, "GET") == 0){

if ((uci_lookup_ptr(c, &ptr, path, true) != UCI_OK) || (ptr.o==NULL || ptr.o->v.string==NULL)) {
uci_free_context(c);
return;
}

if(ptr.flags & UCI_LOOKUP_COMPLETE)
strcpy(buffer, ptr.o->v.string);

uci_free_context(c);

printf("\n\nUCI result data: %s\n\n", buffer);
}

现在我想尝试设置新的网络数据(所以我想启用 ppp -> 将 ppp 设置为 1)我写过:

}else if (strcmp(typeCmd, "SET") == 0){

if ((uci_lookup_ptr(c, &ptr, path, true) != UCI_OK) || (ptr.o==NULL || ptr.o->v.string==NULL)) {
uci_free_context(c);
return;
}

ptr.o->v.string = "1";
if ((uci_set(c, &ptr) != UCI_OK) || (ptr.o==NULL || ptr.o->v.string==NULL)) {
uci_free_context(c);
return;
}

if (uci_commit(c, struct uci_package **p, true) != UCI_OK){
uci_free_context(c);
return;
}
}

LibUci 文档不存在,文件 uci.h 中只有一些信息,我不知道如何填充 uci_ptr 结构,所以我从 uci_lookup_ptr 中检索它,我'我已经更改了 ptr.o->v.string 并使用新参数启动了 uci_set,但是关于 uci_commit 我不知道 结构 uci_package **p.

有人调用我分享一些文档或给我看一些例子吗?

非常感谢

最佳答案

关于 UCI 的文档非常薄。我想出来的方法是使用 uci 结构中的 uci_ptr 的 .value 属性。

从那以后,我更改行:

ptr.o->v.string = "1";

到:

ptr.value = "1";

我还更改了你的提交行如下:

uci_commit(ctx, &ptr.p, false);

这对我有用。

关于c - OpenWrt LibUbi 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26993546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com