1999-09-02 00:32:56 +00:00
|
|
|
/* test.c
|
|
|
|
|
|
|
|
Test code for omapip... */
|
|
|
|
|
|
|
|
/*
|
2014-01-26 10:52:15 -08:00
|
|
|
* Copyright (c) 2009-2010,2013-2014 by Internet Systems Consortium, Inc. ("ISC")
|
2010-05-25 00:22:29 +00:00
|
|
|
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
2005-03-17 20:15:29 +00:00
|
|
|
* Copyright (c) 1999-2003 by Internet Software Consortium
|
1999-09-02 00:32:56 +00:00
|
|
|
*
|
2005-03-17 20:15:29 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
1999-09-02 00:32:56 +00:00
|
|
|
*
|
2005-03-17 20:15:29 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
|
|
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
1999-09-02 00:32:56 +00:00
|
|
|
*
|
2005-03-17 20:15:29 +00:00
|
|
|
* Internet Systems Consortium, Inc.
|
|
|
|
* 950 Charter Street
|
|
|
|
* Redwood City, CA 94063
|
|
|
|
* <info@isc.org>
|
2009-07-23 18:52:21 +00:00
|
|
|
* https://www.isc.org/
|
2000-03-17 04:00:32 +00:00
|
|
|
*
|
1999-09-02 00:32:56 +00:00
|
|
|
*/
|
|
|
|
|
2010-01-23 08:49:32 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
1999-10-08 03:43:15 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
2005-03-17 20:15:29 +00:00
|
|
|
#include <string.h>
|
2009-10-28 04:12:30 +00:00
|
|
|
#include <omapip/result.h>
|
2000-05-17 16:04:26 +00:00
|
|
|
#include <sys/time.h>
|
1999-09-02 00:32:56 +00:00
|
|
|
#include <omapip/omapip.h>
|
2009-10-28 04:12:30 +00:00
|
|
|
#include <omapip/isclib.h>
|
1999-09-02 00:32:56 +00:00
|
|
|
|
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
1999-09-02 00:36:58 +00:00
|
|
|
omapi_object_t *listener = (omapi_object_t*)0;
|
|
|
|
omapi_object_t *connection = (omapi_object_t*)0;
|
1999-09-02 00:32:56 +00:00
|
|
|
isc_result_t status;
|
|
|
|
|
2013-12-11 08:08:42 -08:00
|
|
|
status = dhcp_context_create(DHCP_CONTEXT_PRE_DB | DHCP_CONTEXT_POST_DB,
|
|
|
|
NULL, NULL);
|
2010-05-25 00:22:29 +00:00
|
|
|
if (status != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "Can't initialize context: %s\n",
|
|
|
|
isc_result_totext(status));
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-10-28 04:12:30 +00:00
|
|
|
|
2014-08-28 07:56:20 -04:00
|
|
|
status = omapi_init ();
|
|
|
|
if (status != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "omapi_init failed: %s\n",
|
|
|
|
isc_result_totext(status));
|
|
|
|
exit(1);
|
|
|
|
}
|
1999-09-02 00:32:56 +00:00
|
|
|
|
|
|
|
if (argc > 1 && !strcmp (argv [1], "listen")) {
|
|
|
|
if (argc < 3) {
|
|
|
|
fprintf (stderr, "Usage: test listen port\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
2000-01-26 14:56:18 +00:00
|
|
|
status = omapi_generic_new (&listener, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
if (status != ISC_R_SUCCESS) {
|
|
|
|
fprintf (stderr, "omapi_generic_new: %s\n",
|
|
|
|
isc_result_totext (status));
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
status = omapi_protocol_listen (listener,
|
1999-11-23 19:07:17 +00:00
|
|
|
(unsigned)atoi (argv [2]), 1);
|
1999-09-02 00:32:56 +00:00
|
|
|
if (status != ISC_R_SUCCESS) {
|
|
|
|
fprintf (stderr, "omapi_listen: %s\n",
|
|
|
|
isc_result_totext (status));
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
omapi_dispatch (0);
|
|
|
|
} else if (argc > 1 && !strcmp (argv [1], "connect")) {
|
|
|
|
if (argc < 4) {
|
|
|
|
fprintf (stderr, "Usage: test listen address port\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
2000-01-26 14:56:18 +00:00
|
|
|
status = omapi_generic_new (&connection, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
if (status != ISC_R_SUCCESS) {
|
|
|
|
fprintf (stderr, "omapi_generic_new: %s\n",
|
|
|
|
isc_result_totext (status));
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
status = omapi_protocol_connect (connection,
|
1999-11-23 19:07:17 +00:00
|
|
|
argv [2],
|
|
|
|
(unsigned)atoi (argv [3]), 0);
|
1999-09-02 00:32:56 +00:00
|
|
|
fprintf (stderr, "connect: %s\n", isc_result_totext (status));
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
exit (1);
|
|
|
|
status = omapi_wait_for_completion (connection, 0);
|
|
|
|
fprintf (stderr, "completion: %s\n",
|
|
|
|
isc_result_totext (status));
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
exit (1);
|
|
|
|
/* ... */
|
|
|
|
} else {
|
|
|
|
fprintf (stderr, "Usage: test [listen | connect] ...\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|