44 isc_result_t
find_class (
struct class **c,
const char *n,
const char *f,
int l)
66 static void usage (
char *s) {
67 fprintf (stderr,
"Usage: %s\n", s);
71 static void check (isc_result_t status,
const char *func) {
72 if (status != ISC_R_SUCCESS) {
73 fprintf (stderr,
"%s: %s\n", func, isc_result_totext (status));
79 main(
int argc,
char **argv) {
80 isc_result_t status, waitstatus;
85 const char *name = 0, *algorithm =
"hmac-md5";
88 const char *server =
"127.0.0.1";
98 for (i = 1; i < argc; i++) {
105 if (status != ISC_R_SUCCESS) {
106 fprintf (stderr,
"dhcpctl_initialize: %s\n",
107 isc_result_totext (status));
111 memset (&oh, 0,
sizeof oh);
115 }
else if (oh == NULL) {
116 printf (
"obj: <null>\n");
128 (
int)(r -> rtype -> u .
buffer . len),
129 r -> rtype -> u .
buffer . value);
132 for (i = 0; i < g -> nvalues; i++) {
135 if (!g -> values [i])
138 printf (
"%.*s = ", (
int)v -> name -> len,
145 switch (v -> value -> type) {
148 v -> value -> u . integer);
152 printf (
"\"%.*s\"\n",
153 (
int) v -> value -> u.buffer.len,
154 v -> value -> u.buffer.
value);
160 sizeof(hex_buf), hex_buf);
161 printf(
"%s\n", hex_buf);
171 fputs (
"> ", stdout);
173 if (fgets (buf,
sizeof(buf), stdin) == NULL)
176 status =
new_parse (&cfile, -1, buf, strlen(buf),
"<STDIN>", 1);
177 check(status,
"new_parse()");
179 token =
next_token (&val, (
unsigned *)0, cfile);
192 printf (
"Commands:\n");
193 printf (
" port <server omapi port>\n");
194 printf (
" server <server address>\n");
195 printf (
" key <key name> <key value>\n");
196 printf (
" connect\n");
197 printf (
" new <object-type>\n");
198 printf (
" set <name> = <value>\n");
199 printf (
" create\n");
201 printf (
" update\n");
202 printf (
" unset <name>\n");
203 printf (
" refresh\n");
204 printf (
" remove\n");
209 token =
next_token (&val, (
unsigned *)0, cfile);
212 se = getservbyname (val,
"tcp");
214 port = ntohs (se -> s_port);
216 printf (
"unknown service name: %s\n", val);
219 }
else if (token ==
NUMBER) {
223 printf (
"usage: port <port>\n");
226 token =
next_token (&val, (
unsigned *)0, cfile);
228 printf (
"usage: port <server>\n");
235 token =
next_token (&val, (
unsigned *)0, cfile);
237 int alen = (
sizeof buf) - 1;
242 if (len + 1 > alen) {
244 printf (
"usage: server <server>\n");
249 token =
next_token (&val, (
unsigned *)0, cfile);
253 token =
next_token (&val, (
unsigned *)0, cfile);
261 token =
next_token (&val, (
unsigned *)0, cfile);
265 token =
next_token (&val, (
unsigned *)0, cfile);
273 token =
next_token (&val, (
unsigned *)0, cfile);
277 token =
next_token (&val, (
unsigned *)0, cfile);
288 printf (
"usage: server <server>\n");
295 printf (
"no memory to store server name.\n");
302 token =
next_token (&val, (
unsigned *)0, cfile);
304 printf (
"usage: server <server>\n");
311 token =
peek_token(&val, (
unsigned *)0, cfile);
313 token =
next_token (&val, (
unsigned *)0, cfile);
315 printf (
"usage: key <name> <value>\n");
321 printf (
"no memory for key name.\n");
329 printf (
"usage: key <name> <value>\n");
336 memset (&secret, 0,
sizeof secret);
341 token =
next_token (&val, (
unsigned *)0, cfile);
343 printf (
"usage: key <name> <secret>\n");
350 token =
next_token (&val, (
unsigned *)0, cfile);
352 printf (
"usage: connect\n");
365 if (status != ISC_R_SUCCESS) {
367 "Cannot create authenticator: %s\n",
368 isc_result_totext (status));
373 memset (&connection, 0,
sizeof connection);
375 server, port, authenticator);
376 if (status != ISC_R_SUCCESS) {
377 fprintf (stderr,
"dhcpctl_connect: %s\n",
378 isc_result_totext (status));
385 token =
next_token (&val, (
unsigned *)0, cfile);
387 printf (
"usage: new <object-type>\n");
392 printf (
"an object is already open.\n");
398 printf (
"not connected.\n");
404 if (status != ISC_R_SUCCESS) {
405 printf (
"can't create object: %s\n",
406 isc_result_totext (status));
410 token =
next_token (&val, (
unsigned *)0, cfile);
412 printf (
"usage: new <object-type>\n");
419 token =
next_token (&val, (
unsigned *)0, cfile);
421 printf (
"usage: close\n");
427 printf (
"not connected.\n");
433 printf (
"not open.\n");
442 token =
next_token (&val, (
unsigned *)0, cfile);
446 printf (
"usage: set <name> = <value>\n");
452 printf (
"no open object.\n");
458 printf (
"not connected.\n");
464 strlcpy (s1, val,
sizeof(s1));
467 strncat (s1, val,
sizeof(s1)-strlen(s1)-1);
470 token =
next_token (&val, (
unsigned *)0, cfile);
474 token =
next_token (&val, (
unsigned *)0, cfile);
478 token =
next_token (&val, (
unsigned *)0, cfile);
483 token =
peek_token (&val, (
unsigned *)0, cfile);
487 else if (token ==
DOT) {
491 int intval = atoi (val);
494 "dotted octet > 255: %s",
501 (
unsigned *)0, cfile);
506 (
unsigned *)0, cfile)) ==
DOT)
508 }
while (token ==
NUMBER);
515 token =
next_token (&val, (
unsigned *)0, cfile);
529 (
unsigned *)0, cfile);
533 (
unsigned *)0, cfile);
534 }
while (token ==
NUMBER ||
537 (
unsigned)(s - buf), s1);
541 printf (
"invalid value.\n");
550 token =
next_token (&val, (
unsigned *)0, cfile);
554 printf (
"usage: unset <name>\n");
560 printf (
"no open object.\n");
566 printf (
"not connected.\n");
572 strlcpy (s1, val,
sizeof(s1));
575 strncat (s1, val,
sizeof(s1)-strlen(s1)-1);
578 token =
next_token (&val, (
unsigned *)0, cfile);
589 token =
next_token (&val, (
unsigned *)0, cfile);
591 printf (
"usage: %s\n", val);
597 printf (
"not connected.\n");
603 printf (
"you must make a new object first!\n");
614 if (status == ISC_R_SUCCESS)
617 if (status == ISC_R_SUCCESS)
619 if (status != ISC_R_SUCCESS) {
620 printf (
"can't open object: %s\n",
621 isc_result_totext (status));
628 token =
next_token (&val, (
unsigned *)0, cfile);
630 printf (
"usage: %s\n", val);
636 printf (
"not connected.\n");
642 printf (
"you haven't opened an object yet!\n");
648 if (status == ISC_R_SUCCESS)
651 if (status == ISC_R_SUCCESS)
653 if (status != ISC_R_SUCCESS) {
654 printf (
"can't update object: %s\n",
655 isc_result_totext (status));
662 token =
next_token (&val, (
unsigned *)0, cfile);
664 printf (
"usage: remove\n");
670 printf (
"not connected.\n");
675 printf (
"no object.\n");
680 if (status == ISC_R_SUCCESS)
683 if (status == ISC_R_SUCCESS)
685 if (status != ISC_R_SUCCESS) {
686 printf (
"can't destroy object: %s\n",
687 isc_result_totext (status));
694 token =
next_token (&val, (
unsigned *)0, cfile);
696 printf (
"usage: refresh\n");
702 printf (
"not connected.\n");
707 printf (
"no object.\n");
712 if (status == ISC_R_SUCCESS)
715 if (status == ISC_R_SUCCESS)
717 if (status != ISC_R_SUCCESS) {
718 printf (
"can't refresh object: %s\n",
719 isc_result_totext (status));
736 return ISC_R_SUCCESS;
void print_hex_or_string(unsigned len, const u_int8_t *data, unsigned limit, char *buf)
isc_result_t end_parse(struct parse **cfile)
isc_result_t dhcp_set_control_state(control_object_state_t oldstate, control_object_state_t newstate)
void * dmalloc(unsigned, const char *, int)
dhcpctl_status dhcpctl_set_null_value(dhcpctl_handle h, const char *value_name)
dhcpctl_status dhcpctl_connect(dhcpctl_handle *connection, const char *server_name, int port, dhcpctl_handle authinfo)
int check_collection(struct packet *p, struct lease *l, struct collection *c)
omapi_typed_data_t * value
dhcpctl_status dhcpctl_new_object(dhcpctl_handle *, dhcpctl_handle, const char *)
enum dhcp_token peek_token(const char **rval, unsigned *rlen, struct parse *cfile)
dhcpctl_status dhcpctl_open_object(dhcpctl_handle, dhcpctl_handle, int)
void bootp(struct packet *packet)
dhcpctl_status dhcpctl_initialize()
struct omapi_typed_data_t::@3::@4 buffer
int main(int argc, char **argv)
dhcpctl_status dhcpctl_wait_for_completion(dhcpctl_handle h, dhcpctl_status *s)
enum dhcp_token next_token(const char **rval, unsigned *rlen, struct parse *cfile)
#define DHCPD_LOG_FACILITY
dhcpctl_status dhcpctl_set_data_value(dhcpctl_handle h, const char *value, unsigned len, const char *value_name)
void convert_num(struct parse *cfile, unsigned char *buf, const char *str, int base, unsigned size)
isc_result_t omapi_object_dereference(omapi_object_t **, const char *, int)
dhcpctl_status dhcpctl_set_int_value(dhcpctl_handle h, int value, const char *value_name)
#define dhcpctl_null_handle
union omapi_typed_data_t::@3 u
dhcpctl_status dhcpctl_object_remove(dhcpctl_handle connection, dhcpctl_handle h)
void skip_to_semi(struct parse *cfile)
char * parse_host_name(struct parse *cfile)
int parse_allow_deny(struct option_cache **oc, struct parse *cfile, int flag)
void dhcpv6(struct packet *)
int parse_base64(struct data_string *data, struct parse *cfile)
dhcpctl_status dhcpctl_object_refresh(dhcpctl_handle connection, dhcpctl_handle h)
isc_result_t find_class(struct class **c, const char *n, const char *f, int l)
dhcpctl_status dhcpctl_new_authenticator(dhcpctl_handle *, const char *, const char *, const unsigned char *, unsigned)
dhcpctl_status dhcpctl_set_string_value(dhcpctl_handle h, const char *value, const char *value_name)
dhcpctl_status dhcpctl_object_update(dhcpctl_handle connection, dhcpctl_handle h)
const unsigned char * data
void classify(struct packet *packet, struct class *class)
int parse_warn(struct parse *cfile, const char *fmt,...)
void dhcp(struct packet *packet)
isc_result_t new_parse(struct parse **cfile, int file, char *inbuf, unsigned buflen, const char *name, int eolp)