diff options
author | Ted Lemon <source@isc.org> | 2001-05-11 21:31:06 +0000 |
---|---|---|
committer | Ted Lemon <source@isc.org> | 2001-05-11 21:31:06 +0000 |
commit | 0da9dc2537807eeffd93dae52767c85a0a6b4e8b (patch) | |
tree | 1323f82f33142716c6c395b06acb7f3a769e57be | |
parent | f52adb3d53b4bf0ad851d4bb58c564252dfd6360 (diff) | |
download | isc-dhcp-0da9dc2537807eeffd93dae52767c85a0a6b4e8b.tar.gz |
Support dotted octets and colon-seperated hex lists in omshell.
-rw-r--r-- | dhcpctl/dhcpctl.c | 37 | ||||
-rw-r--r-- | dhcpctl/dhcpctl.h | 2 | ||||
-rw-r--r-- | dhcpctl/omshell.c | 51 |
3 files changed, 90 insertions, 0 deletions
diff --git a/dhcpctl/dhcpctl.c b/dhcpctl/dhcpctl.c index 70e368ab..9e3fafa3 100644 --- a/dhcpctl/dhcpctl.c +++ b/dhcpctl/dhcpctl.c @@ -321,6 +321,43 @@ dhcpctl_status dhcpctl_set_string_value (dhcpctl_handle h, const char *value, return status; } +/* dhcpctl_set_buffer_value + + Sets a NUL-terminated ASCII value on an object referred to by + a dhcpctl_handle. like dhcpctl_set_value, but saves the + trouble of creating a data_string for a NUL-terminated string. + Does not update the server - just sets the value on the handle. */ + +dhcpctl_status dhcpctl_set_data_value (dhcpctl_handle h, + const char *value, unsigned len, + const char *value_name) +{ + isc_result_t status; + omapi_typed_data_t *tv = (omapi_typed_data_t *)0; + omapi_data_string_t *name = (omapi_data_string_t *)0; + int ip; + unsigned ll; + + ll = strlen (value_name); + status = omapi_data_string_new (&name, ll, MDL); + if (status != ISC_R_SUCCESS) + return status; + memcpy (name -> value, value_name, ll); + + status = omapi_typed_data_new (MDL, &tv, + omapi_datatype_data, len, value); + if (status != ISC_R_SUCCESS) { + omapi_data_string_dereference (&name, MDL); + return status; + } + memcpy (tv -> u.buffer.value, value, len); + + status = omapi_set_value (h, (omapi_object_t *)0, name, tv); + omapi_data_string_dereference (&name, MDL); + omapi_typed_data_dereference (&tv, MDL); + return status; +} + /* dhcpctl_set_boolean_value Sets a boolean value on an object - like dhcpctl_set_value, diff --git a/dhcpctl/dhcpctl.h b/dhcpctl/dhcpctl.h index e78a64ee..8cfe133a 100644 --- a/dhcpctl/dhcpctl.h +++ b/dhcpctl/dhcpctl.h @@ -85,6 +85,8 @@ dhcpctl_status dhcpctl_set_value (dhcpctl_handle, dhcpctl_data_string, const char *); dhcpctl_status dhcpctl_set_string_value (dhcpctl_handle, const char *, const char *); +dhcpctl_status dhcpctl_set_data_value (dhcpctl_handle, + const char *, unsigned, const char *); dhcpctl_status dhcpctl_set_boolean_value (dhcpctl_handle, int, const char *); dhcpctl_status dhcpctl_set_int_value (dhcpctl_handle, int, const char *); dhcpctl_status dhcpctl_object_update (dhcpctl_handle, dhcpctl_handle); diff --git a/dhcpctl/omshell.c b/dhcpctl/omshell.c index 24d2b6bf..26555271 100644 --- a/dhcpctl/omshell.c +++ b/dhcpctl/omshell.c @@ -453,9 +453,60 @@ int main (int argc, char **argv, char **envp) break; case NUMBER: + strcpy (buf, val); + token = peek_token (&val, (unsigned *)0, cfile); + /* Colon-seperated hex list? */ + if (token == COLON) + goto cshl; + else if (token == DOT) { + s = buf; + val = buf; + do { + int intval = atoi (val); + if (intval > 255) { + parse_warn (cfile, + "dotted octet > 255: %s", + val); + skip_to_semi (cfile); + goto badnum; + } + *s++ = intval; + token = next_token (&val, + (unsigned *)0, cfile); + if (token != DOT) + break; + token = next_token (&val, + (unsigned *)0, cfile); + } while (token == NUMBER); + dhcpctl_set_data_value (oh, buf, + (unsigned)(s - buf), + s1); + break; + } dhcpctl_set_int_value (oh, atoi (val), s1); + badnum: break; + case NUMBER_OR_NAME: + strcpy (buf, val); + cshl: + s = buf; + val = buf; + do { + convert_num (cfile, s, val, 16, 8); + ++s; + token = next_token (&val, + (unsigned *)0, cfile); + if (token != DOT) + break; + token = next_token (&val, + (unsigned *)0, cfile); + } while (token == NUMBER || + token == NUMBER_OR_NAME); + dhcpctl_set_data_value (oh, buf, + (unsigned)(s - buf), s1); + break; + default: printf ("invalid value.\n"); } |