]>
Commit | Line | Data |
---|---|---|
61b844bf TL |
1 | /* test.c |
2 | ||
3 | Test code for omapip... */ | |
4 | ||
5 | /* | |
98311e4b DH |
6 | * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") |
7 | * Copyright (c) 1999-2003 by Internet Software Consortium | |
61b844bf | 8 | * |
98311e4b DH |
9 | * Permission to use, copy, modify, and distribute this software for any |
10 | * purpose with or without fee is hereby granted, provided that the above | |
11 | * copyright notice and this permission notice appear in all copies. | |
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> | |
25 | * http://www.isc.org/ | |
49733f31 | 26 | * |
98311e4b | 27 | * This software has been written for Internet Systems Consortium |
49733f31 | 28 | * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc. |
98311e4b | 29 | * To learn more about Internet Systems Consortium, see |
49733f31 TL |
30 | * ``http://www.isc.org/''. To learn more about Vixie Enterprises, |
31 | * see ``http://www.vix.com''. To learn more about Nominum, Inc., see | |
32 | * ``http://www.nominum.com''. | |
61b844bf TL |
33 | */ |
34 | ||
6a4c4be8 TL |
35 | #include <time.h> |
36 | #include <stdio.h> | |
37 | #include <stdlib.h> | |
38 | #include <stdarg.h> | |
98311e4b | 39 | #include <string.h> |
d758ad8c | 40 | #include <isc-dhcp/result.h> |
165bce70 | 41 | #include <sys/time.h> |
61b844bf TL |
42 | #include <omapip/omapip.h> |
43 | ||
44 | int main (int argc, char **argv) | |
45 | { | |
06b1a136 TL |
46 | omapi_object_t *listener = (omapi_object_t*)0; |
47 | omapi_object_t *connection = (omapi_object_t*)0; | |
61b844bf TL |
48 | isc_result_t status; |
49 | ||
50 | omapi_init (); | |
51 | ||
52 | if (argc > 1 && !strcmp (argv [1], "listen")) { | |
53 | if (argc < 3) { | |
54 | fprintf (stderr, "Usage: test listen port\n"); | |
55 | exit (1); | |
56 | } | |
4bd8800e | 57 | status = omapi_generic_new (&listener, MDL); |
61b844bf TL |
58 | if (status != ISC_R_SUCCESS) { |
59 | fprintf (stderr, "omapi_generic_new: %s\n", | |
60 | isc_result_totext (status)); | |
61 | exit (1); | |
62 | } | |
63 | status = omapi_protocol_listen (listener, | |
d0a33113 | 64 | (unsigned)atoi (argv [2]), 1); |
61b844bf TL |
65 | if (status != ISC_R_SUCCESS) { |
66 | fprintf (stderr, "omapi_listen: %s\n", | |
67 | isc_result_totext (status)); | |
68 | exit (1); | |
69 | } | |
70 | omapi_dispatch (0); | |
71 | } else if (argc > 1 && !strcmp (argv [1], "connect")) { | |
72 | if (argc < 4) { | |
73 | fprintf (stderr, "Usage: test listen address port\n"); | |
74 | exit (1); | |
75 | } | |
4bd8800e | 76 | status = omapi_generic_new (&connection, MDL); |
61b844bf TL |
77 | if (status != ISC_R_SUCCESS) { |
78 | fprintf (stderr, "omapi_generic_new: %s\n", | |
79 | isc_result_totext (status)); | |
80 | exit (1); | |
81 | } | |
82 | status = omapi_protocol_connect (connection, | |
d0a33113 TL |
83 | argv [2], |
84 | (unsigned)atoi (argv [3]), 0); | |
61b844bf TL |
85 | fprintf (stderr, "connect: %s\n", isc_result_totext (status)); |
86 | if (status != ISC_R_SUCCESS) | |
87 | exit (1); | |
88 | status = omapi_wait_for_completion (connection, 0); | |
89 | fprintf (stderr, "completion: %s\n", | |
90 | isc_result_totext (status)); | |
91 | if (status != ISC_R_SUCCESS) | |
92 | exit (1); | |
93 | /* ... */ | |
94 | } else { | |
95 | fprintf (stderr, "Usage: test [listen | connect] ...\n"); | |
96 | exit (1); | |
97 | } | |
98 | ||
99 | return 0; | |
100 | } |