2013-10-21 43 views

回答

1

在OpenWrt的維基有大量的文檔資料:

http://wiki.openwrt.org/doc/uci

要通過命令行更改network.lan.proto你可以使用:

UCI集網絡.lan.proto = dhcp

哦,然後你會想要提交更改並重新啓動網絡K:

UCI提交網絡 /etc/init.d/network重啓

1

如果你要使用UCI的C API,你可以使用下面的代碼:

#include <uci.h> 

void main() 
{ 
    char path[]="network.lan.proto"; 
    char buffer[80]; 
    struct uci_ptr ptr; 
    struct uci_context *c = uci_alloc_context(); 

    if(!c) return; 

    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); 

    printf("%s\n", buffer); 

    // setting UCI values 
    // ----------------------------------------------------------- 
    // this will set the value to 1234 
    ptr.value = "1234"; 
    // commit your changes to make sure that UCI values are saved 
    if (uci_commit(c, &ptr.p, false) != UCI_OK) 
    { 
     uci_free_context(c); 
     uci_perror(c,"UCI Error"); 
     return; 
    } 

    uci_free_context(c); 
} 

是參考從這篇文章:OpenWrt LibUbi implementation

+0

需要添加uciset之前提交.. ////如果((uci_set(C,PTR) != UCI_OK) ||(ptr.o == NULL || ptr.o-> v.string == NULL)){ uci_free_context(c); return; } – zyanlu

0

網絡配置位於/ etc/config/network。下面是一個配置的例子,你可以使用:

config wifi-iface 
    option 'device'  'radio0' 
    option 'mode'  'sta' 
    option 'ssid'  'Some Wireless Network' 
    option 'encryption' 'psk2' 
    option 'key'  '12345678' 
    option 'network' 'wwan' 

你可以找到更多的文檔在這裏:OpenWRT network config