00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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 }