omapip/test.c

Go to the documentation of this file.
00001 /* test.c
00002 
00003    Test code for omapip... */
00004 
00005 /*
00006  * Copyright (c) 2009-2010,2013-2014 by Internet Systems Consortium, Inc. ("ISC")
00007  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
00008  * Copyright (c) 1999-2003 by Internet Software Consortium
00009  *
00010  * Permission to use, copy, modify, and distribute this software for any
00011  * purpose with or without fee is hereby granted, provided that the above
00012  * copyright notice and this permission notice appear in all copies.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
00015  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00016  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
00017  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00018  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00019  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
00020  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00021  *
00022  *   Internet Systems Consortium, Inc.
00023  *   950 Charter Street
00024  *   Redwood City, CA 94063
00025  *   <info@isc.org>
00026  *   https://www.isc.org/
00027  *
00028  */
00029 
00030 #include "config.h"
00031 
00032 #include <time.h>
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035 #include <stdarg.h>
00036 #include <string.h>
00037 #include <omapip/result.h>
00038 #include <sys/time.h>
00039 #include <omapip/omapip.h>
00040 #include <omapip/isclib.h>
00041 
00042 int main (int argc, char **argv)
00043 {
00044         omapi_object_t *listener = (omapi_object_t*)0;
00045         omapi_object_t *connection = (omapi_object_t*)0;
00046         isc_result_t status;
00047 
00048         status = dhcp_context_create(DHCP_CONTEXT_PRE_DB | DHCP_CONTEXT_POST_DB,
00049                                      NULL, NULL);
00050         if (status != ISC_R_SUCCESS) {
00051                 fprintf(stderr, "Can't initialize context: %s\n",
00052                         isc_result_totext(status));
00053                 exit(1);
00054         }
00055 
00056         omapi_init ();
00057 
00058         if (argc > 1 && !strcmp (argv [1], "listen")) {
00059                 if (argc < 3) {
00060                         fprintf (stderr, "Usage: test listen port\n");
00061                         exit (1);
00062                 }
00063                 status = omapi_generic_new (&listener, MDL);
00064                 if (status != ISC_R_SUCCESS) {
00065                         fprintf (stderr, "omapi_generic_new: %s\n",
00066                                  isc_result_totext (status));
00067                         exit (1);
00068                 }
00069                 status = omapi_protocol_listen (listener,
00070                                                 (unsigned)atoi (argv [2]), 1);
00071                 if (status != ISC_R_SUCCESS) {
00072                         fprintf (stderr, "omapi_listen: %s\n",
00073                                  isc_result_totext (status));
00074                         exit (1);
00075                 }
00076                 omapi_dispatch (0);
00077         } else if (argc > 1 && !strcmp (argv [1], "connect")) {
00078                 if (argc < 4) {
00079                         fprintf (stderr, "Usage: test listen address port\n");
00080                         exit (1);
00081                 }
00082                 status = omapi_generic_new (&connection, MDL);
00083                 if (status != ISC_R_SUCCESS) {
00084                         fprintf (stderr, "omapi_generic_new: %s\n",
00085                                  isc_result_totext (status));
00086                         exit (1);
00087                 }
00088                 status = omapi_protocol_connect (connection,
00089                                                  argv [2],
00090                                                  (unsigned)atoi (argv [3]), 0);
00091                 fprintf (stderr, "connect: %s\n", isc_result_totext (status));
00092                 if (status != ISC_R_SUCCESS)
00093                         exit (1);
00094                 status = omapi_wait_for_completion (connection, 0);
00095                 fprintf (stderr, "completion: %s\n",
00096                          isc_result_totext (status));
00097                 if (status != ISC_R_SUCCESS)
00098                         exit (1);
00099                 /* ... */
00100         } else {
00101                 fprintf (stderr, "Usage: test [listen | connect] ...\n");
00102                 exit (1);
00103         }
00104 
00105         return 0;
00106 }

Generated on 5 Apr 2014 for ISC DHCP by  doxygen 1.6.1