ISC DHCP  4.3.5
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) 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
9  *
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.
13  *
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.
21  *
22  * Internet Systems Consortium, Inc.
23  * 950 Charter Street
24  * Redwood City, CA 94063
25  * <info@isc.org>
26  * https://www.isc.org/
27  *
28  */
29 
30 #include "config.h"
31 
32 #include <time.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <stdarg.h>
36 #include <string.h>
37 #include <omapip/result.h>
38 #include <sys/time.h>
39 #include <omapip/omapip.h>
40 #include <omapip/isclib.h>
41 
42 int main (int argc, char **argv)
43 {
44  omapi_object_t *listener = (omapi_object_t*)0;
45  omapi_object_t *connection = (omapi_object_t*)0;
46  isc_result_t status;
47 
49  NULL, NULL);
50  if (status != ISC_R_SUCCESS) {
51  fprintf(stderr, "Can't initialize context: %s\n",
52  isc_result_totext(status));
53  exit(1);
54  }
55 
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  }
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  }
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));
72  exit (1);
73  }
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));
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  }
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));
91  exit (1);
92  }
93  status = omapi_protocol_connect (connection,
94  argv [2],
95  (unsigned)atoi (argv [3]), 0);
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 }
isc_result_t omapi_protocol_listen(omapi_object_t *, unsigned, int)
Definition: protocol.c:998
int main(int argc, char **argv)
Definition: test.c:42
#define MDL
Definition: omapip.h:568
isc_result_t omapi_dispatch(struct timeval *)
Definition: dispatch.c:415
#define DHCP_CONTEXT_PRE_DB
Definition: isclib.h:126
#define DHCP_CONTEXT_POST_DB
Definition: isclib.h:127
isc_result_t dhcp_context_create(int flags, struct in_addr *local4, struct in6_addr *local6)
Definition: isclib.c:138
isc_result_t omapi_generic_new(omapi_object_t **, const char *, int)
isc_result_t omapi_protocol_connect(omapi_object_t *, const char *, unsigned, omapi_object_t *)
isc_result_t omapi_wait_for_completion(omapi_object_t *, struct timeval *)
Definition: dispatch.c:421
isc_result_t omapi_init(void)
Definition: support.c:62