1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright (c) 2001 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate * All rights reserved.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <stdio.h>
30*0Sstevel@tonic-gate #include <stdlib.h>
31*0Sstevel@tonic-gate #include <alloca.h>
32*0Sstevel@tonic-gate #include <strings.h>
33*0Sstevel@tonic-gate #include <sys/types.h>
34*0Sstevel@tonic-gate #include <arpa/inet.h>
35*0Sstevel@tonic-gate #include <sys/socket.h>
36*0Sstevel@tonic-gate #include <fcntl.h>
37*0Sstevel@tonic-gate #include <errno.h>
38*0Sstevel@tonic-gate #include <dhcp_svc_confopt.h>
39*0Sstevel@tonic-gate #include <dhcp_svc_private.h>
40*0Sstevel@tonic-gate #include <dhcp_svc_public.h>
41*0Sstevel@tonic-gate #include <libinetutil.h>
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate /*
44*0Sstevel@tonic-gate * Argument: resource, and path in that resource.
45*0Sstevel@tonic-gate */
46*0Sstevel@tonic-gate int
main(int argc,char * argv[])47*0Sstevel@tonic-gate main(int argc, char *argv[])
48*0Sstevel@tonic-gate {
49*0Sstevel@tonic-gate int nmods, i, error;
50*0Sstevel@tonic-gate boolean_t dsp_valid = B_FALSE;
51*0Sstevel@tonic-gate char **mods, **listpp;
52*0Sstevel@tonic-gate uint32_t count;
53*0Sstevel@tonic-gate dsvc_datastore_t dsp;
54*0Sstevel@tonic-gate dsvc_handle_t handle;
55*0Sstevel@tonic-gate char cid[DN_MAX_CID_LEN * 2 + 1];
56*0Sstevel@tonic-gate uint_t cidlen;
57*0Sstevel@tonic-gate char cip[INET_ADDRSTRLEN], sip[INET_ADDRSTRLEN];
58*0Sstevel@tonic-gate uint32_t query;
59*0Sstevel@tonic-gate dt_rec_t dt, *dtp, *ntp;
60*0Sstevel@tonic-gate dt_rec_list_t *resdtp, *wtp;
61*0Sstevel@tonic-gate dn_rec_t dn, *dnp;
62*0Sstevel@tonic-gate dn_rec_list_t *resdnp, *wnp;
63*0Sstevel@tonic-gate
64*0Sstevel@tonic-gate if (argc != 3) {
65*0Sstevel@tonic-gate (void) fprintf(stderr, "Usage: %s <resource> <path>\n",
66*0Sstevel@tonic-gate argv[0]);
67*0Sstevel@tonic-gate return (1);
68*0Sstevel@tonic-gate }
69*0Sstevel@tonic-gate
70*0Sstevel@tonic-gate /* enumerate_dd() */
71*0Sstevel@tonic-gate (void) printf("enumerate_dd: ... ");
72*0Sstevel@tonic-gate error = enumerate_dd(&mods, &nmods);
73*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gate if (error != DSVC_SUCCESS)
76*0Sstevel@tonic-gate return (1);
77*0Sstevel@tonic-gate
78*0Sstevel@tonic-gate (void) printf("enumerate_dd: count of modules: %d\n", nmods);
79*0Sstevel@tonic-gate for (i = 0; i < nmods; i++) {
80*0Sstevel@tonic-gate (void) printf(" %d is: %s\n", i, mods[i]);
81*0Sstevel@tonic-gate if (strcmp(argv[1], mods[i]) == 0) {
82*0Sstevel@tonic-gate dsp.d_location = argv[2];
83*0Sstevel@tonic-gate dsp.d_resource = strdup(mods[i]);
84*0Sstevel@tonic-gate dsp.d_conver = DSVC_CUR_CONVER;
85*0Sstevel@tonic-gate dsp_valid = B_TRUE;
86*0Sstevel@tonic-gate }
87*0Sstevel@tonic-gate free(mods[i]);
88*0Sstevel@tonic-gate }
89*0Sstevel@tonic-gate free(mods);
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gate if (!dsp_valid) {
92*0Sstevel@tonic-gate (void) printf("%s: no module for resource `%s'\n", argv[0],
93*0Sstevel@tonic-gate argv[1]);
94*0Sstevel@tonic-gate return (1);
95*0Sstevel@tonic-gate }
96*0Sstevel@tonic-gate
97*0Sstevel@tonic-gate (void) printf("\nstarting testing on %s, tables @ %s\n",
98*0Sstevel@tonic-gate argv[1], argv[2]);
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate /*
101*0Sstevel@tonic-gate * Using the datastore struct we built from arguments, begin poking
102*0Sstevel@tonic-gate * at the user selected public module.
103*0Sstevel@tonic-gate */
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gate /* status_dd */
106*0Sstevel@tonic-gate (void) printf("status_dd: ... ");
107*0Sstevel@tonic-gate error = status_dd(&dsp);
108*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
109*0Sstevel@tonic-gate
110*0Sstevel@tonic-gate (void) printf("Datastore version is %d\n", dsp.d_conver);
111*0Sstevel@tonic-gate
112*0Sstevel@tonic-gate /* mklocation_dd */
113*0Sstevel@tonic-gate (void) printf("mklocation_dd of %s: ... ", dsp.d_location);
114*0Sstevel@tonic-gate error = mklocation_dd(&dsp);
115*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
116*0Sstevel@tonic-gate
117*0Sstevel@tonic-gate /* list_dd - dhcptab */
118*0Sstevel@tonic-gate (void) printf("\nlist_dd of dhcptab containers: ... ");
119*0Sstevel@tonic-gate error = list_dd(&dsp, DSVC_DHCPTAB, &listpp, &count);
120*0Sstevel@tonic-gate (void) printf(" %s\n", dhcpsvc_errmsg(error));
121*0Sstevel@tonic-gate if (error == DSVC_SUCCESS) {
122*0Sstevel@tonic-gate (void) printf(" %d dhcptab container(s): ", count);
123*0Sstevel@tonic-gate for (i = 0; i < count; i++) {
124*0Sstevel@tonic-gate (void) printf("%s ", listpp[i] != NULL ?
125*0Sstevel@tonic-gate listpp[i] : "NULL");
126*0Sstevel@tonic-gate free(listpp[i]);
127*0Sstevel@tonic-gate }
128*0Sstevel@tonic-gate (void) printf("\n");
129*0Sstevel@tonic-gate free(listpp);
130*0Sstevel@tonic-gate } else {
131*0Sstevel@tonic-gate (void) printf("list_dd: listpp: 0x%p, count: %d\n",
132*0Sstevel@tonic-gate (void *)listpp, count);
133*0Sstevel@tonic-gate }
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gate /* open_dd - dhcptab (create) */
136*0Sstevel@tonic-gate (void) printf("open_dd: dhcptab: ... ");
137*0Sstevel@tonic-gate error = open_dd(&handle, &dsp, DSVC_DHCPTAB, "dhcptab",
138*0Sstevel@tonic-gate DSVC_CREATE | DSVC_READ | DSVC_WRITE);
139*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
140*0Sstevel@tonic-gate if (error != DSVC_SUCCESS)
141*0Sstevel@tonic-gate return (1);
142*0Sstevel@tonic-gate
143*0Sstevel@tonic-gate /* add_dd_entry - dhcptab */
144*0Sstevel@tonic-gate {
145*0Sstevel@tonic-gate dt_rec_t recs[5];
146*0Sstevel@tonic-gate
147*0Sstevel@tonic-gate (void) strcpy(recs[0].dt_key, "172.21.0.0");
148*0Sstevel@tonic-gate recs[0].dt_type = DT_MACRO;
149*0Sstevel@tonic-gate recs[0].dt_value = ":Router=172.21.0.1:Subnet=255.255.0.0:";
150*0Sstevel@tonic-gate
151*0Sstevel@tonic-gate (void) strcpy(recs[1].dt_key, "172.20.64.0");
152*0Sstevel@tonic-gate recs[1].dt_type = DT_MACRO;
153*0Sstevel@tonic-gate recs[1].dt_value =
154*0Sstevel@tonic-gate ":Router=172.20.64.2:Subnet=255.255.255.192:";
155*0Sstevel@tonic-gate
156*0Sstevel@tonic-gate (void) strcpy(recs[2].dt_key, "172.20.64.64");
157*0Sstevel@tonic-gate recs[2].dt_type = DT_MACRO;
158*0Sstevel@tonic-gate recs[2].dt_value =
159*0Sstevel@tonic-gate ":Router=172.20.64.65:Subnet=255.255.255.192:";
160*0Sstevel@tonic-gate
161*0Sstevel@tonic-gate (void) strcpy(recs[3].dt_key, "172.20.64.128");
162*0Sstevel@tonic-gate recs[3].dt_type = DT_MACRO;
163*0Sstevel@tonic-gate recs[3].dt_value =
164*0Sstevel@tonic-gate ":Router=172.20.64.129:Subnet=255.255.255.128:";
165*0Sstevel@tonic-gate
166*0Sstevel@tonic-gate (void) strcpy(recs[4].dt_key, "172.22.0.0");
167*0Sstevel@tonic-gate recs[4].dt_type = DT_MACRO;
168*0Sstevel@tonic-gate recs[4].dt_value =
169*0Sstevel@tonic-gate ":Router=172.22.0.1:Subnet=255.255.0.0:MTU=4532:";
170*0Sstevel@tonic-gate
171*0Sstevel@tonic-gate (void) printf("add_dd_entry: ... key type value\n");
172*0Sstevel@tonic-gate for (i = 0; i < sizeof (recs) / sizeof (dt_rec_t); i++) {
173*0Sstevel@tonic-gate (void) printf(" %s %c %s ... ",
174*0Sstevel@tonic-gate recs[i].dt_key, recs[i].dt_type, recs[i].dt_value);
175*0Sstevel@tonic-gate error = add_dd_entry(handle, &recs[i]);
176*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
177*0Sstevel@tonic-gate if (error != DSVC_SUCCESS)
178*0Sstevel@tonic-gate break;
179*0Sstevel@tonic-gate }
180*0Sstevel@tonic-gate }
181*0Sstevel@tonic-gate
182*0Sstevel@tonic-gate /* lookup_dd - dhcptab - macro called '172.20.64.128', then delete it */
183*0Sstevel@tonic-gate
184*0Sstevel@tonic-gate DSVC_QINIT(query);
185*0Sstevel@tonic-gate DSVC_QEQ(query, DT_QKEY);
186*0Sstevel@tonic-gate DSVC_QEQ(query, DT_QTYPE);
187*0Sstevel@tonic-gate
188*0Sstevel@tonic-gate (void) memset(&dt, 0, sizeof (dt));
189*0Sstevel@tonic-gate (void) strcpy(dt.dt_key, "172.20.64.128");
190*0Sstevel@tonic-gate dt.dt_type = 'm';
191*0Sstevel@tonic-gate
192*0Sstevel@tonic-gate (void) printf("lookup_dd: macro %s ... ", dt.dt_key);
193*0Sstevel@tonic-gate error = lookup_dd(handle, B_FALSE, query, -1, &dt, (void **)&resdtp,
194*0Sstevel@tonic-gate &count);
195*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
196*0Sstevel@tonic-gate
197*0Sstevel@tonic-gate if (error == DSVC_SUCCESS) {
198*0Sstevel@tonic-gate if (count != 1) {
199*0Sstevel@tonic-gate (void) printf("lookup_dd: expected 1 record, got %d\n",
200*0Sstevel@tonic-gate count);
201*0Sstevel@tonic-gate }
202*0Sstevel@tonic-gate
203*0Sstevel@tonic-gate for (i = 0, wtp = resdtp; i < count && wtp != NULL; i++) {
204*0Sstevel@tonic-gate dtp = wtp->dtl_rec;
205*0Sstevel@tonic-gate (void) printf(" %s %c %s\n",
206*0Sstevel@tonic-gate dtp->dt_key, dtp->dt_type, dtp->dt_value);
207*0Sstevel@tonic-gate wtp = wtp->dtl_next;
208*0Sstevel@tonic-gate }
209*0Sstevel@tonic-gate free_dd_list(handle, resdtp);
210*0Sstevel@tonic-gate }
211*0Sstevel@tonic-gate
212*0Sstevel@tonic-gate /* Delete it */
213*0Sstevel@tonic-gate (void) printf("delete_dd_entry: %s ... ", dt.dt_key);
214*0Sstevel@tonic-gate error = delete_dd_entry(handle, &dt);
215*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
216*0Sstevel@tonic-gate
217*0Sstevel@tonic-gate
218*0Sstevel@tonic-gate /*
219*0Sstevel@tonic-gate * lookup_dd - dhcptab - macro called '172.21.0.0', and modify its
220*0Sstevel@tonic-gate * definition and replace the value.
221*0Sstevel@tonic-gate */
222*0Sstevel@tonic-gate
223*0Sstevel@tonic-gate DSVC_QINIT(query);
224*0Sstevel@tonic-gate DSVC_QEQ(query, DT_QKEY);
225*0Sstevel@tonic-gate
226*0Sstevel@tonic-gate (void) memset(&dt, 0, sizeof (dt));
227*0Sstevel@tonic-gate (void) strcpy(dt.dt_key, "172.21.0.0");
228*0Sstevel@tonic-gate
229*0Sstevel@tonic-gate (void) printf("lookup_dd: macro %s ... ", dt.dt_key);
230*0Sstevel@tonic-gate error = lookup_dd(handle, B_FALSE, query, 1, &dt, (void **)&resdtp,
231*0Sstevel@tonic-gate &count);
232*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
233*0Sstevel@tonic-gate
234*0Sstevel@tonic-gate if (error == DSVC_SUCCESS) {
235*0Sstevel@tonic-gate if (count != 1) {
236*0Sstevel@tonic-gate (void) printf("lookup_dd: expected 1 record, "
237*0Sstevel@tonic-gate "got %d\n", count);
238*0Sstevel@tonic-gate } else {
239*0Sstevel@tonic-gate dtp = resdtp->dtl_rec;
240*0Sstevel@tonic-gate (void) printf(" %s %c %s\n", dtp->dt_key,
241*0Sstevel@tonic-gate dtp->dt_type, dtp->dt_value);
242*0Sstevel@tonic-gate
243*0Sstevel@tonic-gate ntp = alloc_dtrec(dtp->dt_key, dtp->dt_type,
244*0Sstevel@tonic-gate ":Subnet=255.255.0.0:Router=172.21.0.1 "
245*0Sstevel@tonic-gate "172.21.0.2:MTU=1500:");
246*0Sstevel@tonic-gate if (ntp != NULL) {
247*0Sstevel@tonic-gate ntp->dt_sig = dtp->dt_sig;
248*0Sstevel@tonic-gate
249*0Sstevel@tonic-gate /* Modify it */
250*0Sstevel@tonic-gate (void) printf("modify_dd_entry: macro %s ... ",
251*0Sstevel@tonic-gate dt.dt_key);
252*0Sstevel@tonic-gate error = modify_dd_entry(handle, dtp, ntp);
253*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
254*0Sstevel@tonic-gate free_dd(handle, ntp);
255*0Sstevel@tonic-gate }
256*0Sstevel@tonic-gate }
257*0Sstevel@tonic-gate free_dd_list(handle, resdtp);
258*0Sstevel@tonic-gate }
259*0Sstevel@tonic-gate
260*0Sstevel@tonic-gate /* lookup_dd - all records */
261*0Sstevel@tonic-gate
262*0Sstevel@tonic-gate DSVC_QINIT(query);
263*0Sstevel@tonic-gate
264*0Sstevel@tonic-gate (void) printf("lookup_dd: all records ... ");
265*0Sstevel@tonic-gate error = lookup_dd(handle, B_FALSE, query, -1, &dt, (void **)&resdtp,
266*0Sstevel@tonic-gate &count);
267*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
268*0Sstevel@tonic-gate if (error == DSVC_SUCCESS) {
269*0Sstevel@tonic-gate for (i = 0, wtp = resdtp; i < count && wtp != NULL; i++) {
270*0Sstevel@tonic-gate dtp = wtp->dtl_rec;
271*0Sstevel@tonic-gate (void) printf(" %s %c %s\n", dtp->dt_key,
272*0Sstevel@tonic-gate dtp->dt_type, dtp->dt_value);
273*0Sstevel@tonic-gate wtp = wtp->dtl_next;
274*0Sstevel@tonic-gate }
275*0Sstevel@tonic-gate free_dd_list(handle, resdtp);
276*0Sstevel@tonic-gate }
277*0Sstevel@tonic-gate
278*0Sstevel@tonic-gate /* close_dd - dhcptab */
279*0Sstevel@tonic-gate (void) printf("close_dd: dhcptab ... ");
280*0Sstevel@tonic-gate error = close_dd(&handle);
281*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
282*0Sstevel@tonic-gate
283*0Sstevel@tonic-gate /* list_dd - dhcp network containers */
284*0Sstevel@tonic-gate (void) printf("list_dd: dhcptab ... ");
285*0Sstevel@tonic-gate error = list_dd(&dsp, DSVC_DHCPTAB, &listpp, &count);
286*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
287*0Sstevel@tonic-gate if (error == DSVC_SUCCESS) {
288*0Sstevel@tonic-gate (void) printf(" %d dhcp network container(s): ", count);
289*0Sstevel@tonic-gate for (i = 0; i < count; i++) {
290*0Sstevel@tonic-gate (void) printf("%s ", listpp[i] != NULL ?
291*0Sstevel@tonic-gate listpp[i] : "NULL");
292*0Sstevel@tonic-gate free(listpp[i]);
293*0Sstevel@tonic-gate }
294*0Sstevel@tonic-gate free(listpp);
295*0Sstevel@tonic-gate (void) printf("\n");
296*0Sstevel@tonic-gate } else {
297*0Sstevel@tonic-gate (void) printf("list_dd: listpp: 0x%p, count: %d\n",
298*0Sstevel@tonic-gate (void *)listpp, count);
299*0Sstevel@tonic-gate }
300*0Sstevel@tonic-gate
301*0Sstevel@tonic-gate /* remove_dd - dhcptab */
302*0Sstevel@tonic-gate (void) printf("remove_dd: dhcptab ... ");
303*0Sstevel@tonic-gate error = remove_dd(&dsp, DSVC_DHCPTAB, NULL);
304*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
305*0Sstevel@tonic-gate
306*0Sstevel@tonic-gate /* open_dd - 129.148.5.0 create */
307*0Sstevel@tonic-gate (void) printf("\nopen_dd: 129.148.5.0: ... ");
308*0Sstevel@tonic-gate error = open_dd(&handle, &dsp, DSVC_DHCPNETWORK, "129.148.5.0",
309*0Sstevel@tonic-gate DSVC_CREATE | DSVC_READ | DSVC_WRITE);
310*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
311*0Sstevel@tonic-gate if (error != DSVC_SUCCESS)
312*0Sstevel@tonic-gate return (1);
313*0Sstevel@tonic-gate
314*0Sstevel@tonic-gate /* add_dd_entry - 129.148.5.0 */
315*0Sstevel@tonic-gate {
316*0Sstevel@tonic-gate uchar_t cid0[7] = { 0x01, 0x08, 0x00, 0x20, 0x00, 0x00, 0x01 };
317*0Sstevel@tonic-gate dn_rec_t recs[5] = { 0 };
318*0Sstevel@tonic-gate
319*0Sstevel@tonic-gate recs[0].dn_cid_len = sizeof (cid0);
320*0Sstevel@tonic-gate recs[0].dn_flags = 2;
321*0Sstevel@tonic-gate recs[0].dn_cip.s_addr = 0x81940502;
322*0Sstevel@tonic-gate recs[0].dn_sip.s_addr = 0x81940501;
323*0Sstevel@tonic-gate (void) memcpy(recs[0].dn_cid, cid0, sizeof (cid0));
324*0Sstevel@tonic-gate (void) strlcpy(recs[0].dn_macro, "myserv", DSVC_MAX_MACSYM_LEN);
325*0Sstevel@tonic-gate (void) strlcpy(recs[0].dn_comment, "dave", DN_MAX_COMMENT_LEN);
326*0Sstevel@tonic-gate
327*0Sstevel@tonic-gate recs[1].dn_cid_len = 1;
328*0Sstevel@tonic-gate recs[1].dn_flags = 1;
329*0Sstevel@tonic-gate recs[1].dn_cip.s_addr = 0x81940503;
330*0Sstevel@tonic-gate recs[1].dn_sip.s_addr = 0x81940501;
331*0Sstevel@tonic-gate (void) strlcpy(recs[1].dn_macro, "myserv", DSVC_MAX_MACSYM_LEN);
332*0Sstevel@tonic-gate (void) strlcpy(recs[1].dn_comment, "meem", DN_MAX_COMMENT_LEN);
333*0Sstevel@tonic-gate
334*0Sstevel@tonic-gate recs[2].dn_cid_len = 1;
335*0Sstevel@tonic-gate recs[2].dn_cip.s_addr = 0x81940504;
336*0Sstevel@tonic-gate recs[2].dn_sip.s_addr = 0x81940501;
337*0Sstevel@tonic-gate (void) strlcpy(recs[2].dn_macro, "myserv", DSVC_MAX_MACSYM_LEN);
338*0Sstevel@tonic-gate (void) strlcpy(recs[2].dn_comment, "cpj", DN_MAX_COMMENT_LEN);
339*0Sstevel@tonic-gate
340*0Sstevel@tonic-gate recs[3].dn_cid_len = 1;
341*0Sstevel@tonic-gate recs[3].dn_cip.s_addr = 0x81940505;
342*0Sstevel@tonic-gate recs[3].dn_sip.s_addr = 0x81940501;
343*0Sstevel@tonic-gate (void) strlcpy(recs[3].dn_macro, "myserv", DSVC_MAX_MACSYM_LEN);
344*0Sstevel@tonic-gate (void) strlcpy(recs[3].dn_comment, "mwc", DN_MAX_COMMENT_LEN);
345*0Sstevel@tonic-gate
346*0Sstevel@tonic-gate recs[4].dn_cid_len = 1;
347*0Sstevel@tonic-gate recs[4].dn_cip.s_addr = 0x81940506;
348*0Sstevel@tonic-gate recs[4].dn_sip.s_addr = 0x81940501;
349*0Sstevel@tonic-gate (void) strlcpy(recs[4].dn_macro, "myserv", DSVC_MAX_MACSYM_LEN);
350*0Sstevel@tonic-gate (void) strlcpy(recs[4].dn_comment, "markh", DN_MAX_COMMENT_LEN);
351*0Sstevel@tonic-gate
352*0Sstevel@tonic-gate (void) printf("add_dd_entry: ... cid flag cip sip lease "
353*0Sstevel@tonic-gate "macro comment\n");
354*0Sstevel@tonic-gate for (i = 0; i < sizeof (recs) / sizeof (dn_rec_t); i++) {
355*0Sstevel@tonic-gate cidlen = sizeof (cid);
356*0Sstevel@tonic-gate (void) octet_to_hexascii(recs[i].dn_cid,
357*0Sstevel@tonic-gate recs[i].dn_cid_len, cid, &cidlen);
358*0Sstevel@tonic-gate (void) printf(" %s %d %s %s %u %s %s ... ",
359*0Sstevel@tonic-gate cid, recs[i].dn_flags,
360*0Sstevel@tonic-gate inet_ntop(AF_INET, &recs[i].dn_cip, cip,
361*0Sstevel@tonic-gate INET_ADDRSTRLEN),
362*0Sstevel@tonic-gate inet_ntop(AF_INET, &recs[i].dn_sip, sip,
363*0Sstevel@tonic-gate INET_ADDRSTRLEN),
364*0Sstevel@tonic-gate recs[i].dn_lease, recs[i].dn_macro,
365*0Sstevel@tonic-gate recs[i].dn_comment);
366*0Sstevel@tonic-gate
367*0Sstevel@tonic-gate error = add_dd_entry(handle, &recs[i]);
368*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
369*0Sstevel@tonic-gate if (error != DSVC_SUCCESS)
370*0Sstevel@tonic-gate break;
371*0Sstevel@tonic-gate }
372*0Sstevel@tonic-gate }
373*0Sstevel@tonic-gate
374*0Sstevel@tonic-gate /* lookup_dd - lookup all records. */
375*0Sstevel@tonic-gate DSVC_QINIT(query);
376*0Sstevel@tonic-gate
377*0Sstevel@tonic-gate (void) printf("lookup_dd: 129.148.5.0 ... ");
378*0Sstevel@tonic-gate error = lookup_dd(handle, B_FALSE, query, -1, &dn, (void **)&resdnp,
379*0Sstevel@tonic-gate &count);
380*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
381*0Sstevel@tonic-gate if (error == DSVC_SUCCESS) {
382*0Sstevel@tonic-gate for (i = 0, wnp = resdnp; i < count && wnp != NULL; i++) {
383*0Sstevel@tonic-gate dnp = wnp->dnl_rec;
384*0Sstevel@tonic-gate cidlen = sizeof (cid);
385*0Sstevel@tonic-gate (void) octet_to_hexascii(dnp->dn_cid,
386*0Sstevel@tonic-gate dnp->dn_cid_len, cid, &cidlen);
387*0Sstevel@tonic-gate (void) inet_ntop(AF_INET, &dnp->dn_cip,
388*0Sstevel@tonic-gate cip, INET_ADDRSTRLEN);
389*0Sstevel@tonic-gate (void) inet_ntop(AF_INET, &dnp->dn_sip,
390*0Sstevel@tonic-gate sip, INET_ADDRSTRLEN);
391*0Sstevel@tonic-gate (void) printf(" %s %02u %s %s %u '%s' #%s\n",
392*0Sstevel@tonic-gate cid, dnp->dn_flags, cip, sip, dnp->dn_lease,
393*0Sstevel@tonic-gate dnp->dn_macro, dnp->dn_comment);
394*0Sstevel@tonic-gate wnp = wnp->dnl_next;
395*0Sstevel@tonic-gate }
396*0Sstevel@tonic-gate free_dd_list(handle, resdnp);
397*0Sstevel@tonic-gate }
398*0Sstevel@tonic-gate
399*0Sstevel@tonic-gate /* delete_dd_entry - 129.148.5.3 */
400*0Sstevel@tonic-gate dn.dn_sig = 0;
401*0Sstevel@tonic-gate dn.dn_cip.s_addr = ntohl(inet_addr("129.148.5.3"));
402*0Sstevel@tonic-gate (void) printf("delete_dd_entry: 129.148.5.3 ... ");
403*0Sstevel@tonic-gate error = delete_dd_entry(handle, &dn);
404*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
405*0Sstevel@tonic-gate
406*0Sstevel@tonic-gate /*
407*0Sstevel@tonic-gate * lookup_dd - 129.148.5.0 - record with cid of 01080020000001, modify
408*0Sstevel@tonic-gate * flags to MANUAL+BOOTP, lease to -1, macro to foobar, and server to
409*0Sstevel@tonic-gate * 129.148.174.27.
410*0Sstevel@tonic-gate */
411*0Sstevel@tonic-gate DSVC_QINIT(query);
412*0Sstevel@tonic-gate DSVC_QEQ(query, DN_QCID);
413*0Sstevel@tonic-gate
414*0Sstevel@tonic-gate (void) memset(&dn, 0, sizeof (dn));
415*0Sstevel@tonic-gate dn.dn_cid[0] = 0x1;
416*0Sstevel@tonic-gate dn.dn_cid[1] = 0x8;
417*0Sstevel@tonic-gate dn.dn_cid[2] = 0x0;
418*0Sstevel@tonic-gate dn.dn_cid[3] = 0x20;
419*0Sstevel@tonic-gate dn.dn_cid[4] = 0x0;
420*0Sstevel@tonic-gate dn.dn_cid[5] = 0x0;
421*0Sstevel@tonic-gate dn.dn_cid[6] = 0x1;
422*0Sstevel@tonic-gate dn.dn_cid_len = 7;
423*0Sstevel@tonic-gate
424*0Sstevel@tonic-gate (void) printf("lookup_dd: 01080020000001 ... ");
425*0Sstevel@tonic-gate error = lookup_dd(handle, B_FALSE, query, 1, &dn, (void **)&resdnp,
426*0Sstevel@tonic-gate &count);
427*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
428*0Sstevel@tonic-gate
429*0Sstevel@tonic-gate if (error == DSVC_SUCCESS) {
430*0Sstevel@tonic-gate if (count != 1) {
431*0Sstevel@tonic-gate (void) printf("lookup_dd: expected 1 record, got %d\n",
432*0Sstevel@tonic-gate count);
433*0Sstevel@tonic-gate } else {
434*0Sstevel@tonic-gate dnp = resdnp->dnl_rec;
435*0Sstevel@tonic-gate dn = *dnp; /* struct copy */
436*0Sstevel@tonic-gate
437*0Sstevel@tonic-gate dn.dn_flags = DN_FMANUAL | DN_FBOOTP_ONLY;
438*0Sstevel@tonic-gate dn.dn_lease = DHCP_PERM;
439*0Sstevel@tonic-gate (void) strcpy(dn.dn_macro, "foobar");
440*0Sstevel@tonic-gate dn.dn_sip.s_addr = ntohl(inet_addr("129.148.174.27"));
441*0Sstevel@tonic-gate
442*0Sstevel@tonic-gate /* Modify it */
443*0Sstevel@tonic-gate (void) printf("modify_dd_entry: 01080020000001 ... ");
444*0Sstevel@tonic-gate error = modify_dd_entry(handle, dnp, &dn);
445*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
446*0Sstevel@tonic-gate }
447*0Sstevel@tonic-gate free_dd_list(handle, resdnp);
448*0Sstevel@tonic-gate }
449*0Sstevel@tonic-gate
450*0Sstevel@tonic-gate /* lookup_dd - lookup all fields with DN_FMANUAL set */
451*0Sstevel@tonic-gate
452*0Sstevel@tonic-gate DSVC_QINIT(query);
453*0Sstevel@tonic-gate DSVC_QEQ(query, DN_QFMANUAL);
454*0Sstevel@tonic-gate
455*0Sstevel@tonic-gate (void) memset(&dn, 0, sizeof (dn));
456*0Sstevel@tonic-gate dn.dn_flags = DN_FMANUAL;
457*0Sstevel@tonic-gate
458*0Sstevel@tonic-gate (void) printf("lookup_dd: F_MANUAL ... ");
459*0Sstevel@tonic-gate error = lookup_dd(handle, B_FALSE, query, 1, &dn, (void **)&resdnp,
460*0Sstevel@tonic-gate &count);
461*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
462*0Sstevel@tonic-gate
463*0Sstevel@tonic-gate if (error == DSVC_SUCCESS) {
464*0Sstevel@tonic-gate if (count != 1) {
465*0Sstevel@tonic-gate (void) printf("lookup_dd: expected 1 record, "
466*0Sstevel@tonic-gate "got %d\n", count);
467*0Sstevel@tonic-gate } else {
468*0Sstevel@tonic-gate dnp = resdnp->dnl_rec;
469*0Sstevel@tonic-gate cidlen = sizeof (cid);
470*0Sstevel@tonic-gate (void) octet_to_hexascii(dnp->dn_cid,
471*0Sstevel@tonic-gate dnp->dn_cid_len, cid, &cidlen);
472*0Sstevel@tonic-gate (void) inet_ntop(AF_INET, &dnp->dn_cip,
473*0Sstevel@tonic-gate cip, INET_ADDRSTRLEN);
474*0Sstevel@tonic-gate (void) inet_ntop(AF_INET, &dnp->dn_sip,
475*0Sstevel@tonic-gate sip, INET_ADDRSTRLEN);
476*0Sstevel@tonic-gate (void) printf(" %s %02u %s %s %u '%s' #%s\n",
477*0Sstevel@tonic-gate cid, dnp->dn_flags, cip, sip, dnp->dn_lease,
478*0Sstevel@tonic-gate dnp->dn_macro, dnp->dn_comment);
479*0Sstevel@tonic-gate }
480*0Sstevel@tonic-gate free_dd_list(handle, resdnp);
481*0Sstevel@tonic-gate }
482*0Sstevel@tonic-gate
483*0Sstevel@tonic-gate /* lookup_dd - lookup all records. */
484*0Sstevel@tonic-gate
485*0Sstevel@tonic-gate DSVC_QINIT(query);
486*0Sstevel@tonic-gate
487*0Sstevel@tonic-gate (void) printf("lookup_dd: 129.148.5.0 ...");
488*0Sstevel@tonic-gate error = lookup_dd(handle, B_FALSE, query, -1, &dn, (void **)&resdnp,
489*0Sstevel@tonic-gate &count);
490*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
491*0Sstevel@tonic-gate
492*0Sstevel@tonic-gate if (error == DSVC_SUCCESS) {
493*0Sstevel@tonic-gate for (i = 0, wnp = resdnp; i < count && wnp != NULL; i++) {
494*0Sstevel@tonic-gate cidlen = sizeof (cid);
495*0Sstevel@tonic-gate dnp = wnp->dnl_rec;
496*0Sstevel@tonic-gate (void) octet_to_hexascii(dnp->dn_cid,
497*0Sstevel@tonic-gate dnp->dn_cid_len, cid, &cidlen);
498*0Sstevel@tonic-gate (void) inet_ntop(AF_INET, &dnp->dn_cip,
499*0Sstevel@tonic-gate cip, INET_ADDRSTRLEN);
500*0Sstevel@tonic-gate (void) inet_ntop(AF_INET, &dnp->dn_sip,
501*0Sstevel@tonic-gate sip, INET_ADDRSTRLEN);
502*0Sstevel@tonic-gate (void) printf(" %s %02u %s %s %u '%s' #%s\n",
503*0Sstevel@tonic-gate cid, dnp->dn_flags, cip, sip, dnp->dn_lease,
504*0Sstevel@tonic-gate dnp->dn_macro, dnp->dn_comment);
505*0Sstevel@tonic-gate wnp = wnp->dnl_next;
506*0Sstevel@tonic-gate }
507*0Sstevel@tonic-gate free_dd_list(handle, resdnp);
508*0Sstevel@tonic-gate }
509*0Sstevel@tonic-gate
510*0Sstevel@tonic-gate /* close_dd - 129.148.5.0 */
511*0Sstevel@tonic-gate (void) printf("close_dd: 129.148.5.0 ... ");
512*0Sstevel@tonic-gate error = close_dd(&handle);
513*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
514*0Sstevel@tonic-gate
515*0Sstevel@tonic-gate /* list_dd - dhcp network containers */
516*0Sstevel@tonic-gate (void) printf("list_dd: ... ");
517*0Sstevel@tonic-gate error = list_dd(&dsp, DSVC_DHCPNETWORK, &listpp, &count);
518*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
519*0Sstevel@tonic-gate if (error == DSVC_SUCCESS) {
520*0Sstevel@tonic-gate (void) printf(" %d dhcp network container(s): ", count);
521*0Sstevel@tonic-gate for (i = 0; i < count; i++) {
522*0Sstevel@tonic-gate (void) printf("%s ", listpp[i] != NULL ?
523*0Sstevel@tonic-gate listpp[i] : "NULL");
524*0Sstevel@tonic-gate free(listpp[i]);
525*0Sstevel@tonic-gate }
526*0Sstevel@tonic-gate free(listpp);
527*0Sstevel@tonic-gate (void) printf("\n");
528*0Sstevel@tonic-gate } else {
529*0Sstevel@tonic-gate (void) printf("list_dd: listpp: 0x%p, count: %d\n",
530*0Sstevel@tonic-gate (void *)listpp, count);
531*0Sstevel@tonic-gate }
532*0Sstevel@tonic-gate
533*0Sstevel@tonic-gate /* remove_dd - 129.148.5.0 */
534*0Sstevel@tonic-gate (void) printf("remove_dd_entry: 129.148.5.0 ... ");
535*0Sstevel@tonic-gate error = remove_dd(&dsp, DSVC_DHCPNETWORK, "129.148.5.0");
536*0Sstevel@tonic-gate (void) printf("%s\n", dhcpsvc_errmsg(error));
537*0Sstevel@tonic-gate
538*0Sstevel@tonic-gate return (0);
539*0Sstevel@tonic-gate }
540