]> git.ipfire.org Git - thirdparty/dhcp.git/blob - omapip/test.c
f05896dbe165ed9dcbdc283c43c6f051db6a4a6d
[thirdparty/dhcp.git] / omapip / test.c
1 /* test.c
2
3 Test code for omapip... */
4
5 /*
6 * Copyright (c) 2009-2010,2013-2014 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 */
29
30 #include "config.h"
31
32 #include <time.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <stdarg.h>
36 #include <string.h>
37 #include <omapip/result.h>
38 #include <sys/time.h>
39 #include <omapip/omapip.h>
40 #include <omapip/isclib.h>
41
42 int main (int argc, char **argv)
43 {
44 omapi_object_t *listener = (omapi_object_t*)0;
45 omapi_object_t *connection = (omapi_object_t*)0;
46 isc_result_t status;
47
48 status = dhcp_context_create(DHCP_CONTEXT_PRE_DB | DHCP_CONTEXT_POST_DB,
49 NULL, NULL);
50 if (status != ISC_R_SUCCESS) {
51 fprintf(stderr, "Can't initialize context: %s\n",
52 isc_result_totext(status));
53 exit(1);
54 }
55
56 omapi_init ();
57
58 if (argc > 1 && !strcmp (argv [1], "listen")) {
59 if (argc < 3) {
60 fprintf (stderr, "Usage: test listen port\n");
61 exit (1);
62 }
63 status = omapi_generic_new (&listener, MDL);
64 if (status != ISC_R_SUCCESS) {
65 fprintf (stderr, "omapi_generic_new: %s\n",
66 isc_result_totext (status));
67 exit (1);
68 }
69 status = omapi_protocol_listen (listener,
70 (unsigned)atoi (argv [2]), 1);
71 if (status != ISC_R_SUCCESS) {
72 fprintf (stderr, "omapi_listen: %s\n",
73 isc_result_totext (status));
74 exit (1);
75 }
76 omapi_dispatch (0);
77 } else if (argc > 1 && !strcmp (argv [1], "connect")) {
78 if (argc < 4) {
79 fprintf (stderr, "Usage: test listen address port\n");
80 exit (1);
81 }
82 status = omapi_generic_new (&connection, MDL);
83 if (status != ISC_R_SUCCESS) {
84 fprintf (stderr, "omapi_generic_new: %s\n",
85 isc_result_totext (status));
86 exit (1);
87 }
88 status = omapi_protocol_connect (connection,
89 argv [2],
90 (unsigned)atoi (argv [3]), 0);
91 fprintf (stderr, "connect: %s\n", isc_result_totext (status));
92 if (status != ISC_R_SUCCESS)
93 exit (1);
94 status = omapi_wait_for_completion (connection, 0);
95 fprintf (stderr, "completion: %s\n",
96 isc_result_totext (status));
97 if (status != ISC_R_SUCCESS)
98 exit (1);
99 /* ... */
100 } else {
101 fprintf (stderr, "Usage: test [listen | connect] ...\n");
102 exit (1);
103 }
104
105 return 0;
106 }