xref: /onnv-gate/usr/src/lib/libdhcpsvc/private/public.c (revision 0:68f95e015346)
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 /*
30*0Sstevel@tonic-gate  * This module contains the glue functions necessary for gluing in
31*0Sstevel@tonic-gate  * the selected public module API into the private API.
32*0Sstevel@tonic-gate  */
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #include <stdlib.h>
35*0Sstevel@tonic-gate #include <string.h>
36*0Sstevel@tonic-gate #include <dhcp_svc_public.h>
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate /*
39*0Sstevel@tonic-gate  * Allocate a dt_rec_t structure.  Argument values are copied and set
40*0Sstevel@tonic-gate  * to the respective fields within the allocated dt_rec_t structure.
41*0Sstevel@tonic-gate  * Caller is should free structure using free_dtrec().
42*0Sstevel@tonic-gate  */
43*0Sstevel@tonic-gate dt_rec_t *
alloc_dtrec(const char * key,char type,const char * value)44*0Sstevel@tonic-gate alloc_dtrec(const char *key, char type, const char *value)
45*0Sstevel@tonic-gate {
46*0Sstevel@tonic-gate 	dt_rec_t *retval = malloc(sizeof (dt_rec_t));
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate 	if (key == NULL || value == NULL || retval == NULL) {
49*0Sstevel@tonic-gate 		free(retval);
50*0Sstevel@tonic-gate 		return (NULL);
51*0Sstevel@tonic-gate 	}
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate 	(void) strlcpy(retval->dt_key, key, sizeof (retval->dt_key));
54*0Sstevel@tonic-gate 	retval->dt_sig = 0;
55*0Sstevel@tonic-gate 	retval->dt_type = type;
56*0Sstevel@tonic-gate 	retval->dt_value = strdup(value);
57*0Sstevel@tonic-gate 	if (retval->dt_value == NULL) {
58*0Sstevel@tonic-gate 		free(retval);
59*0Sstevel@tonic-gate 		return (NULL);
60*0Sstevel@tonic-gate 	}
61*0Sstevel@tonic-gate 	return (retval);
62*0Sstevel@tonic-gate }
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate /*
65*0Sstevel@tonic-gate  * Allocate a dn_rec_t structure.  Argument values are copied and set
66*0Sstevel@tonic-gate  * to the respective fields within the allocated dn_rec_t structure.
67*0Sstevel@tonic-gate  */
68*0Sstevel@tonic-gate dn_rec_t *
alloc_dnrec(const uchar_t * cid,uchar_t cid_len,uchar_t flags,struct in_addr cip,struct in_addr sip,lease_t lease,const char * macro,const char * comment)69*0Sstevel@tonic-gate alloc_dnrec(const uchar_t *cid, uchar_t cid_len, uchar_t flags,
70*0Sstevel@tonic-gate     struct in_addr cip, struct in_addr sip, lease_t lease, const char *macro,
71*0Sstevel@tonic-gate     const char *comment)
72*0Sstevel@tonic-gate {
73*0Sstevel@tonic-gate 	dn_rec_t *retval = malloc(sizeof (dn_rec_t));
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate 	if (cid == NULL || retval == NULL) {
76*0Sstevel@tonic-gate 		free(retval);
77*0Sstevel@tonic-gate 		return (NULL);
78*0Sstevel@tonic-gate 	}
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate 	retval->dn_cid_len	= cid_len;
81*0Sstevel@tonic-gate 	retval->dn_flags	= flags;
82*0Sstevel@tonic-gate 	retval->dn_cip		= cip;
83*0Sstevel@tonic-gate 	retval->dn_sip		= sip;
84*0Sstevel@tonic-gate 	retval->dn_lease	= lease;
85*0Sstevel@tonic-gate 	retval->dn_macro[0]	= '\0';
86*0Sstevel@tonic-gate 	retval->dn_comment[0]	= '\0';
87*0Sstevel@tonic-gate 	retval->dn_sig		= 0;
88*0Sstevel@tonic-gate 	(void) memcpy(retval->dn_cid, cid, cid_len);
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate 	if (macro != NULL)
91*0Sstevel@tonic-gate 		(void) strlcpy(retval->dn_macro, macro,
92*0Sstevel@tonic-gate 		    sizeof (retval->dn_macro));
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate 	if (comment != NULL)
95*0Sstevel@tonic-gate 		(void) strlcpy(retval->dn_comment, comment,
96*0Sstevel@tonic-gate 		    sizeof (retval->dn_comment));
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate 	return (retval);
99*0Sstevel@tonic-gate }
100*0Sstevel@tonic-gate 
101*0Sstevel@tonic-gate /*
102*0Sstevel@tonic-gate  * Prepend a dt_rec_t to a dt_rec_list_t; if `listp' is NULL, then
103*0Sstevel@tonic-gate  * the list is created.
104*0Sstevel@tonic-gate  */
105*0Sstevel@tonic-gate dt_rec_list_t *
add_dtrec_to_list(dt_rec_t * entryp,dt_rec_list_t * listp)106*0Sstevel@tonic-gate add_dtrec_to_list(dt_rec_t *entryp, dt_rec_list_t *listp)
107*0Sstevel@tonic-gate {
108*0Sstevel@tonic-gate 	dt_rec_list_t *retval = malloc(sizeof (dt_rec_list_t));
109*0Sstevel@tonic-gate 
110*0Sstevel@tonic-gate 	if (entryp == NULL || retval == NULL) {
111*0Sstevel@tonic-gate 		free(retval);
112*0Sstevel@tonic-gate 		return (NULL);
113*0Sstevel@tonic-gate 	}
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate 	retval->dtl_next = listp;
116*0Sstevel@tonic-gate 	retval->dtl_rec = entryp;
117*0Sstevel@tonic-gate 	return (retval);
118*0Sstevel@tonic-gate }
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate /*
121*0Sstevel@tonic-gate  * Prepend a dn_rec_t to a dn_rec_list_t; if `listp' is NULL, then
122*0Sstevel@tonic-gate  * the list is created.
123*0Sstevel@tonic-gate  */
124*0Sstevel@tonic-gate dn_rec_list_t *
add_dnrec_to_list(dn_rec_t * entryp,dn_rec_list_t * listp)125*0Sstevel@tonic-gate add_dnrec_to_list(dn_rec_t *entryp, dn_rec_list_t *listp)
126*0Sstevel@tonic-gate {
127*0Sstevel@tonic-gate 	dn_rec_list_t *retval = malloc(sizeof (dn_rec_list_t));
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate 	if (entryp == NULL || retval == NULL) {
130*0Sstevel@tonic-gate 		free(retval);
131*0Sstevel@tonic-gate 		return (NULL);
132*0Sstevel@tonic-gate 	}
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate 	retval->dnl_next = listp;
135*0Sstevel@tonic-gate 	retval->dnl_rec = entryp;
136*0Sstevel@tonic-gate 	return (retval);
137*0Sstevel@tonic-gate }
138*0Sstevel@tonic-gate 
139*0Sstevel@tonic-gate /*
140*0Sstevel@tonic-gate  * Free all elements of dtp, as well as the dt_rec_t structure itself.
141*0Sstevel@tonic-gate  */
142*0Sstevel@tonic-gate void
free_dtrec(dt_rec_t * dtp)143*0Sstevel@tonic-gate free_dtrec(dt_rec_t *dtp)
144*0Sstevel@tonic-gate {
145*0Sstevel@tonic-gate 	if (dtp != NULL) {
146*0Sstevel@tonic-gate 		free(dtp->dt_value);
147*0Sstevel@tonic-gate 		free(dtp);
148*0Sstevel@tonic-gate 	}
149*0Sstevel@tonic-gate }
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate /*
152*0Sstevel@tonic-gate  * Free a list of dt_rec_t's
153*0Sstevel@tonic-gate  */
154*0Sstevel@tonic-gate void
free_dtrec_list(dt_rec_list_t * dtlp)155*0Sstevel@tonic-gate free_dtrec_list(dt_rec_list_t *dtlp)
156*0Sstevel@tonic-gate {
157*0Sstevel@tonic-gate 	dt_rec_list_t *next;
158*0Sstevel@tonic-gate 
159*0Sstevel@tonic-gate 	for (; dtlp != NULL; dtlp = next) {
160*0Sstevel@tonic-gate 		free_dtrec(dtlp->dtl_rec);
161*0Sstevel@tonic-gate 		next = dtlp->dtl_next;
162*0Sstevel@tonic-gate 		free(dtlp);
163*0Sstevel@tonic-gate 	}
164*0Sstevel@tonic-gate }
165*0Sstevel@tonic-gate 
166*0Sstevel@tonic-gate /*
167*0Sstevel@tonic-gate  * Free the dn_rec_t structure.
168*0Sstevel@tonic-gate  */
169*0Sstevel@tonic-gate void
free_dnrec(dn_rec_t * dnp)170*0Sstevel@tonic-gate free_dnrec(dn_rec_t *dnp)
171*0Sstevel@tonic-gate {
172*0Sstevel@tonic-gate 	free(dnp);
173*0Sstevel@tonic-gate }
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate /*
176*0Sstevel@tonic-gate  * Free a list of dn_rec_t's
177*0Sstevel@tonic-gate  */
178*0Sstevel@tonic-gate void
free_dnrec_list(dn_rec_list_t * dnlp)179*0Sstevel@tonic-gate free_dnrec_list(dn_rec_list_t *dnlp)
180*0Sstevel@tonic-gate {
181*0Sstevel@tonic-gate 	dn_rec_list_t *next;
182*0Sstevel@tonic-gate 
183*0Sstevel@tonic-gate 	for (; dnlp != NULL; dnlp = next) {
184*0Sstevel@tonic-gate 		free_dnrec(dnlp->dnl_rec);
185*0Sstevel@tonic-gate 		next = dnlp->dnl_next;
186*0Sstevel@tonic-gate 		free(dnlp);
187*0Sstevel@tonic-gate 	}
188*0Sstevel@tonic-gate }
189