ISC DHCP  4.4.3-P1
A reference DHCPv4 and DHCPv6 implementation
test.c
Go to the documentation of this file.
1 /* test.c
2 
3  Test code for omapip... */
4 
5 /*
6  * Copyright (C) 2004-2022 Internet Systems Consortium, Inc. ("ISC")
7  * Copyright (c) 1999-2003 by Internet Software Consortium
8  *
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/.
12  *
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.
20  *
21  * Internet Systems Consortium, Inc.
22  * PO Box 360
23  * Newmarket, NH 03857 USA
24  * <info@isc.org>
25  * https://www.isc.org/
26  *
27  */
28 
29 #include "config.h"
30 
31 #include <time.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <stdarg.h>
35 #include <string.h>
36 #include <omapip/result.h>
37 #include <sys/time.h>
38 #include <omapip/omapip.h>
39 #include <omapip/isclib.h>
40 
41 int main (int argc, char **argv)
42 {
43  omapi_object_t *listener = (omapi_object_t*)0;
44  omapi_object_t *connection = (omapi_object_t*)0;
45  isc_result_t status;
46 
48  NULL, NULL);
49  if (status != ISC_R_SUCCESS) {
50  fprintf(stderr, "Can't initialize context: %s\n",
51  isc_result_totext(status));
52  exit(1);
53  }
54 
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  }
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  }
67  status = omapi_generic_new (&listener, MDL);
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,
74  (unsigned)atoi (argv [2]), 1);
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  }
86  status = omapi_generic_new (&connection, MDL);
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,
93  argv [2],
94  (unsigned)atoi (argv [3]), 0);
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 }
isc_result_t dhcp_context_create(int flags, struct in_addr *local4, struct in6_addr *local6)
Definition: isclib.c:167
#define DHCP_CONTEXT_PRE_DB
Definition: isclib.h:134
#define DHCP_CONTEXT_POST_DB
Definition: isclib.h:135
#define ISC_R_SUCCESS
isc_result_t omapi_protocol_connect(omapi_object_t *, const char *, unsigned, omapi_object_t *)
#define MDL
Definition: omapip.h:567
isc_result_t omapi_generic_new(omapi_object_t **, const char *, int)
isc_result_t omapi_protocol_listen(omapi_object_t *, unsigned, int)
Definition: protocol.c:997
isc_result_t omapi_dispatch(struct timeval *)
Definition: dispatch.c:414
isc_result_t omapi_init(void)
Definition: support.c:61
isc_result_t omapi_wait_for_completion(omapi_object_t *, struct timeval *)
Definition: dispatch.c:424
int main(int argc, char **argv)
Definition: test.c:41