Handle option lists properly in script.c.

This commit is contained in:
Nicholas J. Kain 2010-11-12 18:04:54 -05:00
parent 9d7ad2f11c
commit c0703fc8c9
3 changed files with 41 additions and 36 deletions

View File

@ -187,41 +187,41 @@ struct option_set *find_option(struct option_set *opt_list, char code)
}
/* add an option to the opt_list */
void attach_option(struct option_set **opt_list, struct dhcp_option *option,
char *buffer, int length)
{
struct option_set *existing, *new, **curr;
/* /\* add an option to the opt_list *\/ */
/* void attach_option(struct option_set **opt_list, struct dhcp_option *option, */
/* char *buffer, int length) */
/* { */
/* struct option_set *existing, *new, **curr; */
/* add it to an existing option */
if ((existing = find_option(*opt_list, option->code))) {
log_line("Attaching option %s to existing member of list",
option->name);
if (option->flags & OPTION_LIST) {
if (existing->data[OPT_LEN] + length <= 255) {
existing->data = realloc(existing->data,
existing->data[OPT_LEN] + length + 2);
memcpy(existing->data + existing->data[OPT_LEN] + 2, buffer,
length);
existing->data[OPT_LEN] += length;
} /* else, ignore the data; we could put this in a second option
in the future */
} /* else, ignore the new data */
} else {
log_line("Attaching option %s to list", option->name);
/* /\* add it to an existing option *\/ */
/* if ((existing = find_option(*opt_list, option->code))) { */
/* log_line("Attaching option %s to existing member of list", */
/* option->name); */
/* if (option->flags & OPTION_LIST) { */
/* if (existing->data[OPT_LEN] + length <= 255) { */
/* existing->data = realloc(existing->data, */
/* existing->data[OPT_LEN] + length + 2); */
/* memcpy(existing->data + existing->data[OPT_LEN] + 2, buffer, */
/* length); */
/* existing->data[OPT_LEN] += length; */
/* } /\* else, ignore the data; we could put this in a second option */
/* in the future *\/ */
/* } /\* else, ignore the new data *\/ */
/* } else { */
/* log_line("Attaching option %s to list", option->name); */
/* make a new option */
new = xmalloc(sizeof(struct option_set));
new->data = xmalloc(length + 2);
new->data[OPT_CODE] = option->code;
new->data[OPT_LEN] = length;
memcpy(new->data + 2, buffer, length);
/* /\* make a new option *\/ */
/* new = xmalloc(sizeof(struct option_set)); */
/* new->data = xmalloc(length + 2); */
/* new->data[OPT_CODE] = option->code; */
/* new->data[OPT_LEN] = length; */
/* memcpy(new->data + 2, buffer, length); */
curr = opt_list;
while (*curr && (*curr)->data[OPT_CODE] < option->code)
curr = &(*curr)->next;
/* curr = opt_list; */
/* while (*curr && (*curr)->data[OPT_CODE] < option->code) */
/* curr = &(*curr)->next; */
new->next = *curr;
*curr = new;
}
}
/* new->next = *curr; */
/* *curr = new; */
/* } */
/* } */

View File

@ -35,6 +35,6 @@ int end_option(unsigned char *optionptr);
int add_option_string(unsigned char *optionptr, unsigned char *string);
int add_simple_option(unsigned char *optionptr, unsigned char code, uint32_t data);
struct option_set *find_option(struct option_set *opt_list, char code);
void attach_option(struct option_set **opt_list, struct dhcp_option *option, char *buffer, int length);
/* void attach_option(struct option_set **opt_list, struct dhcp_option *option, char *buffer, int length); */
#endif

View File

@ -78,6 +78,9 @@ static void fill_options(char *dest, unsigned char *option,
*(dest++) = '/';
option += 4;
optlen = 4;
dest += sprintip(dest, maxlen - (dest - odest), "", option);
optlen = option_lengths[type];
break;
case OPTION_IP: /* Works regardless of host byte order. */
dest += sprintip(dest, maxlen - (dest - odest), "", option);
break;
@ -117,7 +120,9 @@ static void fill_options(char *dest, unsigned char *option,
}
option += optlen;
len -= optlen;
if (len <= 0) break;
if (len <= 0)
break;
*(dest++) = ':';
}
}