]>
git.ipfire.org Git - thirdparty/dhcp.git/blob - omapip/test.c
3 Test code for omapip... */
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
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.
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.
22 * Internet Systems Consortium, Inc.
24 * Redwood City, CA 94063
26 * https://www.isc.org/
37 #include <omapip/result.h>
39 #include <omapip/omapip.h>
40 #include <omapip/isclib.h>
42 int main (int argc
, char **argv
)
44 omapi_object_t
*listener
= (omapi_object_t
*)0;
45 omapi_object_t
*connection
= (omapi_object_t
*)0;
48 status
= dhcp_context_create(DHCP_CONTEXT_PRE_DB
| DHCP_CONTEXT_POST_DB
,
50 if (status
!= ISC_R_SUCCESS
) {
51 fprintf(stderr
, "Can't initialize context: %s\n",
52 isc_result_totext(status
));
56 status
= omapi_init ();
57 if (status
!= ISC_R_SUCCESS
) {
58 fprintf(stderr
, "omapi_init failed: %s\n",
59 isc_result_totext(status
));
63 if (argc
> 1 && !strcmp (argv
[1], "listen")) {
65 fprintf (stderr
, "Usage: test listen port\n");
68 status
= omapi_generic_new (&listener
, MDL
);
69 if (status
!= ISC_R_SUCCESS
) {
70 fprintf (stderr
, "omapi_generic_new: %s\n",
71 isc_result_totext (status
));
74 status
= omapi_protocol_listen (listener
,
75 (unsigned)atoi (argv
[2]), 1);
76 if (status
!= ISC_R_SUCCESS
) {
77 fprintf (stderr
, "omapi_listen: %s\n",
78 isc_result_totext (status
));
82 } else if (argc
> 1 && !strcmp (argv
[1], "connect")) {
84 fprintf (stderr
, "Usage: test listen address port\n");
87 status
= omapi_generic_new (&connection
, MDL
);
88 if (status
!= ISC_R_SUCCESS
) {
89 fprintf (stderr
, "omapi_generic_new: %s\n",
90 isc_result_totext (status
));
93 status
= omapi_protocol_connect (connection
,
95 (unsigned)atoi (argv
[3]), 0);
96 fprintf (stderr
, "connect: %s\n", isc_result_totext (status
));
97 if (status
!= ISC_R_SUCCESS
)
99 status
= omapi_wait_for_completion (connection
, 0);
100 fprintf (stderr
, "completion: %s\n",
101 isc_result_totext (status
));
102 if (status
!= ISC_R_SUCCESS
)
106 fprintf (stderr
, "Usage: test [listen | connect] ...\n");