const char *name;
const char *proto;
const char *ifname;
- unsigned char ipaddr[4];
+ unsigned char *ipaddr;
int test;
bool enabled;
struct ucimap_list *aliases;
static int
network_parse_ip(void *section, struct uci_optmap *om, union ucimap_data *data, const char *str)
{
- unsigned char *target = (unsigned char *) data->s;
+ unsigned char *target;
int tmp[4];
int i;
if (sscanf(str, "%d.%d.%d.%d", &tmp[0], &tmp[1], &tmp[2], &tmp[3]) != 4)
return -1;
+ target = malloc(4);
+ if (!target)
+ return -1;
+
+ *data->data = target;
for (i = 0; i < 4; i++)
target[i] = (char) tmp[i];
network_format_ip(void *sction, struct uci_optmap *om, union ucimap_data *data, char **str)
{
static char buf[16];
- unsigned char *ip = (unsigned char *) data->s;
+ unsigned char *ip = (unsigned char *) data->data[0];
sprintf(buf, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
*str = buf;
return 0;
}
+static void
+network_free_ip(void *section, struct uci_optmap *om, void *ptr)
+{
+ free(ptr);
+}
+
static int
network_init_interface(struct uci_map *map, void *section, struct uci_section *s)
{
{
struct uci_network *net = section;
- list_add(&net->list, &ifs);
+ list_add_tail(&net->list, &ifs);
return 0;
}
struct uci_alias *a = section;
if (a->interface)
- list_add(&a->list, &a->interface->alias);
+ list_add_tail(&a->list, &a->interface->alias);
return 0;
}
.name = "ipaddr",
.parse = network_parse_ip,
.format = network_format_ip,
+ .free = network_free_ip,
}
},
{
ucimap_parse(&network_map, pkg);
list_for_each(p, &ifs) {
+ const unsigned char *ipaddr;
+
net = list_entry(p, struct uci_network, list);
+ ipaddr = net->ipaddr;
+ if (!ipaddr)
+ ipaddr = (const unsigned char *) "\x00\x00\x00\x00";
+
printf("New network section '%s'\n"
" type: %s\n"
" ifname: %s\n"
net->name,
net->proto,
net->ifname,
- net->ipaddr[0], net->ipaddr[1],
- net->ipaddr[2], net->ipaddr[3],
+ ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3],
net->test,
(net->enabled ? "on" : "off"));
for (i = 0; i < net->aliases->n_items; i++) {
- alias = net->aliases->item[i].section;
+ alias = net->aliases->item[i].ptr;
printf("New alias: %s\n", alias->name);
}
#if 0