Home | History | Annotate | Line # | Download | only in omapip
test.c revision 1.2.2.2
      1 /*	$NetBSD: test.c,v 1.2.2.2 2018/04/16 01:59:48 pgoyette Exp $	*/
      2 
      3 /* test.c
      4 
      5    Test code for omapip... */
      6 
      7 /*
      8  * Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
      9  * Copyright (c) 1999-2003 by Internet Software Consortium
     10  *
     11  * This Source Code Form is subject to the terms of the Mozilla Public
     12  * License, v. 2.0. If a copy of the MPL was not distributed with this
     13  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     14  *
     15  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
     16  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     17  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
     18  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     19  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     20  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
     21  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     22  *
     23  *   Internet Systems Consortium, Inc.
     24  *   950 Charter Street
     25  *   Redwood City, CA 94063
     26  *   <info (at) isc.org>
     27  *   https://www.isc.org/
     28  *
     29  */
     30 
     31 #include <sys/cdefs.h>
     32 __RCSID("$NetBSD: test.c,v 1.2.2.2 2018/04/16 01:59:48 pgoyette Exp $");
     33 
     34 #include "config.h"
     35 
     36 #include <time.h>
     37 #include <stdio.h>
     38 #include <stdlib.h>
     39 #include <stdarg.h>
     40 #include <string.h>
     41 #include <omapip/result.h>
     42 #include <sys/time.h>
     43 #include <omapip/omapip.h>
     44 #include <omapip/isclib.h>
     45 
     46 int main (int argc, char **argv)
     47 {
     48 	omapi_object_t *listener = (omapi_object_t*)0;
     49 	omapi_object_t *connection = (omapi_object_t*)0;
     50 	isc_result_t status;
     51 
     52 	status = dhcp_context_create(DHCP_CONTEXT_PRE_DB | DHCP_CONTEXT_POST_DB,
     53 				     NULL, NULL);
     54 	if (status != ISC_R_SUCCESS) {
     55 		fprintf(stderr, "Can't initialize context: %s\n",
     56 			isc_result_totext(status));
     57 		exit(1);
     58 	}
     59 
     60 	status = omapi_init ();
     61 	if (status != ISC_R_SUCCESS) {
     62 		fprintf(stderr, "omapi_init failed: %s\n",
     63 			isc_result_totext(status));
     64 		exit(1);
     65 	}
     66 
     67 	if (argc > 1 && !strcmp (argv [1], "listen")) {
     68 		if (argc < 3) {
     69 			fprintf (stderr, "Usage: test listen port\n");
     70 			exit (1);
     71 		}
     72 		status = omapi_generic_new (&listener, MDL);
     73 		if (status != ISC_R_SUCCESS) {
     74 			fprintf (stderr, "omapi_generic_new: %s\n",
     75 				 isc_result_totext (status));
     76 			exit (1);
     77 		}
     78 		status = omapi_protocol_listen (listener,
     79 						(unsigned)atoi (argv [2]), 1);
     80 		if (status != ISC_R_SUCCESS) {
     81 			fprintf (stderr, "omapi_listen: %s\n",
     82 				 isc_result_totext (status));
     83 			exit (1);
     84 		}
     85 		omapi_dispatch (0);
     86 	} else if (argc > 1 && !strcmp (argv [1], "connect")) {
     87 		if (argc < 4) {
     88 			fprintf (stderr, "Usage: test listen address port\n");
     89 			exit (1);
     90 		}
     91 		status = omapi_generic_new (&connection, MDL);
     92 		if (status != ISC_R_SUCCESS) {
     93 			fprintf (stderr, "omapi_generic_new: %s\n",
     94 				 isc_result_totext (status));
     95 			exit (1);
     96 		}
     97 		status = omapi_protocol_connect (connection,
     98 						 argv [2],
     99 						 (unsigned)atoi (argv [3]), 0);
    100 		fprintf (stderr, "connect: %s\n", isc_result_totext (status));
    101 		if (status != ISC_R_SUCCESS)
    102 			exit (1);
    103 		status = omapi_wait_for_completion (connection, 0);
    104 		fprintf (stderr, "completion: %s\n",
    105 			 isc_result_totext (status));
    106 		if (status != ISC_R_SUCCESS)
    107 			exit (1);
    108 		/* ... */
    109 	} else {
    110 		fprintf (stderr, "Usage: test [listen | connect] ...\n");
    111 		exit (1);
    112 	}
    113 
    114 	return 0;
    115 }
    116