1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This module contains the glue functions necessary for gluing in
* the selected public module API into the private API.
*/
#include <stdlib.h>
#include <string.h>
#include <dhcp_svc_public.h>
/*
* Allocate a dt_rec_t structure. Argument values are copied and set
* to the respective fields within the allocated dt_rec_t structure.
* Caller is should free structure using free_dtrec().
*/
dt_rec_t *
alloc_dtrec(const char *key, char type, const char *value)
{
dt_rec_t *retval = malloc(sizeof (dt_rec_t));
if (key == NULL || value == NULL || retval == NULL) {
free(retval);
return (NULL);
}
(void) strlcpy(retval->dt_key, key, sizeof (retval->dt_key));
retval->dt_sig = 0;
retval->dt_type = type;
retval->dt_value = strdup(value);
if (retval->dt_value == NULL) {
free(retval);
return (NULL);
}
return (retval);
}
/*
* Allocate a dn_rec_t structure. Argument values are copied and set
* to the respective fields within the allocated dn_rec_t structure.
*/
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)
{
dn_rec_t *retval = malloc(sizeof (dn_rec_t));
if (cid == NULL || retval == NULL) {
free(retval);
return (NULL);
}
retval->dn_cid_len = cid_len;
retval->dn_flags = flags;
retval->dn_cip = cip;
retval->dn_sip = sip;
retval->dn_lease = lease;
retval->dn_macro[0] = '\0';
retval->dn_comment[0] = '\0';
retval->dn_sig = 0;
(void) memcpy(retval->dn_cid, cid, cid_len);
if (macro != NULL)
(void) strlcpy(retval->dn_macro, macro,
sizeof (retval->dn_macro));
if (comment != NULL)
(void) strlcpy(retval->dn_comment, comment,
sizeof (retval->dn_comment));
return (retval);
}
/*
* Prepend a dt_rec_t to a dt_rec_list_t; if `listp' is NULL, then
* the list is created.
*/
dt_rec_list_t *
add_dtrec_to_list(dt_rec_t *entryp, dt_rec_list_t *listp)
{
dt_rec_list_t *retval = malloc(sizeof (dt_rec_list_t));
if (entryp == NULL || retval == NULL) {
free(retval);
return (NULL);
}
retval->dtl_next = listp;
retval->dtl_rec = entryp;
return (retval);
}
/*
* Prepend a dn_rec_t to a dn_rec_list_t; if `listp' is NULL, then
* the list is created.
*/
dn_rec_list_t *
add_dnrec_to_list(dn_rec_t *entryp, dn_rec_list_t *listp)
{
dn_rec_list_t *retval = malloc(sizeof (dn_rec_list_t));
if (entryp == NULL || retval == NULL) {
free(retval);
return (NULL);
}
retval->dnl_next = listp;
retval->dnl_rec = entryp;
return (retval);
}
/*
* Free all elements of dtp, as well as the dt_rec_t structure itself.
*/
void
free_dtrec(dt_rec_t *dtp)
{
if (dtp != NULL) {
free(dtp->dt_value);
free(dtp);
}
}
/*
* Free a list of dt_rec_t's
*/
void
free_dtrec_list(dt_rec_list_t *dtlp)
{
dt_rec_list_t *next;
for (; dtlp != NULL; dtlp = next) {
free_dtrec(dtlp->dtl_rec);
next = dtlp->dtl_next;
free(dtlp);
}
}
/*
* Free the dn_rec_t structure.
*/
void
free_dnrec(dn_rec_t *dnp)
{
free(dnp);
}
/*
* Free a list of dn_rec_t's
*/
void
free_dnrec_list(dn_rec_list_t *dnlp)
{
dn_rec_list_t *next;
for (; dnlp != NULL; dnlp = next) {
free_dnrec(dnlp->dnl_rec);
next = dnlp->dnl_next;
free(dnlp);
}
}
|