Annotation of embedaddon/dhcp/omapip/test.c, revision 1.1
1.1 ! misho 1: /* test.c
! 2:
! 3: Test code for omapip... */
! 4:
! 5: /*
! 6: * Copyright (c) 2009-2010 by Internet Systems Consortium, Inc. ("ISC")
! 7: * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
! 8: * Copyright (c) 1999-2003 by Internet Software Consortium
! 9: *
! 10: * Permission to use, copy, modify, and distribute this software for any
! 11: * purpose with or without fee is hereby granted, provided that the above
! 12: * copyright notice and this permission notice appear in all copies.
! 13: *
! 14: * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
! 15: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
! 16: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
! 17: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
! 18: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
! 19: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
! 20: * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
! 21: *
! 22: * Internet Systems Consortium, Inc.
! 23: * 950 Charter Street
! 24: * Redwood City, CA 94063
! 25: * <info@isc.org>
! 26: * https://www.isc.org/
! 27: *
! 28: * This software has been written for Internet Systems Consortium
! 29: * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
! 30: * To learn more about Internet Systems Consortium, see
! 31: * ``https://www.isc.org/''. To learn more about Vixie Enterprises,
! 32: * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
! 33: * ``http://www.nominum.com''.
! 34: */
! 35:
! 36: #include "config.h"
! 37:
! 38: #include <time.h>
! 39: #include <stdio.h>
! 40: #include <stdlib.h>
! 41: #include <stdarg.h>
! 42: #include <string.h>
! 43: #include <isc-dhcp/result.h>
! 44: #include <sys/time.h>
! 45: #include <omapip/omapip.h>
! 46:
! 47: int main (int argc, char **argv)
! 48: {
! 49: omapi_object_t *listener = (omapi_object_t*)0;
! 50: omapi_object_t *connection = (omapi_object_t*)0;
! 51: isc_result_t status;
! 52:
! 53: omapi_init ();
! 54:
! 55: if (argc > 1 && !strcmp (argv [1], "listen")) {
! 56: if (argc < 3) {
! 57: fprintf (stderr, "Usage: test listen port\n");
! 58: exit (1);
! 59: }
! 60: status = omapi_generic_new (&listener, MDL);
! 61: if (status != ISC_R_SUCCESS) {
! 62: fprintf (stderr, "omapi_generic_new: %s\n",
! 63: isc_result_totext (status));
! 64: exit (1);
! 65: }
! 66: status = omapi_protocol_listen (listener,
! 67: (unsigned)atoi (argv [2]), 1);
! 68: if (status != ISC_R_SUCCESS) {
! 69: fprintf (stderr, "omapi_listen: %s\n",
! 70: isc_result_totext (status));
! 71: exit (1);
! 72: }
! 73: omapi_dispatch (0);
! 74: } else if (argc > 1 && !strcmp (argv [1], "connect")) {
! 75: if (argc < 4) {
! 76: fprintf (stderr, "Usage: test listen address port\n");
! 77: exit (1);
! 78: }
! 79: status = omapi_generic_new (&connection, MDL);
! 80: if (status != ISC_R_SUCCESS) {
! 81: fprintf (stderr, "omapi_generic_new: %s\n",
! 82: isc_result_totext (status));
! 83: exit (1);
! 84: }
! 85: status = omapi_protocol_connect (connection,
! 86: argv [2],
! 87: (unsigned)atoi (argv [3]), 0);
! 88: fprintf (stderr, "connect: %s\n", isc_result_totext (status));
! 89: if (status != ISC_R_SUCCESS)
! 90: exit (1);
! 91: status = omapi_wait_for_completion (connection, 0);
! 92: fprintf (stderr, "completion: %s\n",
! 93: isc_result_totext (status));
! 94: if (status != ISC_R_SUCCESS)
! 95: exit (1);
! 96: /* ... */
! 97: } else {
! 98: fprintf (stderr, "Usage: test [listen | connect] ...\n");
! 99: exit (1);
! 100: }
! 101:
! 102: return 0;
! 103: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>