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