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