]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
- Give example of creating a group, stuffing statements into it, and
authorTed Lemon <source@isc.org>
Fri, 1 Oct 1999 03:19:47 +0000 (03:19 +0000)
committerTed Lemon <source@isc.org>
Fri, 1 Oct 1999 03:19:47 +0000 (03:19 +0000)
  hanging it off of a host declaration.

dhcpctl/test.c

index 00a5891ade57d9b3913b87274005a23f43e94096..56f420515bdf0aa1b15d1af92200f85972430a43 100644 (file)
@@ -30,9 +30,9 @@ int main (argc, argv)
 {
        isc_result_t status, waitstatus;
        dhcpctl_handle connection;
-       dhcpctl_handle host_handle;
+       dhcpctl_handle host_handle, group_handle;
        dhcpctl_data_string cid, ip_addr;
-       dhcpctl_data_string result;
+       dhcpctl_data_string result, groupname;
 
        status = dhcpctl_initialize ();
        if (status != ISC_R_SUCCESS) {
@@ -50,6 +50,56 @@ int main (argc, argv)
                exit (1);
        }
 
+       /* Create a named group that contains the values we want to assign
+          to the host. */
+       memset (&group_handle, 0, sizeof group_handle);
+       status = dhcpctl_new_object (&group_handle, connection, "group");
+       if (status != ISC_R_SUCCESS) {
+               fprintf (stderr, "dhcpctl_new_object: %s\n",
+                        isc_result_totext (status));
+               exit (1);
+       }
+
+       status = dhcpctl_set_string_value (group_handle, "
+option domain-name \"foo.org\";
+option domain-name-servers 10.0.0.1, 10.0.0.2;",
+                                          "statements");
+       if (status != ISC_R_SUCCESS) {
+               fprintf (stderr, "dhcpctl_set_value: %s\n",
+                        isc_result_totext (status));
+               exit (1);
+       }
+
+       status = dhcpctl_open_object (group_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 (group_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, "group object create: %s\n",
+                        isc_result_totext (waitstatus));
+               exit (1);
+       }
+
+       memset (&groupname, 0, sizeof groupname);
+       status = dhcpctl_get_value (&groupname, group_handle, "name");
+       if (status != ISC_R_SUCCESS) {
+               fprintf (stderr, "dhcpctl_get_value: %s\n",
+                        isc_result_totext (status));
+               exit (1);
+       }
+
+       printf ("group name = %*s\n", groupname -> len, groupname -> value);
+
        memset (&host_handle, 0, sizeof host_handle);
        status = dhcpctl_new_object (&host_handle, connection, "host");
        if (status != ISC_R_SUCCESS) {
@@ -58,7 +108,7 @@ int main (argc, argv)
                exit (1);
        }
 
-#if 0
+#if 1
        memset (&cid, 0, sizeof cid);
        status = omapi_data_string_new (&cid, 6, "main");
        if (status != ISC_R_SUCCESS) {
@@ -70,8 +120,10 @@ int main (argc, argv)
        cid -> value [0] = 0; cid -> value [1] = 0x10;
        cid -> value [2] = 0x5a; cid -> value [3] = 0xf8;
        cid -> value [4] = 0x00; cid -> value [5] = 0xbb;
-#endif
 
+       status = dhcpctl_set_value (host_handle,
+                                   cid, "dhcp-client-identifier");
+#else
        status = dhcpctl_set_string_value (host_handle, "grosse",
                                           "dhcp-client-identifier");
        if (status != ISC_R_SUCCESS) {
@@ -79,14 +131,16 @@ int main (argc, argv)
                         isc_result_totext (status));
                exit (1);
        }
+#endif
 
-       status = dhcpctl_set_string_value (host_handle, "test", "group");
+       status = dhcpctl_set_value (host_handle, groupname, "group");
        if (status != ISC_R_SUCCESS) {
                fprintf (stderr, "dhcpctl_set_value: %s\n",
                         isc_result_totext (status));
                exit (1);
        }
 
+#if 0
        memset (&ip_addr, 0, sizeof ip_addr);
        status = omapi_data_string_new (&ip_addr, 4, "main");
        if (status != ISC_R_SUCCESS) {
@@ -104,6 +158,7 @@ int main (argc, argv)
                         isc_result_totext (status));
                exit (1);
        }
+#endif
 
        /* Set the known flag to 1. */
        status = dhcpctl_set_boolean_value (host_handle, 1, "known");