Hey.

> I need to create a new 'interface' section with  name 'lan1'  in
> /etc/config/network
> 
> config   interface   'lan1'
>   ....
>   ...
> 
> I need to do that through C API.
> Currently I  am creating a new session using   uci_add_section(..) which
> creates a  section with no name.

struct uci_package *p;

/* equivalent to uci set network.lan1=interface */
struct uci_ptr ptr = {
        .package = "network",
        .section = "lan1",
        .option  = NULL,
        .value   = "interface"
};

uci_load(context, ptr.package, &p);

if (!p) {
        /* cannot load config file */
        uci_perror(context, "uci_load(): ");
        return;
}

if (!uci_lookup_ptr(context, &ptr, NULL, true)) {
        /* section already exists */
        return;
}

if (uci_set(context, &ptr)) {
        /* failed to create named section */
        uci_perror(context, "uci_set(): ");
        return;
}

/* section created; ptr.s will hold a pointer to it */



~ Jow

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
openwrt-users mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-users

Reply via email to