]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Add test program for dhcpctl
authorTed Lemon <source@isc.org>
Wed, 8 Sep 1999 01:46:14 +0000 (01:46 +0000)
committerTed Lemon <source@isc.org>
Wed, 8 Sep 1999 01:46:14 +0000 (01:46 +0000)
dhcpctl/Makefile.dist
dhcpctl/test.c [new file with mode: 0644]

index a614b43bffd9726c880cd97f6427f2a4858b9849..bef58a62772b861db7717c02a61b5230e557ece0 100644 (file)
@@ -27,10 +27,10 @@ DEBUG  = -g
 INCLUDES = $(BINDINC) -I../includes
 CFLAGS = $(DEBUG) $(PREDEFINES) $(INCLUDES) $(COPTS)
 
-all:   libdhcpctl.a $(CATMANPAGES)
+all:   libdhcpctl.a test $(CATMANPAGES)
 
-test:  test.o libdhcpctl.a
-       $(CC) $(DEBUG) -o test test.o libdhcpctl.a
+test:  test.o libdhcpctl.a ../omapip/libomapi.a
+       $(CC) $(DEBUG) -o test test.o libdhcpctl.a ../omapip/libomapi.a
 
 libdhcpctl.a:  $(OBJ)
        rm -f libdhcpctl.a
diff --git a/dhcpctl/test.c b/dhcpctl/test.c
new file mode 100644 (file)
index 0000000..6bde461
--- /dev/null
@@ -0,0 +1,110 @@
+/* test.c
+
+   Example program that uses the dhcpctl library. */
+
+/*
+ * Copyright (c) 1996-1999 Internet Software Consortium.
+ * Use is subject to license terms which appear in the file named
+ * ISC-LICENSE that should have accompanied this file when you
+ * received it.   If a file named ISC-LICENSE did not accompany this
+ * file, or you are not sure the one you have is correct, you may
+ * obtain an applicable copy of the license at:
+ *
+ *             http://www.isc.org/isc-license-1.0.html. 
+ *
+ * This file is part of the ISC DHCP distribution.   The documentation
+ * associated with this file is listed in the file DOCUMENTATION,
+ * included in the top-level directory of this release.
+ *
+ * Support and other services are available for ISC products - see
+ * http://www.isc.org for more information.
+ */
+
+#include "dhcpctl.h"
+
+int main (int, char **);
+
+int main (argc, argv)
+       int argc;
+       char **argv;
+{
+       isc_result_t status, waitstatus;
+       dhcpctl_handle connection;
+       dhcpctl_handle host_handle;
+       dhcpctl_data_string cid;
+
+       status = dhcpctl_initialize ();
+       if (status != ISC_R_SUCCESS) {
+               fprintf (stderr, "dhcpctl_initialize: %s\n",
+                        isc_result_totext (status));
+               exit (1);
+       }
+
+       memset (&connection, 0, sizeof connection);
+       status = dhcpctl_connect (&connection, "127.0.0.1", 7911,
+                                 (dhcpctl_handle)0);
+       if (status != ISC_R_SUCCESS) {
+               fprintf (stderr, "dhcpctl_connect: %s\n",
+                        isc_result_totext (status));
+               exit (1);
+       }
+
+       memset (&host_handle, 0, sizeof host_handle);
+       status = dhcpctl_new_object (&host_handle, connection, "host");
+       if (status != ISC_R_SUCCESS) {
+               fprintf (stderr, "dhcpctl_new_object: %s\n",
+                        isc_result_totext (status));
+               exit (1);
+       }
+
+       memset (&cid, 0, sizeof cid);
+       status = omapi_data_string_new (&cid, 7, "main");
+       if (status != ISC_R_SUCCESS) {
+               fprintf (stderr, "omapi_data_string_new: %s\n",
+                        isc_result_totext (status));
+               exit (1);
+       }
+
+       cid -> value [0] = 1; cid -> value [1] = 8;
+       cid -> value [2] = 0; cid -> value [3] = 0x2b;
+       cid -> value [4] = 0x34; cid -> value [5] = 0x1a;
+       cid -> value [6] = 0xc3;
+
+       status = dhcpctl_set_value (host_handle, cid,
+                                   "dhcp-client-identifier");
+       if (status != ISC_R_SUCCESS) {
+               fprintf (stderr, "dhcpctl_set_value: %s\n",
+                        isc_result_totext (status));
+               exit (1);
+       }
+
+       /* Set the known flag to 1. */
+       status = dhcpctl_set_boolean_value (host_handle, 1, "known");
+       if (status != ISC_R_SUCCESS) {
+               fprintf (stderr, "dhcpctl_set_boolean_value: %s\n",
+                        isc_result_totext (status));
+               exit (1);
+       }
+
+       status = dhcpctl_open_object (host_handle, connection,
+                                     DHCPCTL_CREATE | DHCPCTL_EXCL);
+       if (status != ISC_R_SUCCESS) {
+               fprintf (stderr, "dhcpctl_open_object: %s\n",
+                        isc_result_totext (status));
+               exit (1);
+       }
+
+       status = dhcpctl_wait_for_completion (host_handle, &waitstatus);
+       if (status != ISC_R_SUCCESS) {
+               fprintf (stderr, "dhcpctl_wait_for_completion: %s\n",
+                        isc_result_totext (status));
+               exit (1);
+       }
+
+       if (waitstatus != ISC_R_SUCCESS) {
+               fprintf (stderr, "dhcpctl_wait_for_completion: %s\n",
+                        isc_result_totext (waitstatus));
+               exit (1);
+       }
+       exit (0);
+}