]> git.ipfire.org Git - thirdparty/dhcp.git/blame - omapip/test.c
[master] ATF usage and documentation cleaned up
[thirdparty/dhcp.git] / omapip / test.c
CommitLineData
61b844bf
TL
1/* test.c
2
3 Test code for omapip... */
4
5/*
edad9be5 6 * Copyright (c) 2009-2010,2013-2014 by Internet Systems Consortium, Inc. ("ISC")
d122accf 7 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
98311e4b 8 * Copyright (c) 1999-2003 by Internet Software Consortium
61b844bf 9 *
98311e4b
DH
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.
61b844bf 13 *
98311e4b
DH
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.
61b844bf 21 *
98311e4b
DH
22 * Internet Systems Consortium, Inc.
23 * 950 Charter Street
24 * Redwood City, CA 94063
25 * <info@isc.org>
2c85ac9b 26 * https://www.isc.org/
49733f31 27 *
61b844bf
TL
28 */
29
d1f31a00
FD
30#include "config.h"
31
6a4c4be8
TL
32#include <time.h>
33#include <stdio.h>
34#include <stdlib.h>
35#include <stdarg.h>
98311e4b 36#include <string.h>
98bf1607 37#include <omapip/result.h>
165bce70 38#include <sys/time.h>
61b844bf 39#include <omapip/omapip.h>
98bf1607 40#include <omapip/isclib.h>
61b844bf
TL
41
42int main (int argc, char **argv)
43{
06b1a136
TL
44 omapi_object_t *listener = (omapi_object_t*)0;
45 omapi_object_t *connection = (omapi_object_t*)0;
61b844bf
TL
46 isc_result_t status;
47
61ef216b
SR
48 status = dhcp_context_create(DHCP_CONTEXT_PRE_DB | DHCP_CONTEXT_POST_DB,
49 NULL, NULL);
d122accf
SR
50 if (status != ISC_R_SUCCESS) {
51 fprintf(stderr, "Can't initialize context: %s\n",
52 isc_result_totext(status));
53 exit(1);
54 }
98bf1607 55
a07d99bb
TM
56 status = omapi_init ();
57 if (status != ISC_R_SUCCESS) {
58 fprintf(stderr, "omapi_init failed: %s\n",
59 isc_result_totext(status));
60 exit(1);
61 }
61b844bf
TL
62
63 if (argc > 1 && !strcmp (argv [1], "listen")) {
64 if (argc < 3) {
65 fprintf (stderr, "Usage: test listen port\n");
66 exit (1);
67 }
4bd8800e 68 status = omapi_generic_new (&listener, MDL);
61b844bf
TL
69 if (status != ISC_R_SUCCESS) {
70 fprintf (stderr, "omapi_generic_new: %s\n",
71 isc_result_totext (status));
72 exit (1);
73 }
74 status = omapi_protocol_listen (listener,
d0a33113 75 (unsigned)atoi (argv [2]), 1);
61b844bf
TL
76 if (status != ISC_R_SUCCESS) {
77 fprintf (stderr, "omapi_listen: %s\n",
78 isc_result_totext (status));
79 exit (1);
80 }
81 omapi_dispatch (0);
82 } else if (argc > 1 && !strcmp (argv [1], "connect")) {
83 if (argc < 4) {
84 fprintf (stderr, "Usage: test listen address port\n");
85 exit (1);
86 }
4bd8800e 87 status = omapi_generic_new (&connection, MDL);
61b844bf
TL
88 if (status != ISC_R_SUCCESS) {
89 fprintf (stderr, "omapi_generic_new: %s\n",
90 isc_result_totext (status));
91 exit (1);
92 }
93 status = omapi_protocol_connect (connection,
d0a33113
TL
94 argv [2],
95 (unsigned)atoi (argv [3]), 0);
61b844bf
TL
96 fprintf (stderr, "connect: %s\n", isc_result_totext (status));
97 if (status != ISC_R_SUCCESS)
98 exit (1);
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)
103 exit (1);
104 /* ... */
105 } else {
106 fprintf (stderr, "Usage: test [listen | connect] ...\n");
107 exit (1);
108 }
109
110 return 0;
111}