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